@@ -16,2930 +16,2930 @@ |
||
| 16 | 16 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This will hold the event object for event_details screen. |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @var EE_Event $_event |
|
| 24 | - */ |
|
| 25 | - protected $_event; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * This will hold the category object for category_details screen. |
|
| 30 | - * |
|
| 31 | - * @var stdClass $_category |
|
| 32 | - */ |
|
| 33 | - protected $_category; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var EEM_Event $_event_model |
|
| 38 | - */ |
|
| 39 | - protected $_event_model; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var EEM_Datetime $datetime_model |
|
| 43 | - */ |
|
| 44 | - protected $datetime_model; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EEM_Ticket $ticket_model |
|
| 48 | - */ |
|
| 49 | - protected $ticket_model; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var EE_Event |
|
| 54 | - */ |
|
| 55 | - protected $_cpt_model_obj; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Initialize page props for this admin page group. |
|
| 60 | - */ |
|
| 61 | - protected function _init_page_props() |
|
| 62 | - { |
|
| 63 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 64 | - $this->page_label = EVENTS_LABEL; |
|
| 65 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 66 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 67 | - $this->_cpt_model_names = [ |
|
| 68 | - 'create_new' => 'EEM_Event', |
|
| 69 | - 'edit' => 'EEM_Event', |
|
| 70 | - ]; |
|
| 71 | - $this->_cpt_edit_routes = [ |
|
| 72 | - 'espresso_events' => 'edit', |
|
| 73 | - ]; |
|
| 74 | - add_action( |
|
| 75 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 76 | - [$this, 'verify_event_edit'], |
|
| 77 | - 10, |
|
| 78 | - 2 |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Sets the ajax hooks used for this admin page group. |
|
| 85 | - */ |
|
| 86 | - protected function _ajax_hooks() |
|
| 87 | - { |
|
| 88 | - add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Sets the page properties for this admin page group. |
|
| 94 | - */ |
|
| 95 | - protected function _define_page_props() |
|
| 96 | - { |
|
| 97 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 98 | - $this->_labels = [ |
|
| 99 | - 'buttons' => [ |
|
| 100 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 101 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 102 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 103 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 104 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 105 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 106 | - ], |
|
| 107 | - 'editor_title' => [ |
|
| 108 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 109 | - ], |
|
| 110 | - 'publishbox' => [ |
|
| 111 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 112 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 113 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 114 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 115 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 116 | - ], |
|
| 117 | - ]; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Sets the page routes property for this admin page group. |
|
| 123 | - */ |
|
| 124 | - protected function _set_page_routes() |
|
| 125 | - { |
|
| 126 | - // load formatter helper |
|
| 127 | - // load field generator helper |
|
| 128 | - // is there a evt_id in the request? |
|
| 129 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 130 | - ? $this->_req_data['EVT_ID'] |
|
| 131 | - : 0; |
|
| 132 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 133 | - $this->_page_routes = [ |
|
| 134 | - 'default' => [ |
|
| 135 | - 'func' => '_events_overview_list_table', |
|
| 136 | - 'capability' => 'ee_read_events', |
|
| 137 | - ], |
|
| 138 | - 'create_new' => [ |
|
| 139 | - 'func' => '_create_new_cpt_item', |
|
| 140 | - 'capability' => 'ee_edit_events', |
|
| 141 | - ], |
|
| 142 | - 'edit' => [ |
|
| 143 | - 'func' => '_edit_cpt_item', |
|
| 144 | - 'capability' => 'ee_edit_event', |
|
| 145 | - 'obj_id' => $evt_id, |
|
| 146 | - ], |
|
| 147 | - 'copy_event' => [ |
|
| 148 | - 'func' => '_copy_events', |
|
| 149 | - 'capability' => 'ee_edit_event', |
|
| 150 | - 'obj_id' => $evt_id, |
|
| 151 | - 'noheader' => true, |
|
| 152 | - ], |
|
| 153 | - 'trash_event' => [ |
|
| 154 | - 'func' => '_trash_or_restore_event', |
|
| 155 | - 'args' => ['event_status' => 'trash'], |
|
| 156 | - 'capability' => 'ee_delete_event', |
|
| 157 | - 'obj_id' => $evt_id, |
|
| 158 | - 'noheader' => true, |
|
| 159 | - ], |
|
| 160 | - 'trash_events' => [ |
|
| 161 | - 'func' => '_trash_or_restore_events', |
|
| 162 | - 'args' => ['event_status' => 'trash'], |
|
| 163 | - 'capability' => 'ee_delete_events', |
|
| 164 | - 'noheader' => true, |
|
| 165 | - ], |
|
| 166 | - 'restore_event' => [ |
|
| 167 | - 'func' => '_trash_or_restore_event', |
|
| 168 | - 'args' => ['event_status' => 'draft'], |
|
| 169 | - 'capability' => 'ee_delete_event', |
|
| 170 | - 'obj_id' => $evt_id, |
|
| 171 | - 'noheader' => true, |
|
| 172 | - ], |
|
| 173 | - 'restore_events' => [ |
|
| 174 | - 'func' => '_trash_or_restore_events', |
|
| 175 | - 'args' => ['event_status' => 'draft'], |
|
| 176 | - 'capability' => 'ee_delete_events', |
|
| 177 | - 'noheader' => true, |
|
| 178 | - ], |
|
| 179 | - 'delete_event' => [ |
|
| 180 | - 'func' => '_delete_event', |
|
| 181 | - 'capability' => 'ee_delete_event', |
|
| 182 | - 'obj_id' => $evt_id, |
|
| 183 | - 'noheader' => true, |
|
| 184 | - ], |
|
| 185 | - 'delete_events' => [ |
|
| 186 | - 'func' => '_delete_events', |
|
| 187 | - 'capability' => 'ee_delete_events', |
|
| 188 | - 'noheader' => true, |
|
| 189 | - ], |
|
| 190 | - 'view_report' => [ |
|
| 191 | - 'func' => '_view_report', |
|
| 192 | - 'capability' => 'ee_edit_events', |
|
| 193 | - ], |
|
| 194 | - 'default_event_settings' => [ |
|
| 195 | - 'func' => '_default_event_settings', |
|
| 196 | - 'capability' => 'manage_options', |
|
| 197 | - ], |
|
| 198 | - 'update_default_event_settings' => [ |
|
| 199 | - 'func' => '_update_default_event_settings', |
|
| 200 | - 'capability' => 'manage_options', |
|
| 201 | - 'noheader' => true, |
|
| 202 | - ], |
|
| 203 | - 'template_settings' => [ |
|
| 204 | - 'func' => '_template_settings', |
|
| 205 | - 'capability' => 'manage_options', |
|
| 206 | - ], |
|
| 207 | - // event category tab related |
|
| 208 | - 'add_category' => [ |
|
| 209 | - 'func' => '_category_details', |
|
| 210 | - 'capability' => 'ee_edit_event_category', |
|
| 211 | - 'args' => ['add'], |
|
| 212 | - ], |
|
| 213 | - 'edit_category' => [ |
|
| 214 | - 'func' => '_category_details', |
|
| 215 | - 'capability' => 'ee_edit_event_category', |
|
| 216 | - 'args' => ['edit'], |
|
| 217 | - ], |
|
| 218 | - 'delete_categories' => [ |
|
| 219 | - 'func' => '_delete_categories', |
|
| 220 | - 'capability' => 'ee_delete_event_category', |
|
| 221 | - 'noheader' => true, |
|
| 222 | - ], |
|
| 223 | - 'delete_category' => [ |
|
| 224 | - 'func' => '_delete_categories', |
|
| 225 | - 'capability' => 'ee_delete_event_category', |
|
| 226 | - 'noheader' => true, |
|
| 227 | - ], |
|
| 228 | - 'insert_category' => [ |
|
| 229 | - 'func' => '_insert_or_update_category', |
|
| 230 | - 'args' => ['new_category' => true], |
|
| 231 | - 'capability' => 'ee_edit_event_category', |
|
| 232 | - 'noheader' => true, |
|
| 233 | - ], |
|
| 234 | - 'update_category' => [ |
|
| 235 | - 'func' => '_insert_or_update_category', |
|
| 236 | - 'args' => ['new_category' => false], |
|
| 237 | - 'capability' => 'ee_edit_event_category', |
|
| 238 | - 'noheader' => true, |
|
| 239 | - ], |
|
| 240 | - 'category_list' => [ |
|
| 241 | - 'func' => '_category_list_table', |
|
| 242 | - 'capability' => 'ee_manage_event_categories', |
|
| 243 | - ], |
|
| 244 | - ]; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Set the _page_config property for this admin page group. |
|
| 250 | - */ |
|
| 251 | - protected function _set_page_config() |
|
| 252 | - { |
|
| 253 | - $this->_page_config = [ |
|
| 254 | - 'default' => [ |
|
| 255 | - 'nav' => [ |
|
| 256 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 257 | - 'order' => 10, |
|
| 258 | - ], |
|
| 259 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 260 | - 'help_tabs' => [ |
|
| 261 | - 'events_overview_help_tab' => [ |
|
| 262 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 263 | - 'filename' => 'events_overview', |
|
| 264 | - ], |
|
| 265 | - 'events_overview_table_column_headings_help_tab' => [ |
|
| 266 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 267 | - 'filename' => 'events_overview_table_column_headings', |
|
| 268 | - ], |
|
| 269 | - 'events_overview_filters_help_tab' => [ |
|
| 270 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 271 | - 'filename' => 'events_overview_filters', |
|
| 272 | - ], |
|
| 273 | - 'events_overview_view_help_tab' => [ |
|
| 274 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 275 | - 'filename' => 'events_overview_views', |
|
| 276 | - ], |
|
| 277 | - 'events_overview_other_help_tab' => [ |
|
| 278 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 279 | - 'filename' => 'events_overview_other', |
|
| 280 | - ], |
|
| 281 | - ], |
|
| 282 | - 'help_tour' => [ |
|
| 283 | - 'Event_Overview_Help_Tour', |
|
| 284 | - // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 285 | - ], |
|
| 286 | - 'require_nonce' => false, |
|
| 287 | - 'qtips' => ['EE_Event_List_Table_Tips'], |
|
| 288 | - ], |
|
| 289 | - 'create_new' => [ |
|
| 290 | - 'nav' => [ |
|
| 291 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 292 | - 'order' => 5, |
|
| 293 | - 'persistent' => false, |
|
| 294 | - ], |
|
| 295 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 296 | - 'help_tabs' => [ |
|
| 297 | - 'event_editor_help_tab' => [ |
|
| 298 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 299 | - 'filename' => 'event_editor', |
|
| 300 | - ], |
|
| 301 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 302 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 303 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 304 | - ], |
|
| 305 | - 'event_editor_venue_details_help_tab' => [ |
|
| 306 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 307 | - 'filename' => 'event_editor_venue_details', |
|
| 308 | - ], |
|
| 309 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 310 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 311 | - 'filename' => 'event_editor_event_datetimes', |
|
| 312 | - ], |
|
| 313 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 314 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 315 | - 'filename' => 'event_editor_event_tickets', |
|
| 316 | - ], |
|
| 317 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 318 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 319 | - 'filename' => 'event_editor_event_registration_options', |
|
| 320 | - ], |
|
| 321 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 322 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 323 | - 'filename' => 'event_editor_tags_categories', |
|
| 324 | - ], |
|
| 325 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 326 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 327 | - 'filename' => 'event_editor_questions_registrants', |
|
| 328 | - ], |
|
| 329 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 330 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 331 | - 'filename' => 'event_editor_save_new_event', |
|
| 332 | - ], |
|
| 333 | - 'event_editor_other_help_tab' => [ |
|
| 334 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 335 | - 'filename' => 'event_editor_other', |
|
| 336 | - ], |
|
| 337 | - ], |
|
| 338 | - 'help_tour' => [ |
|
| 339 | - 'Event_Editor_Help_Tour', |
|
| 340 | - ], |
|
| 341 | - 'require_nonce' => false, |
|
| 342 | - ], |
|
| 343 | - 'edit' => [ |
|
| 344 | - 'nav' => [ |
|
| 345 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 346 | - 'order' => 5, |
|
| 347 | - 'persistent' => false, |
|
| 348 | - 'url' => isset($this->_req_data['post']) |
|
| 349 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 350 | - ['post' => $this->_req_data['post'], 'action' => 'edit'], |
|
| 351 | - $this->_current_page_view_url |
|
| 352 | - ) |
|
| 353 | - : $this->_admin_base_url, |
|
| 354 | - ], |
|
| 355 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 356 | - 'help_tabs' => [ |
|
| 357 | - 'event_editor_help_tab' => [ |
|
| 358 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 359 | - 'filename' => 'event_editor', |
|
| 360 | - ], |
|
| 361 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 362 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 363 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 364 | - ], |
|
| 365 | - 'event_editor_venue_details_help_tab' => [ |
|
| 366 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 367 | - 'filename' => 'event_editor_venue_details', |
|
| 368 | - ], |
|
| 369 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 370 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 371 | - 'filename' => 'event_editor_event_datetimes', |
|
| 372 | - ], |
|
| 373 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 374 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 375 | - 'filename' => 'event_editor_event_tickets', |
|
| 376 | - ], |
|
| 377 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 378 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 379 | - 'filename' => 'event_editor_event_registration_options', |
|
| 380 | - ], |
|
| 381 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 382 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 383 | - 'filename' => 'event_editor_tags_categories', |
|
| 384 | - ], |
|
| 385 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 386 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 387 | - 'filename' => 'event_editor_questions_registrants', |
|
| 388 | - ], |
|
| 389 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 390 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 391 | - 'filename' => 'event_editor_save_new_event', |
|
| 392 | - ], |
|
| 393 | - 'event_editor_other_help_tab' => [ |
|
| 394 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 395 | - 'filename' => 'event_editor_other', |
|
| 396 | - ], |
|
| 397 | - ], |
|
| 398 | - 'require_nonce' => false, |
|
| 399 | - ], |
|
| 400 | - 'default_event_settings' => [ |
|
| 401 | - 'nav' => [ |
|
| 402 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 403 | - 'order' => 40, |
|
| 404 | - ], |
|
| 405 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 406 | - 'labels' => [ |
|
| 407 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 408 | - ], |
|
| 409 | - 'help_tabs' => [ |
|
| 410 | - 'default_settings_help_tab' => [ |
|
| 411 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 412 | - 'filename' => 'events_default_settings', |
|
| 413 | - ], |
|
| 414 | - 'default_settings_status_help_tab' => [ |
|
| 415 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 416 | - 'filename' => 'events_default_settings_status', |
|
| 417 | - ], |
|
| 418 | - 'default_maximum_tickets_help_tab' => [ |
|
| 419 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 420 | - 'filename' => 'events_default_settings_max_tickets', |
|
| 421 | - ], |
|
| 422 | - ], |
|
| 423 | - 'help_tour' => ['Event_Default_Settings_Help_Tour'], |
|
| 424 | - 'require_nonce' => false, |
|
| 425 | - ], |
|
| 426 | - // template settings |
|
| 427 | - 'template_settings' => [ |
|
| 428 | - 'nav' => [ |
|
| 429 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 430 | - 'order' => 30, |
|
| 431 | - ], |
|
| 432 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 433 | - 'help_tabs' => [ |
|
| 434 | - 'general_settings_templates_help_tab' => [ |
|
| 435 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 436 | - 'filename' => 'general_settings_templates', |
|
| 437 | - ], |
|
| 438 | - ], |
|
| 439 | - 'help_tour' => ['Templates_Help_Tour'], |
|
| 440 | - 'require_nonce' => false, |
|
| 441 | - ], |
|
| 442 | - // event category stuff |
|
| 443 | - 'add_category' => [ |
|
| 444 | - 'nav' => [ |
|
| 445 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 446 | - 'order' => 15, |
|
| 447 | - 'persistent' => false, |
|
| 448 | - ], |
|
| 449 | - 'help_tabs' => [ |
|
| 450 | - 'add_category_help_tab' => [ |
|
| 451 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 452 | - 'filename' => 'events_add_category', |
|
| 453 | - ], |
|
| 454 | - ], |
|
| 455 | - 'help_tour' => ['Event_Add_Category_Help_Tour'], |
|
| 456 | - 'metaboxes' => ['_publish_post_box'], |
|
| 457 | - 'require_nonce' => false, |
|
| 458 | - ], |
|
| 459 | - 'edit_category' => [ |
|
| 460 | - 'nav' => [ |
|
| 461 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 462 | - 'order' => 15, |
|
| 463 | - 'persistent' => false, |
|
| 464 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 465 | - ? add_query_arg( |
|
| 466 | - ['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']], |
|
| 467 | - $this->_current_page_view_url |
|
| 468 | - ) |
|
| 469 | - : $this->_admin_base_url, |
|
| 470 | - ], |
|
| 471 | - 'help_tabs' => [ |
|
| 472 | - 'edit_category_help_tab' => [ |
|
| 473 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 474 | - 'filename' => 'events_edit_category', |
|
| 475 | - ], |
|
| 476 | - ], |
|
| 477 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 478 | - 'metaboxes' => ['_publish_post_box'], |
|
| 479 | - 'require_nonce' => false, |
|
| 480 | - ], |
|
| 481 | - 'category_list' => [ |
|
| 482 | - 'nav' => [ |
|
| 483 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 484 | - 'order' => 20, |
|
| 485 | - ], |
|
| 486 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 487 | - 'help_tabs' => [ |
|
| 488 | - 'events_categories_help_tab' => [ |
|
| 489 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 490 | - 'filename' => 'events_categories', |
|
| 491 | - ], |
|
| 492 | - 'events_categories_table_column_headings_help_tab' => [ |
|
| 493 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 494 | - 'filename' => 'events_categories_table_column_headings', |
|
| 495 | - ], |
|
| 496 | - 'events_categories_view_help_tab' => [ |
|
| 497 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 498 | - 'filename' => 'events_categories_views', |
|
| 499 | - ], |
|
| 500 | - 'events_categories_other_help_tab' => [ |
|
| 501 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 502 | - 'filename' => 'events_categories_other', |
|
| 503 | - ], |
|
| 504 | - ], |
|
| 505 | - 'help_tour' => [ |
|
| 506 | - 'Event_Categories_Help_Tour', |
|
| 507 | - ], |
|
| 508 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 509 | - 'require_nonce' => false, |
|
| 510 | - ], |
|
| 511 | - ]; |
|
| 512 | - // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated |
|
| 513 | - $domain = $this->loader->getShared('EventEspresso\core\domain\Domain'); |
|
| 514 | - if (! $domain->isCaffeinated()) { |
|
| 515 | - $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
|
| 516 | - $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 523 | - */ |
|
| 524 | - protected function _add_screen_options() |
|
| 525 | - { |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Implementing the screen options for the 'default' route. |
|
| 531 | - * |
|
| 532 | - * @throws InvalidArgumentException |
|
| 533 | - * @throws InvalidDataTypeException |
|
| 534 | - * @throws InvalidInterfaceException |
|
| 535 | - */ |
|
| 536 | - protected function _add_screen_options_default() |
|
| 537 | - { |
|
| 538 | - $this->_per_page_screen_option(); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Implementing screen options for the category list route. |
|
| 544 | - * |
|
| 545 | - * @throws InvalidArgumentException |
|
| 546 | - * @throws InvalidDataTypeException |
|
| 547 | - * @throws InvalidInterfaceException |
|
| 548 | - */ |
|
| 549 | - protected function _add_screen_options_category_list() |
|
| 550 | - { |
|
| 551 | - $page_title = $this->_admin_page_title; |
|
| 552 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 553 | - $this->_per_page_screen_option(); |
|
| 554 | - $this->_admin_page_title = $page_title; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Used to register any global feature pointers for the admin page group. |
|
| 560 | - */ |
|
| 561 | - protected function _add_feature_pointers() |
|
| 562 | - { |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 568 | - */ |
|
| 569 | - public function load_scripts_styles() |
|
| 570 | - { |
|
| 571 | - wp_register_style( |
|
| 572 | - 'events-admin-css', |
|
| 573 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 574 | - [], |
|
| 575 | - EVENT_ESPRESSO_VERSION |
|
| 576 | - ); |
|
| 577 | - wp_register_style( |
|
| 578 | - 'ee-cat-admin', |
|
| 579 | - EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 580 | - [], |
|
| 581 | - EVENT_ESPRESSO_VERSION |
|
| 582 | - ); |
|
| 583 | - wp_enqueue_style('events-admin-css'); |
|
| 584 | - wp_enqueue_style('ee-cat-admin'); |
|
| 585 | - // scripts |
|
| 586 | - wp_register_script( |
|
| 587 | - 'event_editor_js', |
|
| 588 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 589 | - ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 590 | - EVENT_ESPRESSO_VERSION, |
|
| 591 | - true |
|
| 592 | - ); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Enqueuing scripts and styles specific to this view |
|
| 598 | - */ |
|
| 599 | - public function load_scripts_styles_create_new() |
|
| 600 | - { |
|
| 601 | - $this->load_scripts_styles_edit(); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * Enqueuing scripts and styles specific to this view |
|
| 607 | - */ |
|
| 608 | - public function load_scripts_styles_edit() |
|
| 609 | - { |
|
| 610 | - // styles |
|
| 611 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 612 | - wp_register_style( |
|
| 613 | - 'event-editor-css', |
|
| 614 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 615 | - ['ee-admin-css'], |
|
| 616 | - EVENT_ESPRESSO_VERSION |
|
| 617 | - ); |
|
| 618 | - wp_enqueue_style('event-editor-css'); |
|
| 619 | - // scripts |
|
| 620 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 621 | - wp_register_script( |
|
| 622 | - 'event-datetime-metabox', |
|
| 623 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 624 | - ['event_editor_js', 'ee-datepicker'], |
|
| 625 | - EVENT_ESPRESSO_VERSION |
|
| 626 | - ); |
|
| 627 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Populating the _views property for the category list table view. |
|
| 634 | - */ |
|
| 635 | - protected function _set_list_table_views_category_list() |
|
| 636 | - { |
|
| 637 | - $this->_views = [ |
|
| 638 | - 'all' => [ |
|
| 639 | - 'slug' => 'all', |
|
| 640 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 641 | - 'count' => 0, |
|
| 642 | - 'bulk_action' => [ |
|
| 643 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 644 | - ], |
|
| 645 | - ], |
|
| 646 | - ]; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 652 | - */ |
|
| 653 | - public function admin_init() |
|
| 654 | - { |
|
| 655 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 656 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 657 | - 'event_espresso' |
|
| 658 | - ); |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 664 | - * group. |
|
| 665 | - */ |
|
| 666 | - public function admin_notices() |
|
| 667 | - { |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 673 | - * this admin page group. |
|
| 674 | - */ |
|
| 675 | - public function admin_footer_scripts() |
|
| 676 | - { |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 682 | - * warning (via EE_Error::add_error()); |
|
| 683 | - * |
|
| 684 | - * @param EE_Event $event Event object |
|
| 685 | - * @param string $req_type |
|
| 686 | - * @return void |
|
| 687 | - * @throws EE_Error |
|
| 688 | - * @access public |
|
| 689 | - */ |
|
| 690 | - public function verify_event_edit($event = null, $req_type = '') |
|
| 691 | - { |
|
| 692 | - // don't need to do this when processing |
|
| 693 | - if (! empty($req_type)) { |
|
| 694 | - return; |
|
| 695 | - } |
|
| 696 | - // no event? |
|
| 697 | - if (! $event instanceof EE_Event) { |
|
| 698 | - $event = $this->_cpt_model_obj; |
|
| 699 | - } |
|
| 700 | - // STILL no event? |
|
| 701 | - if (! $event instanceof EE_Event) { |
|
| 702 | - return; |
|
| 703 | - } |
|
| 704 | - $orig_status = $event->status(); |
|
| 705 | - // first check if event is active. |
|
| 706 | - if ( |
|
| 707 | - $orig_status === EEM_Event::cancelled |
|
| 708 | - || $orig_status === EEM_Event::postponed |
|
| 709 | - || $event->is_expired() |
|
| 710 | - || $event->is_inactive() |
|
| 711 | - ) { |
|
| 712 | - return; |
|
| 713 | - } |
|
| 714 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
| 715 | - if ($event->is_sold_out(true)) { |
|
| 716 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 717 | - EE_Error::add_attention( |
|
| 718 | - sprintf( |
|
| 719 | - esc_html__( |
|
| 720 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 721 | - 'event_espresso' |
|
| 722 | - ), |
|
| 723 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 724 | - ) |
|
| 725 | - ); |
|
| 726 | - } |
|
| 727 | - return; |
|
| 728 | - } |
|
| 729 | - if ($orig_status === EEM_Event::sold_out) { |
|
| 730 | - EE_Error::add_attention( |
|
| 731 | - sprintf( |
|
| 732 | - esc_html__( |
|
| 733 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 734 | - 'event_espresso' |
|
| 735 | - ), |
|
| 736 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 737 | - ) |
|
| 738 | - ); |
|
| 739 | - } |
|
| 740 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 741 | - if (! $event->tickets_on_sale()) { |
|
| 742 | - return; |
|
| 743 | - } |
|
| 744 | - // made it here so show warning |
|
| 745 | - $this->_edit_event_warning(); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 751 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 752 | - * |
|
| 753 | - * @access protected |
|
| 754 | - * @return void |
|
| 755 | - */ |
|
| 756 | - protected function _edit_event_warning() |
|
| 757 | - { |
|
| 758 | - // we don't want to add warnings during these requests |
|
| 759 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 760 | - return; |
|
| 761 | - } |
|
| 762 | - EE_Error::add_attention( |
|
| 763 | - sprintf( |
|
| 764 | - esc_html__( |
|
| 765 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 766 | - 'event_espresso' |
|
| 767 | - ), |
|
| 768 | - '<a class="espresso-help-tab-lnk">', |
|
| 769 | - '</a>' |
|
| 770 | - ) |
|
| 771 | - ); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 777 | - * Otherwise, do the normal logic |
|
| 778 | - * |
|
| 779 | - * @throws EE_Error |
|
| 780 | - * @throws InvalidArgumentException |
|
| 781 | - * @throws InvalidDataTypeException |
|
| 782 | - */ |
|
| 783 | - protected function _create_new_cpt_item() |
|
| 784 | - { |
|
| 785 | - $has_timezone_string = get_option('timezone_string'); |
|
| 786 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 787 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 788 | - EE_Error::add_attention( |
|
| 789 | - sprintf( |
|
| 790 | - __( |
|
| 791 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
| 792 | - 'event_espresso' |
|
| 793 | - ), |
|
| 794 | - '<br>', |
|
| 795 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 796 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 797 | - . '</select>', |
|
| 798 | - '<button class="button button-secondary timezone-submit">', |
|
| 799 | - '</button><span class="spinner"></span>' |
|
| 800 | - ), |
|
| 801 | - __FILE__, |
|
| 802 | - __FUNCTION__, |
|
| 803 | - __LINE__ |
|
| 804 | - ); |
|
| 805 | - } |
|
| 806 | - parent::_create_new_cpt_item(); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - |
|
| 810 | - /** |
|
| 811 | - * Sets the _views property for the default route in this admin page group. |
|
| 812 | - */ |
|
| 813 | - protected function _set_list_table_views_default() |
|
| 814 | - { |
|
| 815 | - $this->_views = [ |
|
| 816 | - 'all' => [ |
|
| 817 | - 'slug' => 'all', |
|
| 818 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 819 | - 'count' => 0, |
|
| 820 | - 'bulk_action' => [ |
|
| 821 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 822 | - ], |
|
| 823 | - ], |
|
| 824 | - 'draft' => [ |
|
| 825 | - 'slug' => 'draft', |
|
| 826 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 827 | - 'count' => 0, |
|
| 828 | - 'bulk_action' => [ |
|
| 829 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 830 | - ], |
|
| 831 | - ], |
|
| 832 | - ]; |
|
| 833 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 834 | - $this->_views['trash'] = [ |
|
| 835 | - 'slug' => 'trash', |
|
| 836 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 837 | - 'count' => 0, |
|
| 838 | - 'bulk_action' => [ |
|
| 839 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 840 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 841 | - ], |
|
| 842 | - ]; |
|
| 843 | - } |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * Provides the legend item array for the default list table view. |
|
| 849 | - * |
|
| 850 | - * @return array |
|
| 851 | - */ |
|
| 852 | - protected function _event_legend_items() |
|
| 853 | - { |
|
| 854 | - $items = [ |
|
| 855 | - 'view_details' => [ |
|
| 856 | - 'class' => 'dashicons dashicons-search', |
|
| 857 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 858 | - ], |
|
| 859 | - 'edit_event' => [ |
|
| 860 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 861 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 862 | - ], |
|
| 863 | - 'view_attendees' => [ |
|
| 864 | - 'class' => 'dashicons dashicons-groups', |
|
| 865 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 866 | - ], |
|
| 867 | - ]; |
|
| 868 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 869 | - $statuses = [ |
|
| 870 | - 'sold_out_status' => [ |
|
| 871 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 872 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 873 | - ], |
|
| 874 | - 'active_status' => [ |
|
| 875 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 876 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 877 | - ], |
|
| 878 | - 'upcoming_status' => [ |
|
| 879 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 880 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 881 | - ], |
|
| 882 | - 'postponed_status' => [ |
|
| 883 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 884 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 885 | - ], |
|
| 886 | - 'cancelled_status' => [ |
|
| 887 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 888 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 889 | - ], |
|
| 890 | - 'expired_status' => [ |
|
| 891 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 892 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 893 | - ], |
|
| 894 | - 'inactive_status' => [ |
|
| 895 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 896 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 897 | - ], |
|
| 898 | - ]; |
|
| 899 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 900 | - return array_merge($items, $statuses); |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - /** |
|
| 905 | - * @return EEM_Event |
|
| 906 | - * @throws EE_Error |
|
| 907 | - */ |
|
| 908 | - private function eventModel() |
|
| 909 | - { |
|
| 910 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 911 | - $this->_event_model = EEM_Event::instance(); |
|
| 912 | - } |
|
| 913 | - return $this->_event_model; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * @param string $event_timezone_string |
|
| 919 | - * @return EEM_Datetime |
|
| 920 | - * @throws EE_Error |
|
| 921 | - */ |
|
| 922 | - private function datetimeModel($event_timezone_string = '') |
|
| 923 | - { |
|
| 924 | - if (! $this->datetime_model instanceof EEM_Datetime) { |
|
| 925 | - $this->datetime_model = EEM_Datetime::instance($event_timezone_string); |
|
| 926 | - } |
|
| 927 | - return $this->datetime_model; |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * @param string $event_timezone_string |
|
| 933 | - * @return EEM_Ticket |
|
| 934 | - * @throws EE_Error |
|
| 935 | - */ |
|
| 936 | - private function ticketModel($event_timezone_string = '') |
|
| 937 | - { |
|
| 938 | - if (! $this->ticket_model instanceof EEM_Ticket) { |
|
| 939 | - $this->ticket_model = EEM_Ticket::instance($event_timezone_string); |
|
| 940 | - } |
|
| 941 | - return $this->ticket_model; |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - /** |
|
| 946 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 947 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 948 | - * |
|
| 949 | - * @param string $return the current html |
|
| 950 | - * @param int $id the post id for the page |
|
| 951 | - * @param string $new_title What the title is |
|
| 952 | - * @param string $new_slug what the slug is |
|
| 953 | - * @return string The new html string for the permalink area |
|
| 954 | - */ |
|
| 955 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 956 | - { |
|
| 957 | - // make sure this is only when editing |
|
| 958 | - if (! empty($id)) { |
|
| 959 | - $post = get_post($id); |
|
| 960 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 961 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 962 | - . '</a> '; |
|
| 963 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 964 | - . $post->ID |
|
| 965 | - . ']">'; |
|
| 966 | - } |
|
| 967 | - return $return; |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * _events_overview_list_table |
|
| 973 | - * This contains the logic for showing the events_overview list |
|
| 974 | - * |
|
| 975 | - * @access protected |
|
| 976 | - * @return void |
|
| 977 | - * @throws DomainException |
|
| 978 | - * @throws EE_Error |
|
| 979 | - * @throws InvalidArgumentException |
|
| 980 | - * @throws InvalidDataTypeException |
|
| 981 | - * @throws InvalidInterfaceException |
|
| 982 | - */ |
|
| 983 | - protected function _events_overview_list_table() |
|
| 984 | - { |
|
| 985 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 986 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 987 | - ? (array) $this->_template_args['after_list_table'] |
|
| 988 | - : []; |
|
| 989 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 990 | - . EEH_Template::get_button_or_link( |
|
| 991 | - get_post_type_archive_link('espresso_events'), |
|
| 992 | - esc_html__('View Event Archive Page', 'event_espresso'), |
|
| 993 | - 'button' |
|
| 994 | - ); |
|
| 995 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 996 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 997 | - 'create_new', |
|
| 998 | - 'add', |
|
| 999 | - [], |
|
| 1000 | - 'add-new-h2' |
|
| 1001 | - ); |
|
| 1002 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * this allows for extra misc actions in the default WP publish box |
|
| 1008 | - * |
|
| 1009 | - * @return void |
|
| 1010 | - * @throws DomainException |
|
| 1011 | - * @throws EE_Error |
|
| 1012 | - * @throws InvalidArgumentException |
|
| 1013 | - * @throws InvalidDataTypeException |
|
| 1014 | - * @throws InvalidInterfaceException |
|
| 1015 | - * @throws ReflectionException |
|
| 1016 | - */ |
|
| 1017 | - public function extra_misc_actions_publish_box() |
|
| 1018 | - { |
|
| 1019 | - $this->_generate_publish_box_extra_content(); |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - |
|
| 1023 | - /** |
|
| 1024 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1025 | - * saved. |
|
| 1026 | - * Typically you would use this to save any additional data. |
|
| 1027 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1028 | - * ALSO very important. When a post transitions from scheduled to published, |
|
| 1029 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1030 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1031 | - * |
|
| 1032 | - * @access protected |
|
| 1033 | - * @abstract |
|
| 1034 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1035 | - * @param object $post The post object of the cpt that was saved. |
|
| 1036 | - * @return void |
|
| 1037 | - * @throws EE_Error |
|
| 1038 | - * @throws InvalidArgumentException |
|
| 1039 | - * @throws InvalidDataTypeException |
|
| 1040 | - * @throws InvalidInterfaceException |
|
| 1041 | - * @throws ReflectionException |
|
| 1042 | - */ |
|
| 1043 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 1044 | - { |
|
| 1045 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1046 | - // get out we're not processing an event save. |
|
| 1047 | - return; |
|
| 1048 | - } |
|
| 1049 | - $event_values = [ |
|
| 1050 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 1051 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 1052 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 1053 | - ? sanitize_text_field($this->_req_data['timezone_string']) |
|
| 1054 | - : null, |
|
| 1055 | - ]; |
|
| 1056 | - /** @var FeatureFlags $flags */ |
|
| 1057 | - $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags'); |
|
| 1058 | - // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
| 1059 | - if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1060 | - $event_values['EVT_display_ticket_selector'] = |
|
| 1061 | - ! empty($this->_req_data['display_ticket_selector']) |
|
| 1062 | - ? 1 |
|
| 1063 | - : 0; |
|
| 1064 | - $event_values['EVT_additional_limit'] = min( |
|
| 1065 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1066 | - ! empty($this->_req_data['additional_limit']) |
|
| 1067 | - ? absint($this->_req_data['additional_limit']) |
|
| 1068 | - : null |
|
| 1069 | - ); |
|
| 1070 | - $event_values['EVT_default_registration_status'] = |
|
| 1071 | - ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 1072 | - ? sanitize_text_field($this->_req_data['EVT_default_registration_status']) |
|
| 1073 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 1074 | - $event_values['EVT_external_URL'] = ! empty($this->_req_data['externalURL']) |
|
| 1075 | - ? esc_url_raw($this->_req_data['externalURL']) |
|
| 1076 | - : null; |
|
| 1077 | - $event_values['EVT_phone'] = ! empty($this->_req_data['event_phone']) |
|
| 1078 | - ? sanitize_text_field($this->_req_data['event_phone']) |
|
| 1079 | - : null; |
|
| 1080 | - } |
|
| 1081 | - // update event |
|
| 1082 | - $success = $this->eventModel()->update_by_ID($event_values, $post_id); |
|
| 1083 | - // get event_object for other metaboxes... |
|
| 1084 | - // though it would seem to make sense to just use $this->eventModel()->get_one_by_ID( $post_id ).. |
|
| 1085 | - // i have to setup where conditions to override the filters in the model |
|
| 1086 | - // that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 1087 | - $get_one_where = [ |
|
| 1088 | - $this->eventModel()->primary_key_name() => $post_id, |
|
| 1089 | - 'OR' => [ |
|
| 1090 | - 'status' => $post->post_status, |
|
| 1091 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1092 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1093 | - 'status*1' => $this->_req_data['original_post_status'], |
|
| 1094 | - ], |
|
| 1095 | - ]; |
|
| 1096 | - $event = $this->eventModel()->get_one([$get_one_where]); |
|
| 1097 | - // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 1098 | - $event_update_callbacks = apply_filters( |
|
| 1099 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1100 | - [ |
|
| 1101 | - [$this, '_default_venue_update'], |
|
| 1102 | - [$this, '_default_tickets_update'], |
|
| 1103 | - ] |
|
| 1104 | - ); |
|
| 1105 | - $att_success = true; |
|
| 1106 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 1107 | - $_success = is_callable($e_callback) |
|
| 1108 | - ? $e_callback($event, $this->_req_data) |
|
| 1109 | - : false; |
|
| 1110 | - // if ANY of these updates fail then we want the appropriate global error message |
|
| 1111 | - $att_success = ! $att_success ? $att_success : $_success; |
|
| 1112 | - } |
|
| 1113 | - // any errors? |
|
| 1114 | - if ($success && false === $att_success) { |
|
| 1115 | - EE_Error::add_error( |
|
| 1116 | - esc_html__( |
|
| 1117 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1118 | - 'event_espresso' |
|
| 1119 | - ), |
|
| 1120 | - __FILE__, |
|
| 1121 | - __FUNCTION__, |
|
| 1122 | - __LINE__ |
|
| 1123 | - ); |
|
| 1124 | - } elseif ($success === false) { |
|
| 1125 | - EE_Error::add_error( |
|
| 1126 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1127 | - __FILE__, |
|
| 1128 | - __FUNCTION__, |
|
| 1129 | - __LINE__ |
|
| 1130 | - ); |
|
| 1131 | - } |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - |
|
| 1135 | - /** |
|
| 1136 | - * @param int $post_id |
|
| 1137 | - * @param int $revision_id |
|
| 1138 | - * @throws EE_Error |
|
| 1139 | - * @throws InvalidArgumentException |
|
| 1140 | - * @throws InvalidDataTypeException |
|
| 1141 | - * @throws InvalidInterfaceException |
|
| 1142 | - * @throws ReflectionException |
|
| 1143 | - * @see parent::restore_item() |
|
| 1144 | - */ |
|
| 1145 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1146 | - { |
|
| 1147 | - // copy existing event meta to new post |
|
| 1148 | - $post_evt = $this->eventModel()->get_one_by_ID($post_id); |
|
| 1149 | - if ($post_evt instanceof EE_Event) { |
|
| 1150 | - // meta revision restore |
|
| 1151 | - $post_evt->restore_revision($revision_id); |
|
| 1152 | - // related objs restore |
|
| 1153 | - $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * Attach the venue to the Event |
|
| 1160 | - * |
|
| 1161 | - * @param EE_Event $evtobj Event Object to add the venue to |
|
| 1162 | - * @param array $data The request data from the form |
|
| 1163 | - * @return bool Success or fail. |
|
| 1164 | - * @throws EE_Error |
|
| 1165 | - * @throws InvalidArgumentException |
|
| 1166 | - * @throws InvalidDataTypeException |
|
| 1167 | - * @throws InvalidInterfaceException |
|
| 1168 | - * @throws ReflectionException |
|
| 1169 | - */ |
|
| 1170 | - protected function _default_venue_update(EE_Event $evtobj, $data) |
|
| 1171 | - { |
|
| 1172 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1173 | - $venue_model = EEM_Venue::instance(); |
|
| 1174 | - $rows_affected = null; |
|
| 1175 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1176 | - // very important. If we don't have a venue name... |
|
| 1177 | - // then we'll get out because not necessary to create empty venue |
|
| 1178 | - if (empty($data['venue_title'])) { |
|
| 1179 | - return false; |
|
| 1180 | - } |
|
| 1181 | - $venue_array = [ |
|
| 1182 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1183 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1184 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1185 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1186 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1187 | - : null, |
|
| 1188 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1189 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1190 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1191 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1192 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1193 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1194 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1195 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1196 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1197 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1198 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1199 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1200 | - 'status' => 'publish', |
|
| 1201 | - ]; |
|
| 1202 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1203 | - if (! empty($venue_id)) { |
|
| 1204 | - $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1205 | - $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1206 | - // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1207 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1208 | - return $rows_affected > 0; |
|
| 1209 | - } |
|
| 1210 | - // we insert the venue |
|
| 1211 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1212 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1213 | - return ! empty($venue_id) ? true : false; |
|
| 1214 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1220 | - * |
|
| 1221 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1222 | - * @param array $data The request data from the form |
|
| 1223 | - * @return array |
|
| 1224 | - * @throws EE_Error |
|
| 1225 | - * @throws InvalidArgumentException |
|
| 1226 | - * @throws InvalidDataTypeException |
|
| 1227 | - * @throws InvalidInterfaceException |
|
| 1228 | - * @throws ReflectionException |
|
| 1229 | - * @throws Exception |
|
| 1230 | - */ |
|
| 1231 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1232 | - { |
|
| 1233 | - if ($this->admin_config->useAdvancedEditor()) { |
|
| 1234 | - return []; |
|
| 1235 | - } |
|
| 1236 | - $saved_dtt = null; |
|
| 1237 | - $saved_tickets = []; |
|
| 1238 | - $incoming_date_formats = ['Y-m-d', 'h:i a']; |
|
| 1239 | - $event_timezone_string = $evtobj->get_timezone(); |
|
| 1240 | - $event_timezone = new DateTimeZone($event_timezone_string); |
|
| 1241 | - // let's use now in the set timezone. |
|
| 1242 | - $now = new DateTime('now', $event_timezone); |
|
| 1243 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1244 | - // trim all values to ensure any excess whitespace is removed. |
|
| 1245 | - $dtt = array_map('trim', $dtt); |
|
| 1246 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) |
|
| 1247 | - ? $dtt['DTT_EVT_end'] |
|
| 1248 | - : $dtt['DTT_EVT_start']; |
|
| 1249 | - $datetime_values = [ |
|
| 1250 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1251 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1252 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1253 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1254 | - 'DTT_order' => $row, |
|
| 1255 | - ]; |
|
| 1256 | - // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1257 | - if (! empty($dtt['DTT_ID'])) { |
|
| 1258 | - $DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']); |
|
| 1259 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1260 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1261 | - foreach ($datetime_values as $field => $value) { |
|
| 1262 | - $DTM->set($field, $value); |
|
| 1263 | - } |
|
| 1264 | - // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1265 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1266 | - } else { |
|
| 1267 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1268 | - 'Datetime', |
|
| 1269 | - [$datetime_values, $event_timezone_string, $incoming_date_formats], |
|
| 1270 | - false, |
|
| 1271 | - false |
|
| 1272 | - ); |
|
| 1273 | - foreach ($datetime_values as $field => $value) { |
|
| 1274 | - $DTM->set($field, $value); |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1277 | - $DTM->save(); |
|
| 1278 | - $DTM = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1279 | - // load DTT helper |
|
| 1280 | - // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1281 | - if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) { |
|
| 1282 | - $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start')); |
|
| 1283 | - $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days'); |
|
| 1284 | - $DTM->save(); |
|
| 1285 | - } |
|
| 1286 | - // now we got to make sure we add the new DTT_ID to the $saved_dtts array |
|
| 1287 | - // because it is possible there was a new one created for the autosave. |
|
| 1288 | - $saved_dtt = $DTM; |
|
| 1289 | - // if ANY of these updates fail then we want the appropriate global error message. |
|
| 1290 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1291 | - } |
|
| 1292 | - // no dtts get deleted so we don't do any of that logic here. |
|
| 1293 | - // update tickets next |
|
| 1294 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1295 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1296 | - $incoming_date_formats = ['Y-m-d', 'h:i a']; |
|
| 1297 | - $update_prices = false; |
|
| 1298 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1299 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
| 1300 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1301 | - $tkt = array_map('trim', $tkt); |
|
| 1302 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1303 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1304 | - } |
|
| 1305 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1306 | - // use the start date of the first datetime |
|
| 1307 | - $dtt = $evtobj->first_datetime(); |
|
| 1308 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1309 | - $incoming_date_formats[0], |
|
| 1310 | - $incoming_date_formats[1] |
|
| 1311 | - ); |
|
| 1312 | - } |
|
| 1313 | - $TKT_values = [ |
|
| 1314 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1315 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1316 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1317 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1318 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1319 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1320 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1321 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1322 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1323 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1324 | - 'TKT_row' => $row, |
|
| 1325 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1326 | - 'TKT_price' => $ticket_price, |
|
| 1327 | - ]; |
|
| 1328 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1329 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1330 | - $TKT_values['TKT_ID'] = 0; |
|
| 1331 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1332 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1333 | - $update_prices = true; |
|
| 1334 | - } |
|
| 1335 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1336 | - // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1337 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1338 | - if (! empty($tkt['TKT_ID'])) { |
|
| 1339 | - $TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']); |
|
| 1340 | - if ($TKT instanceof EE_Ticket) { |
|
| 1341 | - $ticket_sold = $TKT->count_related( |
|
| 1342 | - 'Registration', |
|
| 1343 | - [ |
|
| 1344 | - [ |
|
| 1345 | - 'STS_ID' => [ |
|
| 1346 | - 'NOT IN', |
|
| 1347 | - [EEM_Registration::status_id_incomplete], |
|
| 1348 | - ], |
|
| 1349 | - ], |
|
| 1350 | - ] |
|
| 1351 | - ) > 0; |
|
| 1352 | - // let's just check the total price for the existing ticket and determine if it matches the new |
|
| 1353 | - // total price. if they are different then we create a new ticket (if tickets sold) |
|
| 1354 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 1355 | - $create_new_TKT = $ticket_sold && ! $TKT->deleted() |
|
| 1356 | - && EEH_Money::compare_floats( |
|
| 1357 | - $ticket_price, |
|
| 1358 | - $TKT->get('TKT_price'), |
|
| 1359 | - '!==' |
|
| 1360 | - ); |
|
| 1361 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1362 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1363 | - // set new values |
|
| 1364 | - foreach ($TKT_values as $field => $value) { |
|
| 1365 | - if ($field === 'TKT_qty') { |
|
| 1366 | - $TKT->set_qty($value); |
|
| 1367 | - } else { |
|
| 1368 | - $TKT->set($field, $value); |
|
| 1369 | - } |
|
| 1370 | - } |
|
| 1371 | - // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1372 | - if ($create_new_TKT) { |
|
| 1373 | - // archive the old ticket first |
|
| 1374 | - $TKT->set('TKT_deleted', 1); |
|
| 1375 | - $TKT->save(); |
|
| 1376 | - // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1377 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1378 | - // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1379 | - $TKT = clone $TKT; |
|
| 1380 | - $TKT->set('TKT_ID', 0); |
|
| 1381 | - $TKT->set('TKT_deleted', 0); |
|
| 1382 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1383 | - $TKT->set('TKT_sold', 0); |
|
| 1384 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1385 | - $update_prices = true; |
|
| 1386 | - } |
|
| 1387 | - // make sure price is set if it hasn't been already |
|
| 1388 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1389 | - } |
|
| 1390 | - } else { |
|
| 1391 | - // no TKT_id so a new TKT |
|
| 1392 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1393 | - $TKT = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false); |
|
| 1394 | - if ($TKT instanceof EE_Ticket) { |
|
| 1395 | - // need to reset values to properly account for the date formats |
|
| 1396 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1397 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1398 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1399 | - // set new values |
|
| 1400 | - foreach ($TKT_values as $field => $value) { |
|
| 1401 | - if ($field === 'TKT_qty') { |
|
| 1402 | - $TKT->set_qty($value); |
|
| 1403 | - } else { |
|
| 1404 | - $TKT->set($field, $value); |
|
| 1405 | - } |
|
| 1406 | - } |
|
| 1407 | - $update_prices = true; |
|
| 1408 | - } |
|
| 1409 | - } |
|
| 1410 | - // cap ticket qty by datetime reg limits |
|
| 1411 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1412 | - // update ticket. |
|
| 1413 | - $TKT->save(); |
|
| 1414 | - // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1415 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1416 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1417 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1418 | - $TKT->save(); |
|
| 1419 | - } |
|
| 1420 | - // initially let's add the ticket to the dtt |
|
| 1421 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1422 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1423 | - // add prices to ticket |
|
| 1424 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1425 | - } |
|
| 1426 | - // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1427 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
| 1428 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1429 | - foreach ($tickets_removed as $id) { |
|
| 1430 | - $id = absint($id); |
|
| 1431 | - // get the ticket for this id |
|
| 1432 | - $tkt_to_remove = $this->ticketModel($event_timezone_string)->get_one_by_ID($id); |
|
| 1433 | - // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1434 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1435 | - foreach ($dtts as $dtt) { |
|
| 1436 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1437 | - } |
|
| 1438 | - // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1439 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1440 | - // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1441 | - $tkt_to_remove->delete_permanently(); |
|
| 1442 | - } |
|
| 1443 | - return [$saved_dtt, $saved_tickets]; |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - |
|
| 1447 | - /** |
|
| 1448 | - * This attaches a list of given prices to a ticket. |
|
| 1449 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1450 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1451 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1452 | - * |
|
| 1453 | - * @access private |
|
| 1454 | - * @param array $prices Array of prices from the form. |
|
| 1455 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1456 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1457 | - * @return void |
|
| 1458 | - * @throws EE_Error |
|
| 1459 | - * @throws InvalidArgumentException |
|
| 1460 | - * @throws InvalidDataTypeException |
|
| 1461 | - * @throws InvalidInterfaceException |
|
| 1462 | - * @throws ReflectionException |
|
| 1463 | - */ |
|
| 1464 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1465 | - { |
|
| 1466 | - foreach ($prices as $row => $prc) { |
|
| 1467 | - $PRC_values = [ |
|
| 1468 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1469 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1470 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1471 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1472 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1473 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1474 | - 'PRC_order' => $row, |
|
| 1475 | - ]; |
|
| 1476 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1477 | - $PRC_values['PRC_ID'] = 0; |
|
| 1478 | - $PRC = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false); |
|
| 1479 | - } else { |
|
| 1480 | - $PRC = EEM_Price::instance()->get_one_by_ID($prc['PRC_ID']); |
|
| 1481 | - // update this price with new values |
|
| 1482 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1483 | - $PRC->set($field, $newprc); |
|
| 1484 | - } |
|
| 1485 | - $PRC->save(); |
|
| 1486 | - } |
|
| 1487 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1488 | - } |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - |
|
| 1492 | - /** |
|
| 1493 | - * Add in our autosave ajax handlers |
|
| 1494 | - * |
|
| 1495 | - */ |
|
| 1496 | - protected function _ee_autosave_create_new() |
|
| 1497 | - { |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - |
|
| 1501 | - /** |
|
| 1502 | - * More autosave handlers. |
|
| 1503 | - */ |
|
| 1504 | - protected function _ee_autosave_edit() |
|
| 1505 | - { |
|
| 1506 | - } |
|
| 1507 | - |
|
| 1508 | - |
|
| 1509 | - /** |
|
| 1510 | - * _generate_publish_box_extra_content |
|
| 1511 | - * |
|
| 1512 | - * @throws DomainException |
|
| 1513 | - * @throws EE_Error |
|
| 1514 | - * @throws InvalidArgumentException |
|
| 1515 | - * @throws InvalidDataTypeException |
|
| 1516 | - * @throws InvalidInterfaceException |
|
| 1517 | - * @throws ReflectionException |
|
| 1518 | - */ |
|
| 1519 | - private function _generate_publish_box_extra_content() |
|
| 1520 | - { |
|
| 1521 | - // load formatter helper |
|
| 1522 | - // args for getting related registrations |
|
| 1523 | - $approved_query_args = [ |
|
| 1524 | - [ |
|
| 1525 | - 'REG_deleted' => 0, |
|
| 1526 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1527 | - ], |
|
| 1528 | - ]; |
|
| 1529 | - $not_approved_query_args = [ |
|
| 1530 | - [ |
|
| 1531 | - 'REG_deleted' => 0, |
|
| 1532 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1533 | - ], |
|
| 1534 | - ]; |
|
| 1535 | - $pending_payment_query_args = [ |
|
| 1536 | - [ |
|
| 1537 | - 'REG_deleted' => 0, |
|
| 1538 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1539 | - ], |
|
| 1540 | - ]; |
|
| 1541 | - // publish box |
|
| 1542 | - $publish_box_extra_args = [ |
|
| 1543 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1544 | - [ |
|
| 1545 | - 'action' => 'default', |
|
| 1546 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1547 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1548 | - ], |
|
| 1549 | - REG_ADMIN_URL |
|
| 1550 | - ), |
|
| 1551 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1552 | - [ |
|
| 1553 | - 'action' => 'default', |
|
| 1554 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1555 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1556 | - ], |
|
| 1557 | - REG_ADMIN_URL |
|
| 1558 | - ), |
|
| 1559 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1560 | - [ |
|
| 1561 | - 'action' => 'default', |
|
| 1562 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1563 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1564 | - ], |
|
| 1565 | - REG_ADMIN_URL |
|
| 1566 | - ), |
|
| 1567 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1568 | - 'Registration', |
|
| 1569 | - $approved_query_args |
|
| 1570 | - ), |
|
| 1571 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1572 | - 'Registration', |
|
| 1573 | - $not_approved_query_args |
|
| 1574 | - ), |
|
| 1575 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1576 | - 'Registration', |
|
| 1577 | - $pending_payment_query_args |
|
| 1578 | - ), |
|
| 1579 | - 'misc_pub_section_class' => apply_filters( |
|
| 1580 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1581 | - 'misc-pub-section' |
|
| 1582 | - ), |
|
| 1583 | - ]; |
|
| 1584 | - ob_start(); |
|
| 1585 | - do_action( |
|
| 1586 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1587 | - $this->_cpt_model_obj |
|
| 1588 | - ); |
|
| 1589 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1590 | - // load template |
|
| 1591 | - EEH_Template::display_template( |
|
| 1592 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1593 | - $publish_box_extra_args |
|
| 1594 | - ); |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - |
|
| 1598 | - /** |
|
| 1599 | - * @return EE_Event |
|
| 1600 | - */ |
|
| 1601 | - public function get_event_object() |
|
| 1602 | - { |
|
| 1603 | - return $this->_cpt_model_obj; |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - /** METABOXES * */ |
|
| 1610 | - /** |
|
| 1611 | - * _register_event_editor_meta_boxes |
|
| 1612 | - * add all metaboxes related to the event_editor |
|
| 1613 | - * |
|
| 1614 | - * @return void |
|
| 1615 | - * @throws EE_Error |
|
| 1616 | - * @throws InvalidArgumentException |
|
| 1617 | - * @throws InvalidDataTypeException |
|
| 1618 | - * @throws InvalidInterfaceException |
|
| 1619 | - * @throws ReflectionException |
|
| 1620 | - */ |
|
| 1621 | - protected function _register_event_editor_meta_boxes() |
|
| 1622 | - { |
|
| 1623 | - $this->verify_cpt_object(); |
|
| 1624 | - $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
| 1625 | - /** @var FeatureFlags $flags */ |
|
| 1626 | - $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags'); |
|
| 1627 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1628 | - if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1629 | - add_meta_box( |
|
| 1630 | - 'espresso_event_editor_event_options', |
|
| 1631 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1632 | - [$this, 'registration_options_meta_box'], |
|
| 1633 | - $this->page_slug, |
|
| 1634 | - 'side' |
|
| 1635 | - ); |
|
| 1636 | - } |
|
| 1637 | - if (! $use_advanced_editor) { |
|
| 1638 | - add_meta_box( |
|
| 1639 | - 'espresso_event_editor_tickets', |
|
| 1640 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1641 | - [$this, 'ticket_metabox'], |
|
| 1642 | - $this->page_slug, |
|
| 1643 | - 'normal', |
|
| 1644 | - 'high' |
|
| 1645 | - ); |
|
| 1646 | - } else { |
|
| 1647 | - if ($flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1648 | - add_action( |
|
| 1649 | - 'add_meta_boxes_espresso_events', |
|
| 1650 | - function () { |
|
| 1651 | - global $current_screen; |
|
| 1652 | - remove_meta_box('authordiv', $current_screen, 'normal'); |
|
| 1653 | - }, |
|
| 1654 | - 99 |
|
| 1655 | - ); |
|
| 1656 | - } |
|
| 1657 | - } |
|
| 1658 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1659 | - // where a metabox has a related management page in the admin |
|
| 1660 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1661 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1662 | - } |
|
| 1663 | - |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * @throws DomainException |
|
| 1667 | - * @throws EE_Error |
|
| 1668 | - * @throws InvalidArgumentException |
|
| 1669 | - * @throws InvalidDataTypeException |
|
| 1670 | - * @throws InvalidInterfaceException |
|
| 1671 | - * @throws ReflectionException |
|
| 1672 | - */ |
|
| 1673 | - public function ticket_metabox() |
|
| 1674 | - { |
|
| 1675 | - $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1676 | - // defaults for template args |
|
| 1677 | - $template_args = [ |
|
| 1678 | - 'existing_datetime_ids' => '', |
|
| 1679 | - 'event_datetime_help_link' => '', |
|
| 1680 | - 'ticket_options_help_link' => '', |
|
| 1681 | - 'time' => null, |
|
| 1682 | - 'ticket_rows' => '', |
|
| 1683 | - 'existing_ticket_ids' => '', |
|
| 1684 | - 'total_ticket_rows' => 1, |
|
| 1685 | - 'ticket_js_structure' => '', |
|
| 1686 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1687 | - 'disabled' => '', |
|
| 1688 | - ]; |
|
| 1689 | - $event_id = $this->_cpt_model_obj instanceof EE_Event ? $this->_cpt_model_obj->ID() : 0; |
|
| 1690 | - $event_timezone_string = $this->_cpt_model_obj instanceof EE_Event |
|
| 1691 | - ? $this->_cpt_model_obj->timezone_string() |
|
| 1692 | - : ''; |
|
| 1693 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1694 | - /** |
|
| 1695 | - * 1. Start with retrieving Datetimes |
|
| 1696 | - * 2. Fore each datetime get related tickets |
|
| 1697 | - * 3. For each ticket get related prices |
|
| 1698 | - */ |
|
| 1699 | - $times = $this->datetimeModel($event_timezone_string)->get_all_event_dates($event_id); |
|
| 1700 | - /** @type EE_Datetime $first_datetime */ |
|
| 1701 | - $first_datetime = reset($times); |
|
| 1702 | - // do we get related tickets? |
|
| 1703 | - if ( |
|
| 1704 | - $first_datetime instanceof EE_Datetime |
|
| 1705 | - && $first_datetime->ID() !== 0 |
|
| 1706 | - ) { |
|
| 1707 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1708 | - $template_args['time'] = $first_datetime; |
|
| 1709 | - $related_tickets = $first_datetime->tickets( |
|
| 1710 | - [ |
|
| 1711 | - ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1712 | - 'default_where_conditions' => 'none', |
|
| 1713 | - ] |
|
| 1714 | - ); |
|
| 1715 | - if (! empty($related_tickets)) { |
|
| 1716 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1717 | - $row = 0; |
|
| 1718 | - foreach ($related_tickets as $ticket) { |
|
| 1719 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1720 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1721 | - $row++; |
|
| 1722 | - } |
|
| 1723 | - } else { |
|
| 1724 | - $template_args['total_ticket_rows'] = 1; |
|
| 1725 | - /** @type EE_Ticket $ticket */ |
|
| 1726 | - $ticket = $this->ticketModel($event_timezone_string)->create_default_object(); |
|
| 1727 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1728 | - } |
|
| 1729 | - } else { |
|
| 1730 | - $template_args['time'] = $times[0]; |
|
| 1731 | - /** @type EE_Ticket $ticket */ |
|
| 1732 | - $ticket = $this->ticketModel($event_timezone_string)->get_all_default_tickets(); |
|
| 1733 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1734 | - // NOTE: we're just sending the first default row |
|
| 1735 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1736 | - } |
|
| 1737 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1738 | - 'event_editor_event_datetimes_help_tab' |
|
| 1739 | - ); |
|
| 1740 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1741 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1742 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1743 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1744 | - $this->ticketModel($event_timezone_string)->create_default_object(), |
|
| 1745 | - true |
|
| 1746 | - ); |
|
| 1747 | - $template = apply_filters( |
|
| 1748 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1749 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1750 | - ); |
|
| 1751 | - EEH_Template::display_template($template, $template_args); |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - |
|
| 1755 | - /** |
|
| 1756 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1757 | - * |
|
| 1758 | - * @access private |
|
| 1759 | - * @param EE_Ticket $ticket the ticket object |
|
| 1760 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1761 | - * @param int $row |
|
| 1762 | - * @return string generated html for the ticket row. |
|
| 1763 | - * @throws DomainException |
|
| 1764 | - * @throws EE_Error |
|
| 1765 | - * @throws InvalidArgumentException |
|
| 1766 | - * @throws InvalidDataTypeException |
|
| 1767 | - * @throws InvalidInterfaceException |
|
| 1768 | - * @throws ReflectionException |
|
| 1769 | - */ |
|
| 1770 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1771 | - { |
|
| 1772 | - $template_args = [ |
|
| 1773 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1774 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1775 | - : '', |
|
| 1776 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1777 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1778 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1779 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1780 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1781 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1782 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1783 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1784 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1785 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1786 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1787 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1788 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1789 | - : ' disabled=disabled', |
|
| 1790 | - ]; |
|
| 1791 | - $price = $ticket->ID() !== 0 |
|
| 1792 | - ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1793 | - : EEM_Price::instance()->create_default_object(); |
|
| 1794 | - $price_args = [ |
|
| 1795 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1796 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1797 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1798 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1799 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1800 | - ]; |
|
| 1801 | - // make sure we have default start and end dates if skeleton |
|
| 1802 | - // handle rows that should NOT be empty |
|
| 1803 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1804 | - // if empty then the start date will be now. |
|
| 1805 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1806 | - } |
|
| 1807 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1808 | - // get the earliest datetime (if present); |
|
| 1809 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1810 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1811 | - 'Datetime', |
|
| 1812 | - ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1813 | - ) |
|
| 1814 | - : null; |
|
| 1815 | - if (! empty($earliest_dtt)) { |
|
| 1816 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1817 | - } else { |
|
| 1818 | - $template_args['TKT_end_date'] = date( |
|
| 1819 | - 'Y-m-d h:i a', |
|
| 1820 | - mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')) |
|
| 1821 | - ); |
|
| 1822 | - } |
|
| 1823 | - } |
|
| 1824 | - $template_args = array_merge($template_args, $price_args); |
|
| 1825 | - $template = apply_filters( |
|
| 1826 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1827 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1828 | - $ticket |
|
| 1829 | - ); |
|
| 1830 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1831 | - } |
|
| 1832 | - |
|
| 1833 | - |
|
| 1834 | - /** |
|
| 1835 | - * @throws DomainException |
|
| 1836 | - * @throws EE_Error |
|
| 1837 | - */ |
|
| 1838 | - public function registration_options_meta_box() |
|
| 1839 | - { |
|
| 1840 | - $yes_no_values = [ |
|
| 1841 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1842 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1843 | - ]; |
|
| 1844 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1845 | - [ |
|
| 1846 | - EEM_Registration::status_id_cancelled, |
|
| 1847 | - EEM_Registration::status_id_declined, |
|
| 1848 | - EEM_Registration::status_id_incomplete, |
|
| 1849 | - ], |
|
| 1850 | - true |
|
| 1851 | - ); |
|
| 1852 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1853 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1854 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1855 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1856 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1857 | - 'default_reg_status', |
|
| 1858 | - $default_reg_status_values, |
|
| 1859 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1860 | - ); |
|
| 1861 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1862 | - 'display_desc', |
|
| 1863 | - $yes_no_values, |
|
| 1864 | - $this->_cpt_model_obj->display_description() |
|
| 1865 | - ); |
|
| 1866 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1867 | - 'display_ticket_selector', |
|
| 1868 | - $yes_no_values, |
|
| 1869 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1870 | - '', |
|
| 1871 | - '', |
|
| 1872 | - false |
|
| 1873 | - ); |
|
| 1874 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1875 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1876 | - '', |
|
| 1877 | - $template_args, |
|
| 1878 | - $yes_no_values, |
|
| 1879 | - $default_reg_status_values |
|
| 1880 | - ); |
|
| 1881 | - EEH_Template::display_template( |
|
| 1882 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1883 | - $template_args |
|
| 1884 | - ); |
|
| 1885 | - } |
|
| 1886 | - |
|
| 1887 | - |
|
| 1888 | - /** |
|
| 1889 | - * _get_events() |
|
| 1890 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1891 | - * |
|
| 1892 | - * @access public |
|
| 1893 | - * @param int $per_page count of items per page (20 default); |
|
| 1894 | - * @param int $current_page what is the current page being viewed. |
|
| 1895 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1896 | - * If FALSE then we return an array of event objects |
|
| 1897 | - * that match the given _view and paging parameters. |
|
| 1898 | - * @return array an array of event objects. |
|
| 1899 | - * @throws EE_Error |
|
| 1900 | - * @throws InvalidArgumentException |
|
| 1901 | - * @throws InvalidDataTypeException |
|
| 1902 | - * @throws InvalidInterfaceException |
|
| 1903 | - * @throws ReflectionException |
|
| 1904 | - * @throws Exception |
|
| 1905 | - * @throws Exception |
|
| 1906 | - * @throws Exception |
|
| 1907 | - */ |
|
| 1908 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1909 | - { |
|
| 1910 | - $EEME = $this->eventModel(); |
|
| 1911 | - $offset = ($current_page - 1) * $per_page; |
|
| 1912 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1913 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1914 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 1915 | - if (isset($this->_req_data['month_range'])) { |
|
| 1916 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1917 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1918 | - // where PHP doesn't know what to assume for date. |
|
| 1919 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1920 | - $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1921 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1922 | - } |
|
| 1923 | - $where = []; |
|
| 1924 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1925 | - // determine what post_status our condition will have for the query. |
|
| 1926 | - switch ($status) { |
|
| 1927 | - case 'month': |
|
| 1928 | - case 'today': |
|
| 1929 | - case null: |
|
| 1930 | - case 'all': |
|
| 1931 | - break; |
|
| 1932 | - case 'draft': |
|
| 1933 | - $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1934 | - break; |
|
| 1935 | - default: |
|
| 1936 | - $where['status'] = $status; |
|
| 1937 | - } |
|
| 1938 | - // categories? |
|
| 1939 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1940 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1941 | - if (! empty($category)) { |
|
| 1942 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1943 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1944 | - } |
|
| 1945 | - // date where conditions |
|
| 1946 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1947 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
|
| 1948 | - $DateTime = new DateTime( |
|
| 1949 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1950 | - new DateTimeZone('UTC') |
|
| 1951 | - ); |
|
| 1952 | - $start = $DateTime->getTimestamp(); |
|
| 1953 | - // set the datetime to be the end of the month |
|
| 1954 | - $DateTime->setDate( |
|
| 1955 | - $year_r, |
|
| 1956 | - $month_r, |
|
| 1957 | - $DateTime->format('t') |
|
| 1958 | - )->setTime(23, 59, 59); |
|
| 1959 | - $end = $DateTime->getTimestamp(); |
|
| 1960 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1961 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') { |
|
| 1962 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1963 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1964 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1965 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1966 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') { |
|
| 1967 | - $now = date('Y-m-01'); |
|
| 1968 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1969 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1970 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1971 | - ->setTime(23, 59, 59) |
|
| 1972 | - ->format(implode(' ', $start_formats)); |
|
| 1973 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1974 | - } |
|
| 1975 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1976 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1977 | - } elseif ( |
|
| 1978 | - ! isset($where['status']) |
|
| 1979 | - && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events') |
|
| 1980 | - ) { |
|
| 1981 | - $where['OR'] = [ |
|
| 1982 | - 'status*restrict_private' => ['!=', 'private'], |
|
| 1983 | - 'AND' => [ |
|
| 1984 | - 'status*inclusive' => ['=', 'private'], |
|
| 1985 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1986 | - ], |
|
| 1987 | - ]; |
|
| 1988 | - } |
|
| 1989 | - |
|
| 1990 | - if ( |
|
| 1991 | - isset($this->_req_data['EVT_wp_user']) |
|
| 1992 | - && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id() |
|
| 1993 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1994 | - ) { |
|
| 1995 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1996 | - } |
|
| 1997 | - // search query handling |
|
| 1998 | - if (isset($this->_req_data['s'])) { |
|
| 1999 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2000 | - $where['OR'] = [ |
|
| 2001 | - 'EVT_name' => ['LIKE', $search_string], |
|
| 2002 | - 'EVT_desc' => ['LIKE', $search_string], |
|
| 2003 | - 'EVT_short_desc' => ['LIKE', $search_string], |
|
| 2004 | - ]; |
|
| 2005 | - } |
|
| 2006 | - // filter events by venue. |
|
| 2007 | - if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
| 2008 | - $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
| 2009 | - } |
|
| 2010 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 2011 | - $query_params = apply_filters( |
|
| 2012 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 2013 | - [ |
|
| 2014 | - $where, |
|
| 2015 | - 'limit' => $limit, |
|
| 2016 | - 'order_by' => $orderby, |
|
| 2017 | - 'order' => $order, |
|
| 2018 | - 'group_by' => 'EVT_ID', |
|
| 2019 | - ], |
|
| 2020 | - $this->_req_data |
|
| 2021 | - ); |
|
| 2022 | - |
|
| 2023 | - // let's first check if we have special requests coming in. |
|
| 2024 | - if (isset($this->_req_data['active_status'])) { |
|
| 2025 | - switch ($this->_req_data['active_status']) { |
|
| 2026 | - case 'upcoming': |
|
| 2027 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 2028 | - break; |
|
| 2029 | - case 'expired': |
|
| 2030 | - return $EEME->get_expired_events($query_params, $count); |
|
| 2031 | - break; |
|
| 2032 | - case 'active': |
|
| 2033 | - return $EEME->get_active_events($query_params, $count); |
|
| 2034 | - break; |
|
| 2035 | - case 'inactive': |
|
| 2036 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 2037 | - break; |
|
| 2038 | - } |
|
| 2039 | - } |
|
| 2040 | - |
|
| 2041 | - $events = $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 2042 | - return $events; |
|
| 2043 | - } |
|
| 2044 | - |
|
| 2045 | - |
|
| 2046 | - /** |
|
| 2047 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 2048 | - * |
|
| 2049 | - * @param string $post_id |
|
| 2050 | - * @throws EE_Error |
|
| 2051 | - * @throws InvalidArgumentException |
|
| 2052 | - * @throws InvalidDataTypeException |
|
| 2053 | - * @throws InvalidInterfaceException |
|
| 2054 | - * @throws ReflectionException |
|
| 2055 | - */ |
|
| 2056 | - public function trash_cpt_item($post_id) |
|
| 2057 | - { |
|
| 2058 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 2059 | - $this->_trash_or_restore_event('trash', false); |
|
| 2060 | - } |
|
| 2061 | - |
|
| 2062 | - |
|
| 2063 | - /** |
|
| 2064 | - * @param string $post_id |
|
| 2065 | - * @throws EE_Error |
|
| 2066 | - * @throws InvalidArgumentException |
|
| 2067 | - * @throws InvalidDataTypeException |
|
| 2068 | - * @throws InvalidInterfaceException |
|
| 2069 | - * @throws ReflectionException |
|
| 2070 | - */ |
|
| 2071 | - public function restore_cpt_item($post_id) |
|
| 2072 | - { |
|
| 2073 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 2074 | - $this->_trash_or_restore_event('draft', false); |
|
| 2075 | - } |
|
| 2076 | - |
|
| 2077 | - |
|
| 2078 | - /** |
|
| 2079 | - * @param string $post_id |
|
| 2080 | - * @throws EE_Error |
|
| 2081 | - * @throws InvalidArgumentException |
|
| 2082 | - * @throws InvalidDataTypeException |
|
| 2083 | - * @throws InvalidInterfaceException |
|
| 2084 | - * @throws ReflectionException |
|
| 2085 | - */ |
|
| 2086 | - public function delete_cpt_item($post_id) |
|
| 2087 | - { |
|
| 2088 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 2089 | - $this->_delete_event(false); |
|
| 2090 | - } |
|
| 2091 | - |
|
| 2092 | - |
|
| 2093 | - /** |
|
| 2094 | - * _trash_or_restore_event |
|
| 2095 | - * |
|
| 2096 | - * @access protected |
|
| 2097 | - * @param string $event_status |
|
| 2098 | - * @param bool $redirect_after |
|
| 2099 | - * @throws EE_Error |
|
| 2100 | - * @throws InvalidArgumentException |
|
| 2101 | - * @throws InvalidDataTypeException |
|
| 2102 | - * @throws InvalidInterfaceException |
|
| 2103 | - * @throws ReflectionException |
|
| 2104 | - */ |
|
| 2105 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 2106 | - { |
|
| 2107 | - // determine the event id and set to array. |
|
| 2108 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 2109 | - // loop thru events |
|
| 2110 | - if ($EVT_ID) { |
|
| 2111 | - // clean status |
|
| 2112 | - $event_status = sanitize_key($event_status); |
|
| 2113 | - // grab status |
|
| 2114 | - if (! empty($event_status)) { |
|
| 2115 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2116 | - } else { |
|
| 2117 | - $success = false; |
|
| 2118 | - $msg = esc_html__( |
|
| 2119 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2120 | - 'event_espresso' |
|
| 2121 | - ); |
|
| 2122 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2123 | - } |
|
| 2124 | - } else { |
|
| 2125 | - $success = false; |
|
| 2126 | - $msg = esc_html__( |
|
| 2127 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2128 | - 'event_espresso' |
|
| 2129 | - ); |
|
| 2130 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2131 | - } |
|
| 2132 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2133 | - if ($redirect_after) { |
|
| 2134 | - $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2135 | - } |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - |
|
| 2139 | - /** |
|
| 2140 | - * _trash_or_restore_events |
|
| 2141 | - * |
|
| 2142 | - * @access protected |
|
| 2143 | - * @param string $event_status |
|
| 2144 | - * @return void |
|
| 2145 | - * @throws EE_Error |
|
| 2146 | - * @throws InvalidArgumentException |
|
| 2147 | - * @throws InvalidDataTypeException |
|
| 2148 | - * @throws InvalidInterfaceException |
|
| 2149 | - * @throws ReflectionException |
|
| 2150 | - */ |
|
| 2151 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2152 | - { |
|
| 2153 | - // clean status |
|
| 2154 | - $event_status = sanitize_key($event_status); |
|
| 2155 | - // grab status |
|
| 2156 | - if (! empty($event_status)) { |
|
| 2157 | - $success = true; |
|
| 2158 | - // determine the event id and set to array. |
|
| 2159 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []; |
|
| 2160 | - // loop thru events |
|
| 2161 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2162 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 2163 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2164 | - $success = $results !== false ? $success : false; |
|
| 2165 | - } else { |
|
| 2166 | - $msg = sprintf( |
|
| 2167 | - esc_html__( |
|
| 2168 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2169 | - 'event_espresso' |
|
| 2170 | - ), |
|
| 2171 | - $EVT_ID |
|
| 2172 | - ); |
|
| 2173 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2174 | - $success = false; |
|
| 2175 | - } |
|
| 2176 | - } |
|
| 2177 | - } else { |
|
| 2178 | - $success = false; |
|
| 2179 | - $msg = esc_html__( |
|
| 2180 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2181 | - 'event_espresso' |
|
| 2182 | - ); |
|
| 2183 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2184 | - } |
|
| 2185 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2186 | - $success = $success ? 2 : false; |
|
| 2187 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2188 | - $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2189 | - } |
|
| 2190 | - |
|
| 2191 | - |
|
| 2192 | - /** |
|
| 2193 | - * _trash_or_restore_events |
|
| 2194 | - * |
|
| 2195 | - * @access private |
|
| 2196 | - * @param int $EVT_ID |
|
| 2197 | - * @param string $event_status |
|
| 2198 | - * @return bool |
|
| 2199 | - * @throws EE_Error |
|
| 2200 | - * @throws InvalidArgumentException |
|
| 2201 | - * @throws InvalidDataTypeException |
|
| 2202 | - * @throws InvalidInterfaceException |
|
| 2203 | - * @throws ReflectionException |
|
| 2204 | - */ |
|
| 2205 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2206 | - { |
|
| 2207 | - // grab event id |
|
| 2208 | - if (! $EVT_ID) { |
|
| 2209 | - $msg = esc_html__( |
|
| 2210 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2211 | - 'event_espresso' |
|
| 2212 | - ); |
|
| 2213 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2214 | - return false; |
|
| 2215 | - } |
|
| 2216 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2217 | - // clean status |
|
| 2218 | - $event_status = sanitize_key($event_status); |
|
| 2219 | - // grab status |
|
| 2220 | - if (empty($event_status)) { |
|
| 2221 | - $msg = esc_html__( |
|
| 2222 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2223 | - 'event_espresso' |
|
| 2224 | - ); |
|
| 2225 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2226 | - return false; |
|
| 2227 | - } |
|
| 2228 | - // was event trashed or restored ? |
|
| 2229 | - switch ($event_status) { |
|
| 2230 | - case 'draft': |
|
| 2231 | - $action = 'restored from the trash'; |
|
| 2232 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2233 | - break; |
|
| 2234 | - case 'trash': |
|
| 2235 | - $action = 'moved to the trash'; |
|
| 2236 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2237 | - break; |
|
| 2238 | - default: |
|
| 2239 | - $action = 'updated'; |
|
| 2240 | - $hook = false; |
|
| 2241 | - } |
|
| 2242 | - // use class to change status |
|
| 2243 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2244 | - $success = $this->_cpt_model_obj->save(); |
|
| 2245 | - if ($success === false) { |
|
| 2246 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2247 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2248 | - return false; |
|
| 2249 | - } |
|
| 2250 | - if ($hook) { |
|
| 2251 | - do_action($hook); |
|
| 2252 | - } |
|
| 2253 | - return true; |
|
| 2254 | - } |
|
| 2255 | - |
|
| 2256 | - |
|
| 2257 | - /** |
|
| 2258 | - * _delete_event |
|
| 2259 | - * |
|
| 2260 | - * @access protected |
|
| 2261 | - * @param bool $redirect_after |
|
| 2262 | - * @throws EE_Error |
|
| 2263 | - * @throws InvalidArgumentException |
|
| 2264 | - * @throws InvalidDataTypeException |
|
| 2265 | - * @throws InvalidInterfaceException |
|
| 2266 | - * @throws ReflectionException |
|
| 2267 | - */ |
|
| 2268 | - protected function _delete_event($redirect_after = true) |
|
| 2269 | - { |
|
| 2270 | - // determine the event id and set to array. |
|
| 2271 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2272 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2273 | - // loop thru events |
|
| 2274 | - if ($EVT_ID) { |
|
| 2275 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2276 | - // get list of events with no prices |
|
| 2277 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
|
| 2278 | - // remove this event from the list of events with no prices |
|
| 2279 | - if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
| 2280 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2281 | - } |
|
| 2282 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2283 | - } else { |
|
| 2284 | - $success = false; |
|
| 2285 | - $msg = esc_html__( |
|
| 2286 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2287 | - 'event_espresso' |
|
| 2288 | - ); |
|
| 2289 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2290 | - } |
|
| 2291 | - if ($redirect_after) { |
|
| 2292 | - $this->_redirect_after_action( |
|
| 2293 | - $success, |
|
| 2294 | - 'Event', |
|
| 2295 | - 'deleted', |
|
| 2296 | - ['action' => 'default', 'status' => 'trash'] |
|
| 2297 | - ); |
|
| 2298 | - } |
|
| 2299 | - } |
|
| 2300 | - |
|
| 2301 | - |
|
| 2302 | - /** |
|
| 2303 | - * _delete_events |
|
| 2304 | - * |
|
| 2305 | - * @access protected |
|
| 2306 | - * @return void |
|
| 2307 | - * @throws EE_Error |
|
| 2308 | - * @throws InvalidArgumentException |
|
| 2309 | - * @throws InvalidDataTypeException |
|
| 2310 | - * @throws InvalidInterfaceException |
|
| 2311 | - * @throws ReflectionException |
|
| 2312 | - */ |
|
| 2313 | - protected function _delete_events() |
|
| 2314 | - { |
|
| 2315 | - $success = true; |
|
| 2316 | - // get list of events with no prices |
|
| 2317 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
|
| 2318 | - // determine the event id and set to array. |
|
| 2319 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []; |
|
| 2320 | - // loop thru events |
|
| 2321 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2322 | - $EVT_ID = absint($EVT_ID); |
|
| 2323 | - if ($EVT_ID) { |
|
| 2324 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2325 | - $success = $results !== false ? $success : false; |
|
| 2326 | - // remove this event from the list of events with no prices |
|
| 2327 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2328 | - } else { |
|
| 2329 | - $success = false; |
|
| 2330 | - $msg = esc_html__( |
|
| 2331 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2332 | - 'event_espresso' |
|
| 2333 | - ); |
|
| 2334 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2335 | - } |
|
| 2336 | - } |
|
| 2337 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2338 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2339 | - $success = $success ? 2 : false; |
|
| 2340 | - $this->_redirect_after_action($success, 'Events', 'deleted', ['action' => 'default']); |
|
| 2341 | - } |
|
| 2342 | - |
|
| 2343 | - |
|
| 2344 | - /** |
|
| 2345 | - * _permanently_delete_event |
|
| 2346 | - * |
|
| 2347 | - * @access private |
|
| 2348 | - * @param int $EVT_ID |
|
| 2349 | - * @return bool |
|
| 2350 | - * @throws EE_Error |
|
| 2351 | - * @throws InvalidArgumentException |
|
| 2352 | - * @throws InvalidDataTypeException |
|
| 2353 | - * @throws InvalidInterfaceException |
|
| 2354 | - * @throws ReflectionException |
|
| 2355 | - */ |
|
| 2356 | - private function _permanently_delete_event($EVT_ID = 0) |
|
| 2357 | - { |
|
| 2358 | - // grab event id |
|
| 2359 | - if (! $EVT_ID) { |
|
| 2360 | - $msg = esc_html__( |
|
| 2361 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2362 | - 'event_espresso' |
|
| 2363 | - ); |
|
| 2364 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2365 | - return false; |
|
| 2366 | - } |
|
| 2367 | - if ( |
|
| 2368 | - ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2369 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2370 | - ) { |
|
| 2371 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2372 | - } |
|
| 2373 | - if (! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2374 | - return false; |
|
| 2375 | - } |
|
| 2376 | - // need to delete related tickets and prices first. |
|
| 2377 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2378 | - foreach ($datetimes as $datetime) { |
|
| 2379 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2380 | - $tickets = $datetime->get_many_related('Ticket'); |
|
| 2381 | - foreach ($tickets as $ticket) { |
|
| 2382 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2383 | - $ticket->delete_related_permanently('Price'); |
|
| 2384 | - $ticket->delete_permanently(); |
|
| 2385 | - } |
|
| 2386 | - $datetime->delete(); |
|
| 2387 | - } |
|
| 2388 | - // what about related venues or terms? |
|
| 2389 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2390 | - foreach ($venues as $venue) { |
|
| 2391 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2392 | - } |
|
| 2393 | - // any attached question groups? |
|
| 2394 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2395 | - if (! empty($question_groups)) { |
|
| 2396 | - foreach ($question_groups as $question_group) { |
|
| 2397 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2398 | - } |
|
| 2399 | - } |
|
| 2400 | - // Message Template Groups |
|
| 2401 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2402 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2403 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2404 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2405 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2406 | - } |
|
| 2407 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2408 | - // did it all go as planned ? |
|
| 2409 | - if ($success) { |
|
| 2410 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2411 | - EE_Error::add_success($msg); |
|
| 2412 | - } else { |
|
| 2413 | - $msg = sprintf( |
|
| 2414 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2415 | - $EVT_ID |
|
| 2416 | - ); |
|
| 2417 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2418 | - return false; |
|
| 2419 | - } |
|
| 2420 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2421 | - return true; |
|
| 2422 | - } |
|
| 2423 | - |
|
| 2424 | - |
|
| 2425 | - /** |
|
| 2426 | - * get total number of events |
|
| 2427 | - * |
|
| 2428 | - * @access public |
|
| 2429 | - * @return int |
|
| 2430 | - * @throws EE_Error |
|
| 2431 | - * @throws InvalidArgumentException |
|
| 2432 | - * @throws InvalidDataTypeException |
|
| 2433 | - * @throws InvalidInterfaceException |
|
| 2434 | - */ |
|
| 2435 | - public function total_events() |
|
| 2436 | - { |
|
| 2437 | - $count = EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2438 | - return $count; |
|
| 2439 | - } |
|
| 2440 | - |
|
| 2441 | - |
|
| 2442 | - /** |
|
| 2443 | - * get total number of draft events |
|
| 2444 | - * |
|
| 2445 | - * @access public |
|
| 2446 | - * @return int |
|
| 2447 | - * @throws EE_Error |
|
| 2448 | - * @throws InvalidArgumentException |
|
| 2449 | - * @throws InvalidDataTypeException |
|
| 2450 | - * @throws InvalidInterfaceException |
|
| 2451 | - */ |
|
| 2452 | - public function total_events_draft() |
|
| 2453 | - { |
|
| 2454 | - $where = [ |
|
| 2455 | - 'status' => ['IN', ['draft', 'auto-draft']], |
|
| 2456 | - ]; |
|
| 2457 | - $count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2458 | - return $count; |
|
| 2459 | - } |
|
| 2460 | - |
|
| 2461 | - |
|
| 2462 | - /** |
|
| 2463 | - * get total number of trashed events |
|
| 2464 | - * |
|
| 2465 | - * @access public |
|
| 2466 | - * @return int |
|
| 2467 | - * @throws EE_Error |
|
| 2468 | - * @throws InvalidArgumentException |
|
| 2469 | - * @throws InvalidDataTypeException |
|
| 2470 | - * @throws InvalidInterfaceException |
|
| 2471 | - */ |
|
| 2472 | - public function total_trashed_events() |
|
| 2473 | - { |
|
| 2474 | - $where = [ |
|
| 2475 | - 'status' => 'trash', |
|
| 2476 | - ]; |
|
| 2477 | - $count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2478 | - return $count; |
|
| 2479 | - } |
|
| 2480 | - |
|
| 2481 | - |
|
| 2482 | - /** |
|
| 2483 | - * _default_event_settings |
|
| 2484 | - * This generates the Default Settings Tab |
|
| 2485 | - * |
|
| 2486 | - * @return void |
|
| 2487 | - * @throws DomainException |
|
| 2488 | - * @throws EE_Error |
|
| 2489 | - * @throws InvalidArgumentException |
|
| 2490 | - * @throws InvalidDataTypeException |
|
| 2491 | - * @throws InvalidInterfaceException |
|
| 2492 | - */ |
|
| 2493 | - protected function _default_event_settings() |
|
| 2494 | - { |
|
| 2495 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2496 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2497 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2498 | - $this->display_admin_page_with_sidebar(); |
|
| 2499 | - } |
|
| 2500 | - |
|
| 2501 | - |
|
| 2502 | - /** |
|
| 2503 | - * Return the form for event settings. |
|
| 2504 | - * |
|
| 2505 | - * @return EE_Form_Section_Proper |
|
| 2506 | - * @throws EE_Error |
|
| 2507 | - */ |
|
| 2508 | - protected function _default_event_settings_form() |
|
| 2509 | - { |
|
| 2510 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2511 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2512 | - // exclude |
|
| 2513 | - [ |
|
| 2514 | - EEM_Registration::status_id_cancelled, |
|
| 2515 | - EEM_Registration::status_id_declined, |
|
| 2516 | - EEM_Registration::status_id_incomplete, |
|
| 2517 | - EEM_Registration::status_id_wait_list, |
|
| 2518 | - ], |
|
| 2519 | - true |
|
| 2520 | - ); |
|
| 2521 | - return new EE_Form_Section_Proper( |
|
| 2522 | - [ |
|
| 2523 | - 'name' => 'update_default_event_settings', |
|
| 2524 | - 'html_id' => 'update_default_event_settings', |
|
| 2525 | - 'html_class' => 'form-table', |
|
| 2526 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2527 | - 'subsections' => apply_filters( |
|
| 2528 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2529 | - [ |
|
| 2530 | - 'default_reg_status' => new EE_Select_Input( |
|
| 2531 | - $registration_stati_for_selection, |
|
| 2532 | - [ |
|
| 2533 | - 'default' => isset($registration_config->default_STS_ID) |
|
| 2534 | - && array_key_exists( |
|
| 2535 | - $registration_config->default_STS_ID, |
|
| 2536 | - $registration_stati_for_selection |
|
| 2537 | - ) |
|
| 2538 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2539 | - : EEM_Registration::status_id_pending_payment, |
|
| 2540 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2541 | - . EEH_Template::get_help_tab_link( |
|
| 2542 | - 'default_settings_status_help_tab' |
|
| 2543 | - ), |
|
| 2544 | - 'html_help_text' => esc_html__( |
|
| 2545 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2546 | - 'event_espresso' |
|
| 2547 | - ), |
|
| 2548 | - ] |
|
| 2549 | - ), |
|
| 2550 | - 'default_max_tickets' => new EE_Integer_Input( |
|
| 2551 | - [ |
|
| 2552 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2553 | - ? $registration_config->default_maximum_number_of_tickets |
|
| 2554 | - : EEM_Event::get_default_additional_limit(), |
|
| 2555 | - 'html_label_text' => esc_html__( |
|
| 2556 | - 'Default Maximum Tickets Allowed Per Order:', |
|
| 2557 | - 'event_espresso' |
|
| 2558 | - ) |
|
| 2559 | - . EEH_Template::get_help_tab_link( |
|
| 2560 | - 'default_maximum_tickets_help_tab"' |
|
| 2561 | - ), |
|
| 2562 | - 'html_help_text' => esc_html__( |
|
| 2563 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2564 | - 'event_espresso' |
|
| 2565 | - ), |
|
| 2566 | - ] |
|
| 2567 | - ), |
|
| 2568 | - ] |
|
| 2569 | - ), |
|
| 2570 | - ] |
|
| 2571 | - ); |
|
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - |
|
| 2575 | - /** |
|
| 2576 | - * @return void |
|
| 2577 | - * @throws EE_Error |
|
| 2578 | - * @throws InvalidArgumentException |
|
| 2579 | - * @throws InvalidDataTypeException |
|
| 2580 | - * @throws InvalidInterfaceException |
|
| 2581 | - */ |
|
| 2582 | - protected function _update_default_event_settings() |
|
| 2583 | - { |
|
| 2584 | - $form = $this->_default_event_settings_form(); |
|
| 2585 | - if ($form->was_submitted()) { |
|
| 2586 | - $form->receive_form_submission(); |
|
| 2587 | - if ($form->is_valid()) { |
|
| 2588 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2589 | - $valid_data = $form->valid_data(); |
|
| 2590 | - if (isset($valid_data['default_reg_status'])) { |
|
| 2591 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2592 | - } |
|
| 2593 | - if (isset($valid_data['default_max_tickets'])) { |
|
| 2594 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2595 | - } |
|
| 2596 | - do_action( |
|
| 2597 | - 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
| 2598 | - $valid_data, |
|
| 2599 | - EE_Registry::instance()->CFG, |
|
| 2600 | - $this |
|
| 2601 | - ); |
|
| 2602 | - // update because data was valid! |
|
| 2603 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2604 | - EE_Error::overwrite_success(); |
|
| 2605 | - EE_Error::add_success( |
|
| 2606 | - __('Default Event Settings were updated', 'event_espresso') |
|
| 2607 | - ); |
|
| 2608 | - } |
|
| 2609 | - } |
|
| 2610 | - $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2611 | - } |
|
| 2612 | - |
|
| 2613 | - |
|
| 2614 | - /************* Templates *************/ |
|
| 2615 | - protected function _template_settings() |
|
| 2616 | - { |
|
| 2617 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2618 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2619 | - . EVENTS_ASSETS_URL |
|
| 2620 | - . '/images/' |
|
| 2621 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2622 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2623 | - . '" />'; |
|
| 2624 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 2625 | - . esc_html__( |
|
| 2626 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2627 | - 'event_espresso' |
|
| 2628 | - ) . '</strong>'; |
|
| 2629 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2630 | - } |
|
| 2631 | - |
|
| 2632 | - |
|
| 2633 | - /** Event Category Stuff **/ |
|
| 2634 | - /** |
|
| 2635 | - * set the _category property with the category object for the loaded page. |
|
| 2636 | - * |
|
| 2637 | - * @access private |
|
| 2638 | - * @return void |
|
| 2639 | - */ |
|
| 2640 | - private function _set_category_object() |
|
| 2641 | - { |
|
| 2642 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2643 | - return; |
|
| 2644 | - } //already have the category object so get out. |
|
| 2645 | - // set default category object |
|
| 2646 | - $this->_set_empty_category_object(); |
|
| 2647 | - // only set if we've got an id |
|
| 2648 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2649 | - return; |
|
| 2650 | - } |
|
| 2651 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2652 | - $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2653 | - if (! empty($term)) { |
|
| 2654 | - $this->_category->category_name = $term->name; |
|
| 2655 | - $this->_category->category_identifier = $term->slug; |
|
| 2656 | - $this->_category->category_desc = $term->description; |
|
| 2657 | - $this->_category->id = $term->term_id; |
|
| 2658 | - $this->_category->parent = $term->parent; |
|
| 2659 | - } |
|
| 2660 | - } |
|
| 2661 | - |
|
| 2662 | - |
|
| 2663 | - /** |
|
| 2664 | - * Clears out category properties. |
|
| 2665 | - */ |
|
| 2666 | - private function _set_empty_category_object() |
|
| 2667 | - { |
|
| 2668 | - $this->_category = new stdClass(); |
|
| 2669 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2670 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2671 | - } |
|
| 2672 | - |
|
| 2673 | - |
|
| 2674 | - /** |
|
| 2675 | - * @throws DomainException |
|
| 2676 | - * @throws EE_Error |
|
| 2677 | - * @throws InvalidArgumentException |
|
| 2678 | - * @throws InvalidDataTypeException |
|
| 2679 | - * @throws InvalidInterfaceException |
|
| 2680 | - */ |
|
| 2681 | - protected function _category_list_table() |
|
| 2682 | - { |
|
| 2683 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2684 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2685 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2686 | - 'add_category', |
|
| 2687 | - 'add_category', |
|
| 2688 | - [], |
|
| 2689 | - 'add-new-h2' |
|
| 2690 | - ); |
|
| 2691 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2692 | - } |
|
| 2693 | - |
|
| 2694 | - |
|
| 2695 | - /** |
|
| 2696 | - * Output category details view. |
|
| 2697 | - * |
|
| 2698 | - * @param string $view |
|
| 2699 | - * @throws DomainException |
|
| 2700 | - * @throws EE_Error |
|
| 2701 | - * @throws InvalidArgumentException |
|
| 2702 | - * @throws InvalidDataTypeException |
|
| 2703 | - * @throws InvalidInterfaceException |
|
| 2704 | - */ |
|
| 2705 | - protected function _category_details($view) |
|
| 2706 | - { |
|
| 2707 | - // load formatter helper |
|
| 2708 | - // load field generator helper |
|
| 2709 | - $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
| 2710 | - $this->_set_add_edit_form_tags($route); |
|
| 2711 | - $this->_set_category_object(); |
|
| 2712 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2713 | - $delete_action = 'delete_category'; |
|
| 2714 | - // custom redirect |
|
| 2715 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2716 | - ['action' => 'category_list'], |
|
| 2717 | - $this->_admin_base_url |
|
| 2718 | - ); |
|
| 2719 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2720 | - // take care of contents |
|
| 2721 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2722 | - $this->display_admin_page_with_sidebar(); |
|
| 2723 | - } |
|
| 2724 | - |
|
| 2725 | - |
|
| 2726 | - /** |
|
| 2727 | - * Output category details content. |
|
| 2728 | - * |
|
| 2729 | - * @throws DomainException |
|
| 2730 | - */ |
|
| 2731 | - protected function _category_details_content() |
|
| 2732 | - { |
|
| 2733 | - $editor_args['category_desc'] = [ |
|
| 2734 | - 'type' => 'wp_editor', |
|
| 2735 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2736 | - 'class' => 'my_editor_custom', |
|
| 2737 | - 'wpeditor_args' => ['media_buttons' => false], |
|
| 2738 | - ]; |
|
| 2739 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2740 | - $all_terms = get_terms( |
|
| 2741 | - [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2742 | - ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2743 | - ); |
|
| 2744 | - // setup category select for term parents. |
|
| 2745 | - $category_select_values[] = [ |
|
| 2746 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2747 | - 'id' => 0, |
|
| 2748 | - ]; |
|
| 2749 | - foreach ($all_terms as $term) { |
|
| 2750 | - $category_select_values[] = [ |
|
| 2751 | - 'text' => $term->name, |
|
| 2752 | - 'id' => $term->term_id, |
|
| 2753 | - ]; |
|
| 2754 | - } |
|
| 2755 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2756 | - 'category_parent', |
|
| 2757 | - $category_select_values, |
|
| 2758 | - $this->_category->parent |
|
| 2759 | - ); |
|
| 2760 | - $template_args = [ |
|
| 2761 | - 'category' => $this->_category, |
|
| 2762 | - 'category_select' => $category_select, |
|
| 2763 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2764 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2765 | - 'disable' => '', |
|
| 2766 | - 'disabled_message' => false, |
|
| 2767 | - ]; |
|
| 2768 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2769 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2770 | - } |
|
| 2771 | - |
|
| 2772 | - |
|
| 2773 | - /** |
|
| 2774 | - * Handles deleting categories. |
|
| 2775 | - */ |
|
| 2776 | - protected function _delete_categories() |
|
| 2777 | - { |
|
| 2778 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2779 | - : (array) $this->_req_data['category_id']; |
|
| 2780 | - foreach ($cat_ids as $cat_id) { |
|
| 2781 | - $this->_delete_category($cat_id); |
|
| 2782 | - } |
|
| 2783 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2784 | - $query_args = [ |
|
| 2785 | - 'action' => 'category_list', |
|
| 2786 | - ]; |
|
| 2787 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2788 | - } |
|
| 2789 | - |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * Handles deleting specific category. |
|
| 2793 | - * |
|
| 2794 | - * @param int $cat_id |
|
| 2795 | - */ |
|
| 2796 | - protected function _delete_category($cat_id) |
|
| 2797 | - { |
|
| 2798 | - $cat_id = absint($cat_id); |
|
| 2799 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2800 | - } |
|
| 2801 | - |
|
| 2802 | - |
|
| 2803 | - /** |
|
| 2804 | - * Handles triggering the update or insertion of a new category. |
|
| 2805 | - * |
|
| 2806 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2807 | - * @throws EE_Error |
|
| 2808 | - * @throws InvalidArgumentException |
|
| 2809 | - * @throws InvalidDataTypeException |
|
| 2810 | - * @throws InvalidInterfaceException |
|
| 2811 | - */ |
|
| 2812 | - protected function _insert_or_update_category($new_category) |
|
| 2813 | - { |
|
| 2814 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2815 | - $success = 0; // we already have a success message so lets not send another. |
|
| 2816 | - if ($cat_id) { |
|
| 2817 | - $query_args = [ |
|
| 2818 | - 'action' => 'edit_category', |
|
| 2819 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2820 | - ]; |
|
| 2821 | - } else { |
|
| 2822 | - $query_args = ['action' => 'add_category']; |
|
| 2823 | - } |
|
| 2824 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2825 | - } |
|
| 2826 | - |
|
| 2827 | - |
|
| 2828 | - /** |
|
| 2829 | - * Inserts or updates category |
|
| 2830 | - * |
|
| 2831 | - * @param bool $update (true indicates we're updating a category). |
|
| 2832 | - * @return bool|mixed|string |
|
| 2833 | - */ |
|
| 2834 | - private function _insert_category($update = false) |
|
| 2835 | - { |
|
| 2836 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2837 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2838 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2839 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2840 | - if (empty($category_name)) { |
|
| 2841 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2842 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2843 | - return false; |
|
| 2844 | - } |
|
| 2845 | - $term_args = [ |
|
| 2846 | - 'name' => $category_name, |
|
| 2847 | - 'description' => $category_desc, |
|
| 2848 | - 'parent' => $category_parent, |
|
| 2849 | - ]; |
|
| 2850 | - // was the category_identifier input disabled? |
|
| 2851 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2852 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2853 | - } |
|
| 2854 | - $insert_ids = $update |
|
| 2855 | - ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2856 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2857 | - if (! is_array($insert_ids)) { |
|
| 2858 | - $msg = esc_html__( |
|
| 2859 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2860 | - 'event_espresso' |
|
| 2861 | - ); |
|
| 2862 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2863 | - } else { |
|
| 2864 | - $cat_id = $insert_ids['term_id']; |
|
| 2865 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2866 | - EE_Error::add_success($msg); |
|
| 2867 | - } |
|
| 2868 | - return $cat_id; |
|
| 2869 | - } |
|
| 2870 | - |
|
| 2871 | - |
|
| 2872 | - /** |
|
| 2873 | - * Gets categories or count of categories matching the arguments in the request. |
|
| 2874 | - * |
|
| 2875 | - * @param int $per_page |
|
| 2876 | - * @param int $current_page |
|
| 2877 | - * @param bool $count |
|
| 2878 | - * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
| 2879 | - * @throws EE_Error |
|
| 2880 | - * @throws InvalidArgumentException |
|
| 2881 | - * @throws InvalidDataTypeException |
|
| 2882 | - * @throws InvalidInterfaceException |
|
| 2883 | - */ |
|
| 2884 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2885 | - { |
|
| 2886 | - // testing term stuff |
|
| 2887 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2888 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2889 | - $limit = ($current_page - 1) * $per_page; |
|
| 2890 | - $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2891 | - if (isset($this->_req_data['s'])) { |
|
| 2892 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2893 | - $where['OR'] = [ |
|
| 2894 | - 'Term.name' => ['LIKE', $sstr], |
|
| 2895 | - 'description' => ['LIKE', $sstr], |
|
| 2896 | - ]; |
|
| 2897 | - } |
|
| 2898 | - $query_params = [ |
|
| 2899 | - $where, |
|
| 2900 | - 'order_by' => [$orderby => $order], |
|
| 2901 | - 'limit' => $limit . ',' . $per_page, |
|
| 2902 | - 'force_join' => ['Term'], |
|
| 2903 | - ]; |
|
| 2904 | - $categories = $count |
|
| 2905 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2906 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2907 | - return $categories; |
|
| 2908 | - } |
|
| 2909 | - |
|
| 2910 | - /* end category stuff */ |
|
| 2911 | - /**************/ |
|
| 2912 | - |
|
| 2913 | - |
|
| 2914 | - /** |
|
| 2915 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2916 | - * |
|
| 2917 | - * @throws EE_Error |
|
| 2918 | - * @throws InvalidArgumentException |
|
| 2919 | - * @throws InvalidDataTypeException |
|
| 2920 | - * @throws InvalidInterfaceException |
|
| 2921 | - */ |
|
| 2922 | - public function save_timezonestring_setting() |
|
| 2923 | - { |
|
| 2924 | - $timezone_string = isset($this->_req_data['timezone_selected']) |
|
| 2925 | - ? $this->_req_data['timezone_selected'] |
|
| 2926 | - : ''; |
|
| 2927 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2928 | - EE_Error::add_error( |
|
| 2929 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2930 | - __FILE__, |
|
| 2931 | - __FUNCTION__, |
|
| 2932 | - __LINE__ |
|
| 2933 | - ); |
|
| 2934 | - $this->_template_args['error'] = true; |
|
| 2935 | - $this->_return_json(); |
|
| 2936 | - } |
|
| 2937 | - |
|
| 2938 | - update_option('timezone_string', $timezone_string); |
|
| 2939 | - EE_Error::add_success( |
|
| 2940 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2941 | - ); |
|
| 2942 | - $this->_template_args['success'] = true; |
|
| 2943 | - $this->_return_json(true, ['action' => 'create_new']); |
|
| 2944 | - } |
|
| 19 | + /** |
|
| 20 | + * This will hold the event object for event_details screen. |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @var EE_Event $_event |
|
| 24 | + */ |
|
| 25 | + protected $_event; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * This will hold the category object for category_details screen. |
|
| 30 | + * |
|
| 31 | + * @var stdClass $_category |
|
| 32 | + */ |
|
| 33 | + protected $_category; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var EEM_Event $_event_model |
|
| 38 | + */ |
|
| 39 | + protected $_event_model; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var EEM_Datetime $datetime_model |
|
| 43 | + */ |
|
| 44 | + protected $datetime_model; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EEM_Ticket $ticket_model |
|
| 48 | + */ |
|
| 49 | + protected $ticket_model; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var EE_Event |
|
| 54 | + */ |
|
| 55 | + protected $_cpt_model_obj; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Initialize page props for this admin page group. |
|
| 60 | + */ |
|
| 61 | + protected function _init_page_props() |
|
| 62 | + { |
|
| 63 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 64 | + $this->page_label = EVENTS_LABEL; |
|
| 65 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 66 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 67 | + $this->_cpt_model_names = [ |
|
| 68 | + 'create_new' => 'EEM_Event', |
|
| 69 | + 'edit' => 'EEM_Event', |
|
| 70 | + ]; |
|
| 71 | + $this->_cpt_edit_routes = [ |
|
| 72 | + 'espresso_events' => 'edit', |
|
| 73 | + ]; |
|
| 74 | + add_action( |
|
| 75 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 76 | + [$this, 'verify_event_edit'], |
|
| 77 | + 10, |
|
| 78 | + 2 |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Sets the ajax hooks used for this admin page group. |
|
| 85 | + */ |
|
| 86 | + protected function _ajax_hooks() |
|
| 87 | + { |
|
| 88 | + add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Sets the page properties for this admin page group. |
|
| 94 | + */ |
|
| 95 | + protected function _define_page_props() |
|
| 96 | + { |
|
| 97 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 98 | + $this->_labels = [ |
|
| 99 | + 'buttons' => [ |
|
| 100 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 101 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 102 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 103 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 104 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 105 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 106 | + ], |
|
| 107 | + 'editor_title' => [ |
|
| 108 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 109 | + ], |
|
| 110 | + 'publishbox' => [ |
|
| 111 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 112 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 113 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 114 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 115 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 116 | + ], |
|
| 117 | + ]; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Sets the page routes property for this admin page group. |
|
| 123 | + */ |
|
| 124 | + protected function _set_page_routes() |
|
| 125 | + { |
|
| 126 | + // load formatter helper |
|
| 127 | + // load field generator helper |
|
| 128 | + // is there a evt_id in the request? |
|
| 129 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 130 | + ? $this->_req_data['EVT_ID'] |
|
| 131 | + : 0; |
|
| 132 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 133 | + $this->_page_routes = [ |
|
| 134 | + 'default' => [ |
|
| 135 | + 'func' => '_events_overview_list_table', |
|
| 136 | + 'capability' => 'ee_read_events', |
|
| 137 | + ], |
|
| 138 | + 'create_new' => [ |
|
| 139 | + 'func' => '_create_new_cpt_item', |
|
| 140 | + 'capability' => 'ee_edit_events', |
|
| 141 | + ], |
|
| 142 | + 'edit' => [ |
|
| 143 | + 'func' => '_edit_cpt_item', |
|
| 144 | + 'capability' => 'ee_edit_event', |
|
| 145 | + 'obj_id' => $evt_id, |
|
| 146 | + ], |
|
| 147 | + 'copy_event' => [ |
|
| 148 | + 'func' => '_copy_events', |
|
| 149 | + 'capability' => 'ee_edit_event', |
|
| 150 | + 'obj_id' => $evt_id, |
|
| 151 | + 'noheader' => true, |
|
| 152 | + ], |
|
| 153 | + 'trash_event' => [ |
|
| 154 | + 'func' => '_trash_or_restore_event', |
|
| 155 | + 'args' => ['event_status' => 'trash'], |
|
| 156 | + 'capability' => 'ee_delete_event', |
|
| 157 | + 'obj_id' => $evt_id, |
|
| 158 | + 'noheader' => true, |
|
| 159 | + ], |
|
| 160 | + 'trash_events' => [ |
|
| 161 | + 'func' => '_trash_or_restore_events', |
|
| 162 | + 'args' => ['event_status' => 'trash'], |
|
| 163 | + 'capability' => 'ee_delete_events', |
|
| 164 | + 'noheader' => true, |
|
| 165 | + ], |
|
| 166 | + 'restore_event' => [ |
|
| 167 | + 'func' => '_trash_or_restore_event', |
|
| 168 | + 'args' => ['event_status' => 'draft'], |
|
| 169 | + 'capability' => 'ee_delete_event', |
|
| 170 | + 'obj_id' => $evt_id, |
|
| 171 | + 'noheader' => true, |
|
| 172 | + ], |
|
| 173 | + 'restore_events' => [ |
|
| 174 | + 'func' => '_trash_or_restore_events', |
|
| 175 | + 'args' => ['event_status' => 'draft'], |
|
| 176 | + 'capability' => 'ee_delete_events', |
|
| 177 | + 'noheader' => true, |
|
| 178 | + ], |
|
| 179 | + 'delete_event' => [ |
|
| 180 | + 'func' => '_delete_event', |
|
| 181 | + 'capability' => 'ee_delete_event', |
|
| 182 | + 'obj_id' => $evt_id, |
|
| 183 | + 'noheader' => true, |
|
| 184 | + ], |
|
| 185 | + 'delete_events' => [ |
|
| 186 | + 'func' => '_delete_events', |
|
| 187 | + 'capability' => 'ee_delete_events', |
|
| 188 | + 'noheader' => true, |
|
| 189 | + ], |
|
| 190 | + 'view_report' => [ |
|
| 191 | + 'func' => '_view_report', |
|
| 192 | + 'capability' => 'ee_edit_events', |
|
| 193 | + ], |
|
| 194 | + 'default_event_settings' => [ |
|
| 195 | + 'func' => '_default_event_settings', |
|
| 196 | + 'capability' => 'manage_options', |
|
| 197 | + ], |
|
| 198 | + 'update_default_event_settings' => [ |
|
| 199 | + 'func' => '_update_default_event_settings', |
|
| 200 | + 'capability' => 'manage_options', |
|
| 201 | + 'noheader' => true, |
|
| 202 | + ], |
|
| 203 | + 'template_settings' => [ |
|
| 204 | + 'func' => '_template_settings', |
|
| 205 | + 'capability' => 'manage_options', |
|
| 206 | + ], |
|
| 207 | + // event category tab related |
|
| 208 | + 'add_category' => [ |
|
| 209 | + 'func' => '_category_details', |
|
| 210 | + 'capability' => 'ee_edit_event_category', |
|
| 211 | + 'args' => ['add'], |
|
| 212 | + ], |
|
| 213 | + 'edit_category' => [ |
|
| 214 | + 'func' => '_category_details', |
|
| 215 | + 'capability' => 'ee_edit_event_category', |
|
| 216 | + 'args' => ['edit'], |
|
| 217 | + ], |
|
| 218 | + 'delete_categories' => [ |
|
| 219 | + 'func' => '_delete_categories', |
|
| 220 | + 'capability' => 'ee_delete_event_category', |
|
| 221 | + 'noheader' => true, |
|
| 222 | + ], |
|
| 223 | + 'delete_category' => [ |
|
| 224 | + 'func' => '_delete_categories', |
|
| 225 | + 'capability' => 'ee_delete_event_category', |
|
| 226 | + 'noheader' => true, |
|
| 227 | + ], |
|
| 228 | + 'insert_category' => [ |
|
| 229 | + 'func' => '_insert_or_update_category', |
|
| 230 | + 'args' => ['new_category' => true], |
|
| 231 | + 'capability' => 'ee_edit_event_category', |
|
| 232 | + 'noheader' => true, |
|
| 233 | + ], |
|
| 234 | + 'update_category' => [ |
|
| 235 | + 'func' => '_insert_or_update_category', |
|
| 236 | + 'args' => ['new_category' => false], |
|
| 237 | + 'capability' => 'ee_edit_event_category', |
|
| 238 | + 'noheader' => true, |
|
| 239 | + ], |
|
| 240 | + 'category_list' => [ |
|
| 241 | + 'func' => '_category_list_table', |
|
| 242 | + 'capability' => 'ee_manage_event_categories', |
|
| 243 | + ], |
|
| 244 | + ]; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Set the _page_config property for this admin page group. |
|
| 250 | + */ |
|
| 251 | + protected function _set_page_config() |
|
| 252 | + { |
|
| 253 | + $this->_page_config = [ |
|
| 254 | + 'default' => [ |
|
| 255 | + 'nav' => [ |
|
| 256 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 257 | + 'order' => 10, |
|
| 258 | + ], |
|
| 259 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 260 | + 'help_tabs' => [ |
|
| 261 | + 'events_overview_help_tab' => [ |
|
| 262 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 263 | + 'filename' => 'events_overview', |
|
| 264 | + ], |
|
| 265 | + 'events_overview_table_column_headings_help_tab' => [ |
|
| 266 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 267 | + 'filename' => 'events_overview_table_column_headings', |
|
| 268 | + ], |
|
| 269 | + 'events_overview_filters_help_tab' => [ |
|
| 270 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 271 | + 'filename' => 'events_overview_filters', |
|
| 272 | + ], |
|
| 273 | + 'events_overview_view_help_tab' => [ |
|
| 274 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 275 | + 'filename' => 'events_overview_views', |
|
| 276 | + ], |
|
| 277 | + 'events_overview_other_help_tab' => [ |
|
| 278 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 279 | + 'filename' => 'events_overview_other', |
|
| 280 | + ], |
|
| 281 | + ], |
|
| 282 | + 'help_tour' => [ |
|
| 283 | + 'Event_Overview_Help_Tour', |
|
| 284 | + // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 285 | + ], |
|
| 286 | + 'require_nonce' => false, |
|
| 287 | + 'qtips' => ['EE_Event_List_Table_Tips'], |
|
| 288 | + ], |
|
| 289 | + 'create_new' => [ |
|
| 290 | + 'nav' => [ |
|
| 291 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 292 | + 'order' => 5, |
|
| 293 | + 'persistent' => false, |
|
| 294 | + ], |
|
| 295 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 296 | + 'help_tabs' => [ |
|
| 297 | + 'event_editor_help_tab' => [ |
|
| 298 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 299 | + 'filename' => 'event_editor', |
|
| 300 | + ], |
|
| 301 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 302 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 303 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 304 | + ], |
|
| 305 | + 'event_editor_venue_details_help_tab' => [ |
|
| 306 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 307 | + 'filename' => 'event_editor_venue_details', |
|
| 308 | + ], |
|
| 309 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 310 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 311 | + 'filename' => 'event_editor_event_datetimes', |
|
| 312 | + ], |
|
| 313 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 314 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 315 | + 'filename' => 'event_editor_event_tickets', |
|
| 316 | + ], |
|
| 317 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 318 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 319 | + 'filename' => 'event_editor_event_registration_options', |
|
| 320 | + ], |
|
| 321 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 322 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 323 | + 'filename' => 'event_editor_tags_categories', |
|
| 324 | + ], |
|
| 325 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 326 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 327 | + 'filename' => 'event_editor_questions_registrants', |
|
| 328 | + ], |
|
| 329 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 330 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 331 | + 'filename' => 'event_editor_save_new_event', |
|
| 332 | + ], |
|
| 333 | + 'event_editor_other_help_tab' => [ |
|
| 334 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 335 | + 'filename' => 'event_editor_other', |
|
| 336 | + ], |
|
| 337 | + ], |
|
| 338 | + 'help_tour' => [ |
|
| 339 | + 'Event_Editor_Help_Tour', |
|
| 340 | + ], |
|
| 341 | + 'require_nonce' => false, |
|
| 342 | + ], |
|
| 343 | + 'edit' => [ |
|
| 344 | + 'nav' => [ |
|
| 345 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 346 | + 'order' => 5, |
|
| 347 | + 'persistent' => false, |
|
| 348 | + 'url' => isset($this->_req_data['post']) |
|
| 349 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 350 | + ['post' => $this->_req_data['post'], 'action' => 'edit'], |
|
| 351 | + $this->_current_page_view_url |
|
| 352 | + ) |
|
| 353 | + : $this->_admin_base_url, |
|
| 354 | + ], |
|
| 355 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 356 | + 'help_tabs' => [ |
|
| 357 | + 'event_editor_help_tab' => [ |
|
| 358 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 359 | + 'filename' => 'event_editor', |
|
| 360 | + ], |
|
| 361 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 362 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 363 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 364 | + ], |
|
| 365 | + 'event_editor_venue_details_help_tab' => [ |
|
| 366 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 367 | + 'filename' => 'event_editor_venue_details', |
|
| 368 | + ], |
|
| 369 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 370 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 371 | + 'filename' => 'event_editor_event_datetimes', |
|
| 372 | + ], |
|
| 373 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 374 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 375 | + 'filename' => 'event_editor_event_tickets', |
|
| 376 | + ], |
|
| 377 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 378 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 379 | + 'filename' => 'event_editor_event_registration_options', |
|
| 380 | + ], |
|
| 381 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 382 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 383 | + 'filename' => 'event_editor_tags_categories', |
|
| 384 | + ], |
|
| 385 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 386 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 387 | + 'filename' => 'event_editor_questions_registrants', |
|
| 388 | + ], |
|
| 389 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 390 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 391 | + 'filename' => 'event_editor_save_new_event', |
|
| 392 | + ], |
|
| 393 | + 'event_editor_other_help_tab' => [ |
|
| 394 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 395 | + 'filename' => 'event_editor_other', |
|
| 396 | + ], |
|
| 397 | + ], |
|
| 398 | + 'require_nonce' => false, |
|
| 399 | + ], |
|
| 400 | + 'default_event_settings' => [ |
|
| 401 | + 'nav' => [ |
|
| 402 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 403 | + 'order' => 40, |
|
| 404 | + ], |
|
| 405 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 406 | + 'labels' => [ |
|
| 407 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 408 | + ], |
|
| 409 | + 'help_tabs' => [ |
|
| 410 | + 'default_settings_help_tab' => [ |
|
| 411 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 412 | + 'filename' => 'events_default_settings', |
|
| 413 | + ], |
|
| 414 | + 'default_settings_status_help_tab' => [ |
|
| 415 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 416 | + 'filename' => 'events_default_settings_status', |
|
| 417 | + ], |
|
| 418 | + 'default_maximum_tickets_help_tab' => [ |
|
| 419 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 420 | + 'filename' => 'events_default_settings_max_tickets', |
|
| 421 | + ], |
|
| 422 | + ], |
|
| 423 | + 'help_tour' => ['Event_Default_Settings_Help_Tour'], |
|
| 424 | + 'require_nonce' => false, |
|
| 425 | + ], |
|
| 426 | + // template settings |
|
| 427 | + 'template_settings' => [ |
|
| 428 | + 'nav' => [ |
|
| 429 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 430 | + 'order' => 30, |
|
| 431 | + ], |
|
| 432 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 433 | + 'help_tabs' => [ |
|
| 434 | + 'general_settings_templates_help_tab' => [ |
|
| 435 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 436 | + 'filename' => 'general_settings_templates', |
|
| 437 | + ], |
|
| 438 | + ], |
|
| 439 | + 'help_tour' => ['Templates_Help_Tour'], |
|
| 440 | + 'require_nonce' => false, |
|
| 441 | + ], |
|
| 442 | + // event category stuff |
|
| 443 | + 'add_category' => [ |
|
| 444 | + 'nav' => [ |
|
| 445 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 446 | + 'order' => 15, |
|
| 447 | + 'persistent' => false, |
|
| 448 | + ], |
|
| 449 | + 'help_tabs' => [ |
|
| 450 | + 'add_category_help_tab' => [ |
|
| 451 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 452 | + 'filename' => 'events_add_category', |
|
| 453 | + ], |
|
| 454 | + ], |
|
| 455 | + 'help_tour' => ['Event_Add_Category_Help_Tour'], |
|
| 456 | + 'metaboxes' => ['_publish_post_box'], |
|
| 457 | + 'require_nonce' => false, |
|
| 458 | + ], |
|
| 459 | + 'edit_category' => [ |
|
| 460 | + 'nav' => [ |
|
| 461 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 462 | + 'order' => 15, |
|
| 463 | + 'persistent' => false, |
|
| 464 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 465 | + ? add_query_arg( |
|
| 466 | + ['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']], |
|
| 467 | + $this->_current_page_view_url |
|
| 468 | + ) |
|
| 469 | + : $this->_admin_base_url, |
|
| 470 | + ], |
|
| 471 | + 'help_tabs' => [ |
|
| 472 | + 'edit_category_help_tab' => [ |
|
| 473 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 474 | + 'filename' => 'events_edit_category', |
|
| 475 | + ], |
|
| 476 | + ], |
|
| 477 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 478 | + 'metaboxes' => ['_publish_post_box'], |
|
| 479 | + 'require_nonce' => false, |
|
| 480 | + ], |
|
| 481 | + 'category_list' => [ |
|
| 482 | + 'nav' => [ |
|
| 483 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 484 | + 'order' => 20, |
|
| 485 | + ], |
|
| 486 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 487 | + 'help_tabs' => [ |
|
| 488 | + 'events_categories_help_tab' => [ |
|
| 489 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 490 | + 'filename' => 'events_categories', |
|
| 491 | + ], |
|
| 492 | + 'events_categories_table_column_headings_help_tab' => [ |
|
| 493 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 494 | + 'filename' => 'events_categories_table_column_headings', |
|
| 495 | + ], |
|
| 496 | + 'events_categories_view_help_tab' => [ |
|
| 497 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 498 | + 'filename' => 'events_categories_views', |
|
| 499 | + ], |
|
| 500 | + 'events_categories_other_help_tab' => [ |
|
| 501 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 502 | + 'filename' => 'events_categories_other', |
|
| 503 | + ], |
|
| 504 | + ], |
|
| 505 | + 'help_tour' => [ |
|
| 506 | + 'Event_Categories_Help_Tour', |
|
| 507 | + ], |
|
| 508 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 509 | + 'require_nonce' => false, |
|
| 510 | + ], |
|
| 511 | + ]; |
|
| 512 | + // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated |
|
| 513 | + $domain = $this->loader->getShared('EventEspresso\core\domain\Domain'); |
|
| 514 | + if (! $domain->isCaffeinated()) { |
|
| 515 | + $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
|
| 516 | + $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 523 | + */ |
|
| 524 | + protected function _add_screen_options() |
|
| 525 | + { |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Implementing the screen options for the 'default' route. |
|
| 531 | + * |
|
| 532 | + * @throws InvalidArgumentException |
|
| 533 | + * @throws InvalidDataTypeException |
|
| 534 | + * @throws InvalidInterfaceException |
|
| 535 | + */ |
|
| 536 | + protected function _add_screen_options_default() |
|
| 537 | + { |
|
| 538 | + $this->_per_page_screen_option(); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Implementing screen options for the category list route. |
|
| 544 | + * |
|
| 545 | + * @throws InvalidArgumentException |
|
| 546 | + * @throws InvalidDataTypeException |
|
| 547 | + * @throws InvalidInterfaceException |
|
| 548 | + */ |
|
| 549 | + protected function _add_screen_options_category_list() |
|
| 550 | + { |
|
| 551 | + $page_title = $this->_admin_page_title; |
|
| 552 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 553 | + $this->_per_page_screen_option(); |
|
| 554 | + $this->_admin_page_title = $page_title; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Used to register any global feature pointers for the admin page group. |
|
| 560 | + */ |
|
| 561 | + protected function _add_feature_pointers() |
|
| 562 | + { |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 568 | + */ |
|
| 569 | + public function load_scripts_styles() |
|
| 570 | + { |
|
| 571 | + wp_register_style( |
|
| 572 | + 'events-admin-css', |
|
| 573 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 574 | + [], |
|
| 575 | + EVENT_ESPRESSO_VERSION |
|
| 576 | + ); |
|
| 577 | + wp_register_style( |
|
| 578 | + 'ee-cat-admin', |
|
| 579 | + EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 580 | + [], |
|
| 581 | + EVENT_ESPRESSO_VERSION |
|
| 582 | + ); |
|
| 583 | + wp_enqueue_style('events-admin-css'); |
|
| 584 | + wp_enqueue_style('ee-cat-admin'); |
|
| 585 | + // scripts |
|
| 586 | + wp_register_script( |
|
| 587 | + 'event_editor_js', |
|
| 588 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 589 | + ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 590 | + EVENT_ESPRESSO_VERSION, |
|
| 591 | + true |
|
| 592 | + ); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Enqueuing scripts and styles specific to this view |
|
| 598 | + */ |
|
| 599 | + public function load_scripts_styles_create_new() |
|
| 600 | + { |
|
| 601 | + $this->load_scripts_styles_edit(); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * Enqueuing scripts and styles specific to this view |
|
| 607 | + */ |
|
| 608 | + public function load_scripts_styles_edit() |
|
| 609 | + { |
|
| 610 | + // styles |
|
| 611 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 612 | + wp_register_style( |
|
| 613 | + 'event-editor-css', |
|
| 614 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 615 | + ['ee-admin-css'], |
|
| 616 | + EVENT_ESPRESSO_VERSION |
|
| 617 | + ); |
|
| 618 | + wp_enqueue_style('event-editor-css'); |
|
| 619 | + // scripts |
|
| 620 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
| 621 | + wp_register_script( |
|
| 622 | + 'event-datetime-metabox', |
|
| 623 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 624 | + ['event_editor_js', 'ee-datepicker'], |
|
| 625 | + EVENT_ESPRESSO_VERSION |
|
| 626 | + ); |
|
| 627 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Populating the _views property for the category list table view. |
|
| 634 | + */ |
|
| 635 | + protected function _set_list_table_views_category_list() |
|
| 636 | + { |
|
| 637 | + $this->_views = [ |
|
| 638 | + 'all' => [ |
|
| 639 | + 'slug' => 'all', |
|
| 640 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 641 | + 'count' => 0, |
|
| 642 | + 'bulk_action' => [ |
|
| 643 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 644 | + ], |
|
| 645 | + ], |
|
| 646 | + ]; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 652 | + */ |
|
| 653 | + public function admin_init() |
|
| 654 | + { |
|
| 655 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 656 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 657 | + 'event_espresso' |
|
| 658 | + ); |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 664 | + * group. |
|
| 665 | + */ |
|
| 666 | + public function admin_notices() |
|
| 667 | + { |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 673 | + * this admin page group. |
|
| 674 | + */ |
|
| 675 | + public function admin_footer_scripts() |
|
| 676 | + { |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 682 | + * warning (via EE_Error::add_error()); |
|
| 683 | + * |
|
| 684 | + * @param EE_Event $event Event object |
|
| 685 | + * @param string $req_type |
|
| 686 | + * @return void |
|
| 687 | + * @throws EE_Error |
|
| 688 | + * @access public |
|
| 689 | + */ |
|
| 690 | + public function verify_event_edit($event = null, $req_type = '') |
|
| 691 | + { |
|
| 692 | + // don't need to do this when processing |
|
| 693 | + if (! empty($req_type)) { |
|
| 694 | + return; |
|
| 695 | + } |
|
| 696 | + // no event? |
|
| 697 | + if (! $event instanceof EE_Event) { |
|
| 698 | + $event = $this->_cpt_model_obj; |
|
| 699 | + } |
|
| 700 | + // STILL no event? |
|
| 701 | + if (! $event instanceof EE_Event) { |
|
| 702 | + return; |
|
| 703 | + } |
|
| 704 | + $orig_status = $event->status(); |
|
| 705 | + // first check if event is active. |
|
| 706 | + if ( |
|
| 707 | + $orig_status === EEM_Event::cancelled |
|
| 708 | + || $orig_status === EEM_Event::postponed |
|
| 709 | + || $event->is_expired() |
|
| 710 | + || $event->is_inactive() |
|
| 711 | + ) { |
|
| 712 | + return; |
|
| 713 | + } |
|
| 714 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
| 715 | + if ($event->is_sold_out(true)) { |
|
| 716 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 717 | + EE_Error::add_attention( |
|
| 718 | + sprintf( |
|
| 719 | + esc_html__( |
|
| 720 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 721 | + 'event_espresso' |
|
| 722 | + ), |
|
| 723 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 724 | + ) |
|
| 725 | + ); |
|
| 726 | + } |
|
| 727 | + return; |
|
| 728 | + } |
|
| 729 | + if ($orig_status === EEM_Event::sold_out) { |
|
| 730 | + EE_Error::add_attention( |
|
| 731 | + sprintf( |
|
| 732 | + esc_html__( |
|
| 733 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 734 | + 'event_espresso' |
|
| 735 | + ), |
|
| 736 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 737 | + ) |
|
| 738 | + ); |
|
| 739 | + } |
|
| 740 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 741 | + if (! $event->tickets_on_sale()) { |
|
| 742 | + return; |
|
| 743 | + } |
|
| 744 | + // made it here so show warning |
|
| 745 | + $this->_edit_event_warning(); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 751 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 752 | + * |
|
| 753 | + * @access protected |
|
| 754 | + * @return void |
|
| 755 | + */ |
|
| 756 | + protected function _edit_event_warning() |
|
| 757 | + { |
|
| 758 | + // we don't want to add warnings during these requests |
|
| 759 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 760 | + return; |
|
| 761 | + } |
|
| 762 | + EE_Error::add_attention( |
|
| 763 | + sprintf( |
|
| 764 | + esc_html__( |
|
| 765 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 766 | + 'event_espresso' |
|
| 767 | + ), |
|
| 768 | + '<a class="espresso-help-tab-lnk">', |
|
| 769 | + '</a>' |
|
| 770 | + ) |
|
| 771 | + ); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 777 | + * Otherwise, do the normal logic |
|
| 778 | + * |
|
| 779 | + * @throws EE_Error |
|
| 780 | + * @throws InvalidArgumentException |
|
| 781 | + * @throws InvalidDataTypeException |
|
| 782 | + */ |
|
| 783 | + protected function _create_new_cpt_item() |
|
| 784 | + { |
|
| 785 | + $has_timezone_string = get_option('timezone_string'); |
|
| 786 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 787 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 788 | + EE_Error::add_attention( |
|
| 789 | + sprintf( |
|
| 790 | + __( |
|
| 791 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
| 792 | + 'event_espresso' |
|
| 793 | + ), |
|
| 794 | + '<br>', |
|
| 795 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 796 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 797 | + . '</select>', |
|
| 798 | + '<button class="button button-secondary timezone-submit">', |
|
| 799 | + '</button><span class="spinner"></span>' |
|
| 800 | + ), |
|
| 801 | + __FILE__, |
|
| 802 | + __FUNCTION__, |
|
| 803 | + __LINE__ |
|
| 804 | + ); |
|
| 805 | + } |
|
| 806 | + parent::_create_new_cpt_item(); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + |
|
| 810 | + /** |
|
| 811 | + * Sets the _views property for the default route in this admin page group. |
|
| 812 | + */ |
|
| 813 | + protected function _set_list_table_views_default() |
|
| 814 | + { |
|
| 815 | + $this->_views = [ |
|
| 816 | + 'all' => [ |
|
| 817 | + 'slug' => 'all', |
|
| 818 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 819 | + 'count' => 0, |
|
| 820 | + 'bulk_action' => [ |
|
| 821 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 822 | + ], |
|
| 823 | + ], |
|
| 824 | + 'draft' => [ |
|
| 825 | + 'slug' => 'draft', |
|
| 826 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 827 | + 'count' => 0, |
|
| 828 | + 'bulk_action' => [ |
|
| 829 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 830 | + ], |
|
| 831 | + ], |
|
| 832 | + ]; |
|
| 833 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 834 | + $this->_views['trash'] = [ |
|
| 835 | + 'slug' => 'trash', |
|
| 836 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 837 | + 'count' => 0, |
|
| 838 | + 'bulk_action' => [ |
|
| 839 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 840 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 841 | + ], |
|
| 842 | + ]; |
|
| 843 | + } |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * Provides the legend item array for the default list table view. |
|
| 849 | + * |
|
| 850 | + * @return array |
|
| 851 | + */ |
|
| 852 | + protected function _event_legend_items() |
|
| 853 | + { |
|
| 854 | + $items = [ |
|
| 855 | + 'view_details' => [ |
|
| 856 | + 'class' => 'dashicons dashicons-search', |
|
| 857 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 858 | + ], |
|
| 859 | + 'edit_event' => [ |
|
| 860 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 861 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 862 | + ], |
|
| 863 | + 'view_attendees' => [ |
|
| 864 | + 'class' => 'dashicons dashicons-groups', |
|
| 865 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 866 | + ], |
|
| 867 | + ]; |
|
| 868 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 869 | + $statuses = [ |
|
| 870 | + 'sold_out_status' => [ |
|
| 871 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 872 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 873 | + ], |
|
| 874 | + 'active_status' => [ |
|
| 875 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 876 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 877 | + ], |
|
| 878 | + 'upcoming_status' => [ |
|
| 879 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 880 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 881 | + ], |
|
| 882 | + 'postponed_status' => [ |
|
| 883 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 884 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 885 | + ], |
|
| 886 | + 'cancelled_status' => [ |
|
| 887 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 888 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 889 | + ], |
|
| 890 | + 'expired_status' => [ |
|
| 891 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 892 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 893 | + ], |
|
| 894 | + 'inactive_status' => [ |
|
| 895 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 896 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 897 | + ], |
|
| 898 | + ]; |
|
| 899 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 900 | + return array_merge($items, $statuses); |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + /** |
|
| 905 | + * @return EEM_Event |
|
| 906 | + * @throws EE_Error |
|
| 907 | + */ |
|
| 908 | + private function eventModel() |
|
| 909 | + { |
|
| 910 | + if (! $this->_event_model instanceof EEM_Event) { |
|
| 911 | + $this->_event_model = EEM_Event::instance(); |
|
| 912 | + } |
|
| 913 | + return $this->_event_model; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * @param string $event_timezone_string |
|
| 919 | + * @return EEM_Datetime |
|
| 920 | + * @throws EE_Error |
|
| 921 | + */ |
|
| 922 | + private function datetimeModel($event_timezone_string = '') |
|
| 923 | + { |
|
| 924 | + if (! $this->datetime_model instanceof EEM_Datetime) { |
|
| 925 | + $this->datetime_model = EEM_Datetime::instance($event_timezone_string); |
|
| 926 | + } |
|
| 927 | + return $this->datetime_model; |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * @param string $event_timezone_string |
|
| 933 | + * @return EEM_Ticket |
|
| 934 | + * @throws EE_Error |
|
| 935 | + */ |
|
| 936 | + private function ticketModel($event_timezone_string = '') |
|
| 937 | + { |
|
| 938 | + if (! $this->ticket_model instanceof EEM_Ticket) { |
|
| 939 | + $this->ticket_model = EEM_Ticket::instance($event_timezone_string); |
|
| 940 | + } |
|
| 941 | + return $this->ticket_model; |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + /** |
|
| 946 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 947 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 948 | + * |
|
| 949 | + * @param string $return the current html |
|
| 950 | + * @param int $id the post id for the page |
|
| 951 | + * @param string $new_title What the title is |
|
| 952 | + * @param string $new_slug what the slug is |
|
| 953 | + * @return string The new html string for the permalink area |
|
| 954 | + */ |
|
| 955 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 956 | + { |
|
| 957 | + // make sure this is only when editing |
|
| 958 | + if (! empty($id)) { |
|
| 959 | + $post = get_post($id); |
|
| 960 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 961 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 962 | + . '</a> '; |
|
| 963 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 964 | + . $post->ID |
|
| 965 | + . ']">'; |
|
| 966 | + } |
|
| 967 | + return $return; |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * _events_overview_list_table |
|
| 973 | + * This contains the logic for showing the events_overview list |
|
| 974 | + * |
|
| 975 | + * @access protected |
|
| 976 | + * @return void |
|
| 977 | + * @throws DomainException |
|
| 978 | + * @throws EE_Error |
|
| 979 | + * @throws InvalidArgumentException |
|
| 980 | + * @throws InvalidDataTypeException |
|
| 981 | + * @throws InvalidInterfaceException |
|
| 982 | + */ |
|
| 983 | + protected function _events_overview_list_table() |
|
| 984 | + { |
|
| 985 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 986 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 987 | + ? (array) $this->_template_args['after_list_table'] |
|
| 988 | + : []; |
|
| 989 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 990 | + . EEH_Template::get_button_or_link( |
|
| 991 | + get_post_type_archive_link('espresso_events'), |
|
| 992 | + esc_html__('View Event Archive Page', 'event_espresso'), |
|
| 993 | + 'button' |
|
| 994 | + ); |
|
| 995 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 996 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 997 | + 'create_new', |
|
| 998 | + 'add', |
|
| 999 | + [], |
|
| 1000 | + 'add-new-h2' |
|
| 1001 | + ); |
|
| 1002 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * this allows for extra misc actions in the default WP publish box |
|
| 1008 | + * |
|
| 1009 | + * @return void |
|
| 1010 | + * @throws DomainException |
|
| 1011 | + * @throws EE_Error |
|
| 1012 | + * @throws InvalidArgumentException |
|
| 1013 | + * @throws InvalidDataTypeException |
|
| 1014 | + * @throws InvalidInterfaceException |
|
| 1015 | + * @throws ReflectionException |
|
| 1016 | + */ |
|
| 1017 | + public function extra_misc_actions_publish_box() |
|
| 1018 | + { |
|
| 1019 | + $this->_generate_publish_box_extra_content(); |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + |
|
| 1023 | + /** |
|
| 1024 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1025 | + * saved. |
|
| 1026 | + * Typically you would use this to save any additional data. |
|
| 1027 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1028 | + * ALSO very important. When a post transitions from scheduled to published, |
|
| 1029 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1030 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1031 | + * |
|
| 1032 | + * @access protected |
|
| 1033 | + * @abstract |
|
| 1034 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1035 | + * @param object $post The post object of the cpt that was saved. |
|
| 1036 | + * @return void |
|
| 1037 | + * @throws EE_Error |
|
| 1038 | + * @throws InvalidArgumentException |
|
| 1039 | + * @throws InvalidDataTypeException |
|
| 1040 | + * @throws InvalidInterfaceException |
|
| 1041 | + * @throws ReflectionException |
|
| 1042 | + */ |
|
| 1043 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 1044 | + { |
|
| 1045 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1046 | + // get out we're not processing an event save. |
|
| 1047 | + return; |
|
| 1048 | + } |
|
| 1049 | + $event_values = [ |
|
| 1050 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 1051 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 1052 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 1053 | + ? sanitize_text_field($this->_req_data['timezone_string']) |
|
| 1054 | + : null, |
|
| 1055 | + ]; |
|
| 1056 | + /** @var FeatureFlags $flags */ |
|
| 1057 | + $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags'); |
|
| 1058 | + // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
| 1059 | + if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1060 | + $event_values['EVT_display_ticket_selector'] = |
|
| 1061 | + ! empty($this->_req_data['display_ticket_selector']) |
|
| 1062 | + ? 1 |
|
| 1063 | + : 0; |
|
| 1064 | + $event_values['EVT_additional_limit'] = min( |
|
| 1065 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1066 | + ! empty($this->_req_data['additional_limit']) |
|
| 1067 | + ? absint($this->_req_data['additional_limit']) |
|
| 1068 | + : null |
|
| 1069 | + ); |
|
| 1070 | + $event_values['EVT_default_registration_status'] = |
|
| 1071 | + ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 1072 | + ? sanitize_text_field($this->_req_data['EVT_default_registration_status']) |
|
| 1073 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 1074 | + $event_values['EVT_external_URL'] = ! empty($this->_req_data['externalURL']) |
|
| 1075 | + ? esc_url_raw($this->_req_data['externalURL']) |
|
| 1076 | + : null; |
|
| 1077 | + $event_values['EVT_phone'] = ! empty($this->_req_data['event_phone']) |
|
| 1078 | + ? sanitize_text_field($this->_req_data['event_phone']) |
|
| 1079 | + : null; |
|
| 1080 | + } |
|
| 1081 | + // update event |
|
| 1082 | + $success = $this->eventModel()->update_by_ID($event_values, $post_id); |
|
| 1083 | + // get event_object for other metaboxes... |
|
| 1084 | + // though it would seem to make sense to just use $this->eventModel()->get_one_by_ID( $post_id ).. |
|
| 1085 | + // i have to setup where conditions to override the filters in the model |
|
| 1086 | + // that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 1087 | + $get_one_where = [ |
|
| 1088 | + $this->eventModel()->primary_key_name() => $post_id, |
|
| 1089 | + 'OR' => [ |
|
| 1090 | + 'status' => $post->post_status, |
|
| 1091 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1092 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1093 | + 'status*1' => $this->_req_data['original_post_status'], |
|
| 1094 | + ], |
|
| 1095 | + ]; |
|
| 1096 | + $event = $this->eventModel()->get_one([$get_one_where]); |
|
| 1097 | + // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 1098 | + $event_update_callbacks = apply_filters( |
|
| 1099 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1100 | + [ |
|
| 1101 | + [$this, '_default_venue_update'], |
|
| 1102 | + [$this, '_default_tickets_update'], |
|
| 1103 | + ] |
|
| 1104 | + ); |
|
| 1105 | + $att_success = true; |
|
| 1106 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 1107 | + $_success = is_callable($e_callback) |
|
| 1108 | + ? $e_callback($event, $this->_req_data) |
|
| 1109 | + : false; |
|
| 1110 | + // if ANY of these updates fail then we want the appropriate global error message |
|
| 1111 | + $att_success = ! $att_success ? $att_success : $_success; |
|
| 1112 | + } |
|
| 1113 | + // any errors? |
|
| 1114 | + if ($success && false === $att_success) { |
|
| 1115 | + EE_Error::add_error( |
|
| 1116 | + esc_html__( |
|
| 1117 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1118 | + 'event_espresso' |
|
| 1119 | + ), |
|
| 1120 | + __FILE__, |
|
| 1121 | + __FUNCTION__, |
|
| 1122 | + __LINE__ |
|
| 1123 | + ); |
|
| 1124 | + } elseif ($success === false) { |
|
| 1125 | + EE_Error::add_error( |
|
| 1126 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1127 | + __FILE__, |
|
| 1128 | + __FUNCTION__, |
|
| 1129 | + __LINE__ |
|
| 1130 | + ); |
|
| 1131 | + } |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + |
|
| 1135 | + /** |
|
| 1136 | + * @param int $post_id |
|
| 1137 | + * @param int $revision_id |
|
| 1138 | + * @throws EE_Error |
|
| 1139 | + * @throws InvalidArgumentException |
|
| 1140 | + * @throws InvalidDataTypeException |
|
| 1141 | + * @throws InvalidInterfaceException |
|
| 1142 | + * @throws ReflectionException |
|
| 1143 | + * @see parent::restore_item() |
|
| 1144 | + */ |
|
| 1145 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1146 | + { |
|
| 1147 | + // copy existing event meta to new post |
|
| 1148 | + $post_evt = $this->eventModel()->get_one_by_ID($post_id); |
|
| 1149 | + if ($post_evt instanceof EE_Event) { |
|
| 1150 | + // meta revision restore |
|
| 1151 | + $post_evt->restore_revision($revision_id); |
|
| 1152 | + // related objs restore |
|
| 1153 | + $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * Attach the venue to the Event |
|
| 1160 | + * |
|
| 1161 | + * @param EE_Event $evtobj Event Object to add the venue to |
|
| 1162 | + * @param array $data The request data from the form |
|
| 1163 | + * @return bool Success or fail. |
|
| 1164 | + * @throws EE_Error |
|
| 1165 | + * @throws InvalidArgumentException |
|
| 1166 | + * @throws InvalidDataTypeException |
|
| 1167 | + * @throws InvalidInterfaceException |
|
| 1168 | + * @throws ReflectionException |
|
| 1169 | + */ |
|
| 1170 | + protected function _default_venue_update(EE_Event $evtobj, $data) |
|
| 1171 | + { |
|
| 1172 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1173 | + $venue_model = EEM_Venue::instance(); |
|
| 1174 | + $rows_affected = null; |
|
| 1175 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1176 | + // very important. If we don't have a venue name... |
|
| 1177 | + // then we'll get out because not necessary to create empty venue |
|
| 1178 | + if (empty($data['venue_title'])) { |
|
| 1179 | + return false; |
|
| 1180 | + } |
|
| 1181 | + $venue_array = [ |
|
| 1182 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1183 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1184 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1185 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1186 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1187 | + : null, |
|
| 1188 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1189 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1190 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1191 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1192 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1193 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1194 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1195 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1196 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1197 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1198 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1199 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1200 | + 'status' => 'publish', |
|
| 1201 | + ]; |
|
| 1202 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1203 | + if (! empty($venue_id)) { |
|
| 1204 | + $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1205 | + $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1206 | + // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1207 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1208 | + return $rows_affected > 0; |
|
| 1209 | + } |
|
| 1210 | + // we insert the venue |
|
| 1211 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1212 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1213 | + return ! empty($venue_id) ? true : false; |
|
| 1214 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1220 | + * |
|
| 1221 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1222 | + * @param array $data The request data from the form |
|
| 1223 | + * @return array |
|
| 1224 | + * @throws EE_Error |
|
| 1225 | + * @throws InvalidArgumentException |
|
| 1226 | + * @throws InvalidDataTypeException |
|
| 1227 | + * @throws InvalidInterfaceException |
|
| 1228 | + * @throws ReflectionException |
|
| 1229 | + * @throws Exception |
|
| 1230 | + */ |
|
| 1231 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1232 | + { |
|
| 1233 | + if ($this->admin_config->useAdvancedEditor()) { |
|
| 1234 | + return []; |
|
| 1235 | + } |
|
| 1236 | + $saved_dtt = null; |
|
| 1237 | + $saved_tickets = []; |
|
| 1238 | + $incoming_date_formats = ['Y-m-d', 'h:i a']; |
|
| 1239 | + $event_timezone_string = $evtobj->get_timezone(); |
|
| 1240 | + $event_timezone = new DateTimeZone($event_timezone_string); |
|
| 1241 | + // let's use now in the set timezone. |
|
| 1242 | + $now = new DateTime('now', $event_timezone); |
|
| 1243 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1244 | + // trim all values to ensure any excess whitespace is removed. |
|
| 1245 | + $dtt = array_map('trim', $dtt); |
|
| 1246 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) |
|
| 1247 | + ? $dtt['DTT_EVT_end'] |
|
| 1248 | + : $dtt['DTT_EVT_start']; |
|
| 1249 | + $datetime_values = [ |
|
| 1250 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1251 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1252 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1253 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1254 | + 'DTT_order' => $row, |
|
| 1255 | + ]; |
|
| 1256 | + // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1257 | + if (! empty($dtt['DTT_ID'])) { |
|
| 1258 | + $DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']); |
|
| 1259 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1260 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1261 | + foreach ($datetime_values as $field => $value) { |
|
| 1262 | + $DTM->set($field, $value); |
|
| 1263 | + } |
|
| 1264 | + // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1265 | + $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1266 | + } else { |
|
| 1267 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1268 | + 'Datetime', |
|
| 1269 | + [$datetime_values, $event_timezone_string, $incoming_date_formats], |
|
| 1270 | + false, |
|
| 1271 | + false |
|
| 1272 | + ); |
|
| 1273 | + foreach ($datetime_values as $field => $value) { |
|
| 1274 | + $DTM->set($field, $value); |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | + $DTM->save(); |
|
| 1278 | + $DTM = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1279 | + // load DTT helper |
|
| 1280 | + // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1281 | + if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) { |
|
| 1282 | + $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start')); |
|
| 1283 | + $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days'); |
|
| 1284 | + $DTM->save(); |
|
| 1285 | + } |
|
| 1286 | + // now we got to make sure we add the new DTT_ID to the $saved_dtts array |
|
| 1287 | + // because it is possible there was a new one created for the autosave. |
|
| 1288 | + $saved_dtt = $DTM; |
|
| 1289 | + // if ANY of these updates fail then we want the appropriate global error message. |
|
| 1290 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1291 | + } |
|
| 1292 | + // no dtts get deleted so we don't do any of that logic here. |
|
| 1293 | + // update tickets next |
|
| 1294 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1295 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1296 | + $incoming_date_formats = ['Y-m-d', 'h:i a']; |
|
| 1297 | + $update_prices = false; |
|
| 1298 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1299 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
| 1300 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1301 | + $tkt = array_map('trim', $tkt); |
|
| 1302 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1303 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1304 | + } |
|
| 1305 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1306 | + // use the start date of the first datetime |
|
| 1307 | + $dtt = $evtobj->first_datetime(); |
|
| 1308 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1309 | + $incoming_date_formats[0], |
|
| 1310 | + $incoming_date_formats[1] |
|
| 1311 | + ); |
|
| 1312 | + } |
|
| 1313 | + $TKT_values = [ |
|
| 1314 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1315 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1316 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1317 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1318 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1319 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1320 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1321 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1322 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1323 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1324 | + 'TKT_row' => $row, |
|
| 1325 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1326 | + 'TKT_price' => $ticket_price, |
|
| 1327 | + ]; |
|
| 1328 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1329 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1330 | + $TKT_values['TKT_ID'] = 0; |
|
| 1331 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1332 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1333 | + $update_prices = true; |
|
| 1334 | + } |
|
| 1335 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1336 | + // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1337 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1338 | + if (! empty($tkt['TKT_ID'])) { |
|
| 1339 | + $TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']); |
|
| 1340 | + if ($TKT instanceof EE_Ticket) { |
|
| 1341 | + $ticket_sold = $TKT->count_related( |
|
| 1342 | + 'Registration', |
|
| 1343 | + [ |
|
| 1344 | + [ |
|
| 1345 | + 'STS_ID' => [ |
|
| 1346 | + 'NOT IN', |
|
| 1347 | + [EEM_Registration::status_id_incomplete], |
|
| 1348 | + ], |
|
| 1349 | + ], |
|
| 1350 | + ] |
|
| 1351 | + ) > 0; |
|
| 1352 | + // let's just check the total price for the existing ticket and determine if it matches the new |
|
| 1353 | + // total price. if they are different then we create a new ticket (if tickets sold) |
|
| 1354 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 1355 | + $create_new_TKT = $ticket_sold && ! $TKT->deleted() |
|
| 1356 | + && EEH_Money::compare_floats( |
|
| 1357 | + $ticket_price, |
|
| 1358 | + $TKT->get('TKT_price'), |
|
| 1359 | + '!==' |
|
| 1360 | + ); |
|
| 1361 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1362 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1363 | + // set new values |
|
| 1364 | + foreach ($TKT_values as $field => $value) { |
|
| 1365 | + if ($field === 'TKT_qty') { |
|
| 1366 | + $TKT->set_qty($value); |
|
| 1367 | + } else { |
|
| 1368 | + $TKT->set($field, $value); |
|
| 1369 | + } |
|
| 1370 | + } |
|
| 1371 | + // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1372 | + if ($create_new_TKT) { |
|
| 1373 | + // archive the old ticket first |
|
| 1374 | + $TKT->set('TKT_deleted', 1); |
|
| 1375 | + $TKT->save(); |
|
| 1376 | + // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1377 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1378 | + // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1379 | + $TKT = clone $TKT; |
|
| 1380 | + $TKT->set('TKT_ID', 0); |
|
| 1381 | + $TKT->set('TKT_deleted', 0); |
|
| 1382 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1383 | + $TKT->set('TKT_sold', 0); |
|
| 1384 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1385 | + $update_prices = true; |
|
| 1386 | + } |
|
| 1387 | + // make sure price is set if it hasn't been already |
|
| 1388 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1389 | + } |
|
| 1390 | + } else { |
|
| 1391 | + // no TKT_id so a new TKT |
|
| 1392 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1393 | + $TKT = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false); |
|
| 1394 | + if ($TKT instanceof EE_Ticket) { |
|
| 1395 | + // need to reset values to properly account for the date formats |
|
| 1396 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1397 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1398 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1399 | + // set new values |
|
| 1400 | + foreach ($TKT_values as $field => $value) { |
|
| 1401 | + if ($field === 'TKT_qty') { |
|
| 1402 | + $TKT->set_qty($value); |
|
| 1403 | + } else { |
|
| 1404 | + $TKT->set($field, $value); |
|
| 1405 | + } |
|
| 1406 | + } |
|
| 1407 | + $update_prices = true; |
|
| 1408 | + } |
|
| 1409 | + } |
|
| 1410 | + // cap ticket qty by datetime reg limits |
|
| 1411 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1412 | + // update ticket. |
|
| 1413 | + $TKT->save(); |
|
| 1414 | + // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1415 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1416 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1417 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1418 | + $TKT->save(); |
|
| 1419 | + } |
|
| 1420 | + // initially let's add the ticket to the dtt |
|
| 1421 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1422 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1423 | + // add prices to ticket |
|
| 1424 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1425 | + } |
|
| 1426 | + // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1427 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
| 1428 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1429 | + foreach ($tickets_removed as $id) { |
|
| 1430 | + $id = absint($id); |
|
| 1431 | + // get the ticket for this id |
|
| 1432 | + $tkt_to_remove = $this->ticketModel($event_timezone_string)->get_one_by_ID($id); |
|
| 1433 | + // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1434 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1435 | + foreach ($dtts as $dtt) { |
|
| 1436 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1437 | + } |
|
| 1438 | + // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1439 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1440 | + // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1441 | + $tkt_to_remove->delete_permanently(); |
|
| 1442 | + } |
|
| 1443 | + return [$saved_dtt, $saved_tickets]; |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + |
|
| 1447 | + /** |
|
| 1448 | + * This attaches a list of given prices to a ticket. |
|
| 1449 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1450 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1451 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1452 | + * |
|
| 1453 | + * @access private |
|
| 1454 | + * @param array $prices Array of prices from the form. |
|
| 1455 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1456 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1457 | + * @return void |
|
| 1458 | + * @throws EE_Error |
|
| 1459 | + * @throws InvalidArgumentException |
|
| 1460 | + * @throws InvalidDataTypeException |
|
| 1461 | + * @throws InvalidInterfaceException |
|
| 1462 | + * @throws ReflectionException |
|
| 1463 | + */ |
|
| 1464 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1465 | + { |
|
| 1466 | + foreach ($prices as $row => $prc) { |
|
| 1467 | + $PRC_values = [ |
|
| 1468 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1469 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1470 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1471 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1472 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1473 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1474 | + 'PRC_order' => $row, |
|
| 1475 | + ]; |
|
| 1476 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1477 | + $PRC_values['PRC_ID'] = 0; |
|
| 1478 | + $PRC = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false); |
|
| 1479 | + } else { |
|
| 1480 | + $PRC = EEM_Price::instance()->get_one_by_ID($prc['PRC_ID']); |
|
| 1481 | + // update this price with new values |
|
| 1482 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1483 | + $PRC->set($field, $newprc); |
|
| 1484 | + } |
|
| 1485 | + $PRC->save(); |
|
| 1486 | + } |
|
| 1487 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1488 | + } |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + |
|
| 1492 | + /** |
|
| 1493 | + * Add in our autosave ajax handlers |
|
| 1494 | + * |
|
| 1495 | + */ |
|
| 1496 | + protected function _ee_autosave_create_new() |
|
| 1497 | + { |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + |
|
| 1501 | + /** |
|
| 1502 | + * More autosave handlers. |
|
| 1503 | + */ |
|
| 1504 | + protected function _ee_autosave_edit() |
|
| 1505 | + { |
|
| 1506 | + } |
|
| 1507 | + |
|
| 1508 | + |
|
| 1509 | + /** |
|
| 1510 | + * _generate_publish_box_extra_content |
|
| 1511 | + * |
|
| 1512 | + * @throws DomainException |
|
| 1513 | + * @throws EE_Error |
|
| 1514 | + * @throws InvalidArgumentException |
|
| 1515 | + * @throws InvalidDataTypeException |
|
| 1516 | + * @throws InvalidInterfaceException |
|
| 1517 | + * @throws ReflectionException |
|
| 1518 | + */ |
|
| 1519 | + private function _generate_publish_box_extra_content() |
|
| 1520 | + { |
|
| 1521 | + // load formatter helper |
|
| 1522 | + // args for getting related registrations |
|
| 1523 | + $approved_query_args = [ |
|
| 1524 | + [ |
|
| 1525 | + 'REG_deleted' => 0, |
|
| 1526 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1527 | + ], |
|
| 1528 | + ]; |
|
| 1529 | + $not_approved_query_args = [ |
|
| 1530 | + [ |
|
| 1531 | + 'REG_deleted' => 0, |
|
| 1532 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1533 | + ], |
|
| 1534 | + ]; |
|
| 1535 | + $pending_payment_query_args = [ |
|
| 1536 | + [ |
|
| 1537 | + 'REG_deleted' => 0, |
|
| 1538 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1539 | + ], |
|
| 1540 | + ]; |
|
| 1541 | + // publish box |
|
| 1542 | + $publish_box_extra_args = [ |
|
| 1543 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1544 | + [ |
|
| 1545 | + 'action' => 'default', |
|
| 1546 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1547 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1548 | + ], |
|
| 1549 | + REG_ADMIN_URL |
|
| 1550 | + ), |
|
| 1551 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1552 | + [ |
|
| 1553 | + 'action' => 'default', |
|
| 1554 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1555 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1556 | + ], |
|
| 1557 | + REG_ADMIN_URL |
|
| 1558 | + ), |
|
| 1559 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1560 | + [ |
|
| 1561 | + 'action' => 'default', |
|
| 1562 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1563 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1564 | + ], |
|
| 1565 | + REG_ADMIN_URL |
|
| 1566 | + ), |
|
| 1567 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1568 | + 'Registration', |
|
| 1569 | + $approved_query_args |
|
| 1570 | + ), |
|
| 1571 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1572 | + 'Registration', |
|
| 1573 | + $not_approved_query_args |
|
| 1574 | + ), |
|
| 1575 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1576 | + 'Registration', |
|
| 1577 | + $pending_payment_query_args |
|
| 1578 | + ), |
|
| 1579 | + 'misc_pub_section_class' => apply_filters( |
|
| 1580 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1581 | + 'misc-pub-section' |
|
| 1582 | + ), |
|
| 1583 | + ]; |
|
| 1584 | + ob_start(); |
|
| 1585 | + do_action( |
|
| 1586 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1587 | + $this->_cpt_model_obj |
|
| 1588 | + ); |
|
| 1589 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1590 | + // load template |
|
| 1591 | + EEH_Template::display_template( |
|
| 1592 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1593 | + $publish_box_extra_args |
|
| 1594 | + ); |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + |
|
| 1598 | + /** |
|
| 1599 | + * @return EE_Event |
|
| 1600 | + */ |
|
| 1601 | + public function get_event_object() |
|
| 1602 | + { |
|
| 1603 | + return $this->_cpt_model_obj; |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + /** METABOXES * */ |
|
| 1610 | + /** |
|
| 1611 | + * _register_event_editor_meta_boxes |
|
| 1612 | + * add all metaboxes related to the event_editor |
|
| 1613 | + * |
|
| 1614 | + * @return void |
|
| 1615 | + * @throws EE_Error |
|
| 1616 | + * @throws InvalidArgumentException |
|
| 1617 | + * @throws InvalidDataTypeException |
|
| 1618 | + * @throws InvalidInterfaceException |
|
| 1619 | + * @throws ReflectionException |
|
| 1620 | + */ |
|
| 1621 | + protected function _register_event_editor_meta_boxes() |
|
| 1622 | + { |
|
| 1623 | + $this->verify_cpt_object(); |
|
| 1624 | + $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
| 1625 | + /** @var FeatureFlags $flags */ |
|
| 1626 | + $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags'); |
|
| 1627 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1628 | + if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1629 | + add_meta_box( |
|
| 1630 | + 'espresso_event_editor_event_options', |
|
| 1631 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1632 | + [$this, 'registration_options_meta_box'], |
|
| 1633 | + $this->page_slug, |
|
| 1634 | + 'side' |
|
| 1635 | + ); |
|
| 1636 | + } |
|
| 1637 | + if (! $use_advanced_editor) { |
|
| 1638 | + add_meta_box( |
|
| 1639 | + 'espresso_event_editor_tickets', |
|
| 1640 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1641 | + [$this, 'ticket_metabox'], |
|
| 1642 | + $this->page_slug, |
|
| 1643 | + 'normal', |
|
| 1644 | + 'high' |
|
| 1645 | + ); |
|
| 1646 | + } else { |
|
| 1647 | + if ($flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1648 | + add_action( |
|
| 1649 | + 'add_meta_boxes_espresso_events', |
|
| 1650 | + function () { |
|
| 1651 | + global $current_screen; |
|
| 1652 | + remove_meta_box('authordiv', $current_screen, 'normal'); |
|
| 1653 | + }, |
|
| 1654 | + 99 |
|
| 1655 | + ); |
|
| 1656 | + } |
|
| 1657 | + } |
|
| 1658 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1659 | + // where a metabox has a related management page in the admin |
|
| 1660 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1661 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1662 | + } |
|
| 1663 | + |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * @throws DomainException |
|
| 1667 | + * @throws EE_Error |
|
| 1668 | + * @throws InvalidArgumentException |
|
| 1669 | + * @throws InvalidDataTypeException |
|
| 1670 | + * @throws InvalidInterfaceException |
|
| 1671 | + * @throws ReflectionException |
|
| 1672 | + */ |
|
| 1673 | + public function ticket_metabox() |
|
| 1674 | + { |
|
| 1675 | + $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1676 | + // defaults for template args |
|
| 1677 | + $template_args = [ |
|
| 1678 | + 'existing_datetime_ids' => '', |
|
| 1679 | + 'event_datetime_help_link' => '', |
|
| 1680 | + 'ticket_options_help_link' => '', |
|
| 1681 | + 'time' => null, |
|
| 1682 | + 'ticket_rows' => '', |
|
| 1683 | + 'existing_ticket_ids' => '', |
|
| 1684 | + 'total_ticket_rows' => 1, |
|
| 1685 | + 'ticket_js_structure' => '', |
|
| 1686 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1687 | + 'disabled' => '', |
|
| 1688 | + ]; |
|
| 1689 | + $event_id = $this->_cpt_model_obj instanceof EE_Event ? $this->_cpt_model_obj->ID() : 0; |
|
| 1690 | + $event_timezone_string = $this->_cpt_model_obj instanceof EE_Event |
|
| 1691 | + ? $this->_cpt_model_obj->timezone_string() |
|
| 1692 | + : ''; |
|
| 1693 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1694 | + /** |
|
| 1695 | + * 1. Start with retrieving Datetimes |
|
| 1696 | + * 2. Fore each datetime get related tickets |
|
| 1697 | + * 3. For each ticket get related prices |
|
| 1698 | + */ |
|
| 1699 | + $times = $this->datetimeModel($event_timezone_string)->get_all_event_dates($event_id); |
|
| 1700 | + /** @type EE_Datetime $first_datetime */ |
|
| 1701 | + $first_datetime = reset($times); |
|
| 1702 | + // do we get related tickets? |
|
| 1703 | + if ( |
|
| 1704 | + $first_datetime instanceof EE_Datetime |
|
| 1705 | + && $first_datetime->ID() !== 0 |
|
| 1706 | + ) { |
|
| 1707 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1708 | + $template_args['time'] = $first_datetime; |
|
| 1709 | + $related_tickets = $first_datetime->tickets( |
|
| 1710 | + [ |
|
| 1711 | + ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1712 | + 'default_where_conditions' => 'none', |
|
| 1713 | + ] |
|
| 1714 | + ); |
|
| 1715 | + if (! empty($related_tickets)) { |
|
| 1716 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1717 | + $row = 0; |
|
| 1718 | + foreach ($related_tickets as $ticket) { |
|
| 1719 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1720 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1721 | + $row++; |
|
| 1722 | + } |
|
| 1723 | + } else { |
|
| 1724 | + $template_args['total_ticket_rows'] = 1; |
|
| 1725 | + /** @type EE_Ticket $ticket */ |
|
| 1726 | + $ticket = $this->ticketModel($event_timezone_string)->create_default_object(); |
|
| 1727 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1728 | + } |
|
| 1729 | + } else { |
|
| 1730 | + $template_args['time'] = $times[0]; |
|
| 1731 | + /** @type EE_Ticket $ticket */ |
|
| 1732 | + $ticket = $this->ticketModel($event_timezone_string)->get_all_default_tickets(); |
|
| 1733 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1734 | + // NOTE: we're just sending the first default row |
|
| 1735 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1736 | + } |
|
| 1737 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1738 | + 'event_editor_event_datetimes_help_tab' |
|
| 1739 | + ); |
|
| 1740 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1741 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1742 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1743 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1744 | + $this->ticketModel($event_timezone_string)->create_default_object(), |
|
| 1745 | + true |
|
| 1746 | + ); |
|
| 1747 | + $template = apply_filters( |
|
| 1748 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1749 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1750 | + ); |
|
| 1751 | + EEH_Template::display_template($template, $template_args); |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + |
|
| 1755 | + /** |
|
| 1756 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1757 | + * |
|
| 1758 | + * @access private |
|
| 1759 | + * @param EE_Ticket $ticket the ticket object |
|
| 1760 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1761 | + * @param int $row |
|
| 1762 | + * @return string generated html for the ticket row. |
|
| 1763 | + * @throws DomainException |
|
| 1764 | + * @throws EE_Error |
|
| 1765 | + * @throws InvalidArgumentException |
|
| 1766 | + * @throws InvalidDataTypeException |
|
| 1767 | + * @throws InvalidInterfaceException |
|
| 1768 | + * @throws ReflectionException |
|
| 1769 | + */ |
|
| 1770 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1771 | + { |
|
| 1772 | + $template_args = [ |
|
| 1773 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1774 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1775 | + : '', |
|
| 1776 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1777 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1778 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1779 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1780 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1781 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1782 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1783 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1784 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1785 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1786 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1787 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1788 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1789 | + : ' disabled=disabled', |
|
| 1790 | + ]; |
|
| 1791 | + $price = $ticket->ID() !== 0 |
|
| 1792 | + ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1793 | + : EEM_Price::instance()->create_default_object(); |
|
| 1794 | + $price_args = [ |
|
| 1795 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1796 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1797 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1798 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1799 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1800 | + ]; |
|
| 1801 | + // make sure we have default start and end dates if skeleton |
|
| 1802 | + // handle rows that should NOT be empty |
|
| 1803 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1804 | + // if empty then the start date will be now. |
|
| 1805 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1806 | + } |
|
| 1807 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1808 | + // get the earliest datetime (if present); |
|
| 1809 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1810 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1811 | + 'Datetime', |
|
| 1812 | + ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1813 | + ) |
|
| 1814 | + : null; |
|
| 1815 | + if (! empty($earliest_dtt)) { |
|
| 1816 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1817 | + } else { |
|
| 1818 | + $template_args['TKT_end_date'] = date( |
|
| 1819 | + 'Y-m-d h:i a', |
|
| 1820 | + mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')) |
|
| 1821 | + ); |
|
| 1822 | + } |
|
| 1823 | + } |
|
| 1824 | + $template_args = array_merge($template_args, $price_args); |
|
| 1825 | + $template = apply_filters( |
|
| 1826 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1827 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1828 | + $ticket |
|
| 1829 | + ); |
|
| 1830 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1831 | + } |
|
| 1832 | + |
|
| 1833 | + |
|
| 1834 | + /** |
|
| 1835 | + * @throws DomainException |
|
| 1836 | + * @throws EE_Error |
|
| 1837 | + */ |
|
| 1838 | + public function registration_options_meta_box() |
|
| 1839 | + { |
|
| 1840 | + $yes_no_values = [ |
|
| 1841 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1842 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1843 | + ]; |
|
| 1844 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1845 | + [ |
|
| 1846 | + EEM_Registration::status_id_cancelled, |
|
| 1847 | + EEM_Registration::status_id_declined, |
|
| 1848 | + EEM_Registration::status_id_incomplete, |
|
| 1849 | + ], |
|
| 1850 | + true |
|
| 1851 | + ); |
|
| 1852 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1853 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1854 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1855 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1856 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1857 | + 'default_reg_status', |
|
| 1858 | + $default_reg_status_values, |
|
| 1859 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1860 | + ); |
|
| 1861 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1862 | + 'display_desc', |
|
| 1863 | + $yes_no_values, |
|
| 1864 | + $this->_cpt_model_obj->display_description() |
|
| 1865 | + ); |
|
| 1866 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1867 | + 'display_ticket_selector', |
|
| 1868 | + $yes_no_values, |
|
| 1869 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1870 | + '', |
|
| 1871 | + '', |
|
| 1872 | + false |
|
| 1873 | + ); |
|
| 1874 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1875 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1876 | + '', |
|
| 1877 | + $template_args, |
|
| 1878 | + $yes_no_values, |
|
| 1879 | + $default_reg_status_values |
|
| 1880 | + ); |
|
| 1881 | + EEH_Template::display_template( |
|
| 1882 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1883 | + $template_args |
|
| 1884 | + ); |
|
| 1885 | + } |
|
| 1886 | + |
|
| 1887 | + |
|
| 1888 | + /** |
|
| 1889 | + * _get_events() |
|
| 1890 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1891 | + * |
|
| 1892 | + * @access public |
|
| 1893 | + * @param int $per_page count of items per page (20 default); |
|
| 1894 | + * @param int $current_page what is the current page being viewed. |
|
| 1895 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1896 | + * If FALSE then we return an array of event objects |
|
| 1897 | + * that match the given _view and paging parameters. |
|
| 1898 | + * @return array an array of event objects. |
|
| 1899 | + * @throws EE_Error |
|
| 1900 | + * @throws InvalidArgumentException |
|
| 1901 | + * @throws InvalidDataTypeException |
|
| 1902 | + * @throws InvalidInterfaceException |
|
| 1903 | + * @throws ReflectionException |
|
| 1904 | + * @throws Exception |
|
| 1905 | + * @throws Exception |
|
| 1906 | + * @throws Exception |
|
| 1907 | + */ |
|
| 1908 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1909 | + { |
|
| 1910 | + $EEME = $this->eventModel(); |
|
| 1911 | + $offset = ($current_page - 1) * $per_page; |
|
| 1912 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1913 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1914 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 1915 | + if (isset($this->_req_data['month_range'])) { |
|
| 1916 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1917 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1918 | + // where PHP doesn't know what to assume for date. |
|
| 1919 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1920 | + $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1921 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1922 | + } |
|
| 1923 | + $where = []; |
|
| 1924 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1925 | + // determine what post_status our condition will have for the query. |
|
| 1926 | + switch ($status) { |
|
| 1927 | + case 'month': |
|
| 1928 | + case 'today': |
|
| 1929 | + case null: |
|
| 1930 | + case 'all': |
|
| 1931 | + break; |
|
| 1932 | + case 'draft': |
|
| 1933 | + $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1934 | + break; |
|
| 1935 | + default: |
|
| 1936 | + $where['status'] = $status; |
|
| 1937 | + } |
|
| 1938 | + // categories? |
|
| 1939 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1940 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1941 | + if (! empty($category)) { |
|
| 1942 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1943 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1944 | + } |
|
| 1945 | + // date where conditions |
|
| 1946 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1947 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
|
| 1948 | + $DateTime = new DateTime( |
|
| 1949 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1950 | + new DateTimeZone('UTC') |
|
| 1951 | + ); |
|
| 1952 | + $start = $DateTime->getTimestamp(); |
|
| 1953 | + // set the datetime to be the end of the month |
|
| 1954 | + $DateTime->setDate( |
|
| 1955 | + $year_r, |
|
| 1956 | + $month_r, |
|
| 1957 | + $DateTime->format('t') |
|
| 1958 | + )->setTime(23, 59, 59); |
|
| 1959 | + $end = $DateTime->getTimestamp(); |
|
| 1960 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1961 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') { |
|
| 1962 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1963 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1964 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1965 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1966 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') { |
|
| 1967 | + $now = date('Y-m-01'); |
|
| 1968 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1969 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1970 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1971 | + ->setTime(23, 59, 59) |
|
| 1972 | + ->format(implode(' ', $start_formats)); |
|
| 1973 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1974 | + } |
|
| 1975 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1976 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1977 | + } elseif ( |
|
| 1978 | + ! isset($where['status']) |
|
| 1979 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events') |
|
| 1980 | + ) { |
|
| 1981 | + $where['OR'] = [ |
|
| 1982 | + 'status*restrict_private' => ['!=', 'private'], |
|
| 1983 | + 'AND' => [ |
|
| 1984 | + 'status*inclusive' => ['=', 'private'], |
|
| 1985 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1986 | + ], |
|
| 1987 | + ]; |
|
| 1988 | + } |
|
| 1989 | + |
|
| 1990 | + if ( |
|
| 1991 | + isset($this->_req_data['EVT_wp_user']) |
|
| 1992 | + && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id() |
|
| 1993 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1994 | + ) { |
|
| 1995 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1996 | + } |
|
| 1997 | + // search query handling |
|
| 1998 | + if (isset($this->_req_data['s'])) { |
|
| 1999 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2000 | + $where['OR'] = [ |
|
| 2001 | + 'EVT_name' => ['LIKE', $search_string], |
|
| 2002 | + 'EVT_desc' => ['LIKE', $search_string], |
|
| 2003 | + 'EVT_short_desc' => ['LIKE', $search_string], |
|
| 2004 | + ]; |
|
| 2005 | + } |
|
| 2006 | + // filter events by venue. |
|
| 2007 | + if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
| 2008 | + $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
| 2009 | + } |
|
| 2010 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 2011 | + $query_params = apply_filters( |
|
| 2012 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 2013 | + [ |
|
| 2014 | + $where, |
|
| 2015 | + 'limit' => $limit, |
|
| 2016 | + 'order_by' => $orderby, |
|
| 2017 | + 'order' => $order, |
|
| 2018 | + 'group_by' => 'EVT_ID', |
|
| 2019 | + ], |
|
| 2020 | + $this->_req_data |
|
| 2021 | + ); |
|
| 2022 | + |
|
| 2023 | + // let's first check if we have special requests coming in. |
|
| 2024 | + if (isset($this->_req_data['active_status'])) { |
|
| 2025 | + switch ($this->_req_data['active_status']) { |
|
| 2026 | + case 'upcoming': |
|
| 2027 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 2028 | + break; |
|
| 2029 | + case 'expired': |
|
| 2030 | + return $EEME->get_expired_events($query_params, $count); |
|
| 2031 | + break; |
|
| 2032 | + case 'active': |
|
| 2033 | + return $EEME->get_active_events($query_params, $count); |
|
| 2034 | + break; |
|
| 2035 | + case 'inactive': |
|
| 2036 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 2037 | + break; |
|
| 2038 | + } |
|
| 2039 | + } |
|
| 2040 | + |
|
| 2041 | + $events = $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 2042 | + return $events; |
|
| 2043 | + } |
|
| 2044 | + |
|
| 2045 | + |
|
| 2046 | + /** |
|
| 2047 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 2048 | + * |
|
| 2049 | + * @param string $post_id |
|
| 2050 | + * @throws EE_Error |
|
| 2051 | + * @throws InvalidArgumentException |
|
| 2052 | + * @throws InvalidDataTypeException |
|
| 2053 | + * @throws InvalidInterfaceException |
|
| 2054 | + * @throws ReflectionException |
|
| 2055 | + */ |
|
| 2056 | + public function trash_cpt_item($post_id) |
|
| 2057 | + { |
|
| 2058 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 2059 | + $this->_trash_or_restore_event('trash', false); |
|
| 2060 | + } |
|
| 2061 | + |
|
| 2062 | + |
|
| 2063 | + /** |
|
| 2064 | + * @param string $post_id |
|
| 2065 | + * @throws EE_Error |
|
| 2066 | + * @throws InvalidArgumentException |
|
| 2067 | + * @throws InvalidDataTypeException |
|
| 2068 | + * @throws InvalidInterfaceException |
|
| 2069 | + * @throws ReflectionException |
|
| 2070 | + */ |
|
| 2071 | + public function restore_cpt_item($post_id) |
|
| 2072 | + { |
|
| 2073 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 2074 | + $this->_trash_or_restore_event('draft', false); |
|
| 2075 | + } |
|
| 2076 | + |
|
| 2077 | + |
|
| 2078 | + /** |
|
| 2079 | + * @param string $post_id |
|
| 2080 | + * @throws EE_Error |
|
| 2081 | + * @throws InvalidArgumentException |
|
| 2082 | + * @throws InvalidDataTypeException |
|
| 2083 | + * @throws InvalidInterfaceException |
|
| 2084 | + * @throws ReflectionException |
|
| 2085 | + */ |
|
| 2086 | + public function delete_cpt_item($post_id) |
|
| 2087 | + { |
|
| 2088 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 2089 | + $this->_delete_event(false); |
|
| 2090 | + } |
|
| 2091 | + |
|
| 2092 | + |
|
| 2093 | + /** |
|
| 2094 | + * _trash_or_restore_event |
|
| 2095 | + * |
|
| 2096 | + * @access protected |
|
| 2097 | + * @param string $event_status |
|
| 2098 | + * @param bool $redirect_after |
|
| 2099 | + * @throws EE_Error |
|
| 2100 | + * @throws InvalidArgumentException |
|
| 2101 | + * @throws InvalidDataTypeException |
|
| 2102 | + * @throws InvalidInterfaceException |
|
| 2103 | + * @throws ReflectionException |
|
| 2104 | + */ |
|
| 2105 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 2106 | + { |
|
| 2107 | + // determine the event id and set to array. |
|
| 2108 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 2109 | + // loop thru events |
|
| 2110 | + if ($EVT_ID) { |
|
| 2111 | + // clean status |
|
| 2112 | + $event_status = sanitize_key($event_status); |
|
| 2113 | + // grab status |
|
| 2114 | + if (! empty($event_status)) { |
|
| 2115 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2116 | + } else { |
|
| 2117 | + $success = false; |
|
| 2118 | + $msg = esc_html__( |
|
| 2119 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2120 | + 'event_espresso' |
|
| 2121 | + ); |
|
| 2122 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2123 | + } |
|
| 2124 | + } else { |
|
| 2125 | + $success = false; |
|
| 2126 | + $msg = esc_html__( |
|
| 2127 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2128 | + 'event_espresso' |
|
| 2129 | + ); |
|
| 2130 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2131 | + } |
|
| 2132 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2133 | + if ($redirect_after) { |
|
| 2134 | + $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2135 | + } |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + |
|
| 2139 | + /** |
|
| 2140 | + * _trash_or_restore_events |
|
| 2141 | + * |
|
| 2142 | + * @access protected |
|
| 2143 | + * @param string $event_status |
|
| 2144 | + * @return void |
|
| 2145 | + * @throws EE_Error |
|
| 2146 | + * @throws InvalidArgumentException |
|
| 2147 | + * @throws InvalidDataTypeException |
|
| 2148 | + * @throws InvalidInterfaceException |
|
| 2149 | + * @throws ReflectionException |
|
| 2150 | + */ |
|
| 2151 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2152 | + { |
|
| 2153 | + // clean status |
|
| 2154 | + $event_status = sanitize_key($event_status); |
|
| 2155 | + // grab status |
|
| 2156 | + if (! empty($event_status)) { |
|
| 2157 | + $success = true; |
|
| 2158 | + // determine the event id and set to array. |
|
| 2159 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []; |
|
| 2160 | + // loop thru events |
|
| 2161 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2162 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 2163 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2164 | + $success = $results !== false ? $success : false; |
|
| 2165 | + } else { |
|
| 2166 | + $msg = sprintf( |
|
| 2167 | + esc_html__( |
|
| 2168 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2169 | + 'event_espresso' |
|
| 2170 | + ), |
|
| 2171 | + $EVT_ID |
|
| 2172 | + ); |
|
| 2173 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2174 | + $success = false; |
|
| 2175 | + } |
|
| 2176 | + } |
|
| 2177 | + } else { |
|
| 2178 | + $success = false; |
|
| 2179 | + $msg = esc_html__( |
|
| 2180 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2181 | + 'event_espresso' |
|
| 2182 | + ); |
|
| 2183 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2184 | + } |
|
| 2185 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2186 | + $success = $success ? 2 : false; |
|
| 2187 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2188 | + $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2189 | + } |
|
| 2190 | + |
|
| 2191 | + |
|
| 2192 | + /** |
|
| 2193 | + * _trash_or_restore_events |
|
| 2194 | + * |
|
| 2195 | + * @access private |
|
| 2196 | + * @param int $EVT_ID |
|
| 2197 | + * @param string $event_status |
|
| 2198 | + * @return bool |
|
| 2199 | + * @throws EE_Error |
|
| 2200 | + * @throws InvalidArgumentException |
|
| 2201 | + * @throws InvalidDataTypeException |
|
| 2202 | + * @throws InvalidInterfaceException |
|
| 2203 | + * @throws ReflectionException |
|
| 2204 | + */ |
|
| 2205 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2206 | + { |
|
| 2207 | + // grab event id |
|
| 2208 | + if (! $EVT_ID) { |
|
| 2209 | + $msg = esc_html__( |
|
| 2210 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2211 | + 'event_espresso' |
|
| 2212 | + ); |
|
| 2213 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2214 | + return false; |
|
| 2215 | + } |
|
| 2216 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2217 | + // clean status |
|
| 2218 | + $event_status = sanitize_key($event_status); |
|
| 2219 | + // grab status |
|
| 2220 | + if (empty($event_status)) { |
|
| 2221 | + $msg = esc_html__( |
|
| 2222 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2223 | + 'event_espresso' |
|
| 2224 | + ); |
|
| 2225 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2226 | + return false; |
|
| 2227 | + } |
|
| 2228 | + // was event trashed or restored ? |
|
| 2229 | + switch ($event_status) { |
|
| 2230 | + case 'draft': |
|
| 2231 | + $action = 'restored from the trash'; |
|
| 2232 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2233 | + break; |
|
| 2234 | + case 'trash': |
|
| 2235 | + $action = 'moved to the trash'; |
|
| 2236 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2237 | + break; |
|
| 2238 | + default: |
|
| 2239 | + $action = 'updated'; |
|
| 2240 | + $hook = false; |
|
| 2241 | + } |
|
| 2242 | + // use class to change status |
|
| 2243 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2244 | + $success = $this->_cpt_model_obj->save(); |
|
| 2245 | + if ($success === false) { |
|
| 2246 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2247 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2248 | + return false; |
|
| 2249 | + } |
|
| 2250 | + if ($hook) { |
|
| 2251 | + do_action($hook); |
|
| 2252 | + } |
|
| 2253 | + return true; |
|
| 2254 | + } |
|
| 2255 | + |
|
| 2256 | + |
|
| 2257 | + /** |
|
| 2258 | + * _delete_event |
|
| 2259 | + * |
|
| 2260 | + * @access protected |
|
| 2261 | + * @param bool $redirect_after |
|
| 2262 | + * @throws EE_Error |
|
| 2263 | + * @throws InvalidArgumentException |
|
| 2264 | + * @throws InvalidDataTypeException |
|
| 2265 | + * @throws InvalidInterfaceException |
|
| 2266 | + * @throws ReflectionException |
|
| 2267 | + */ |
|
| 2268 | + protected function _delete_event($redirect_after = true) |
|
| 2269 | + { |
|
| 2270 | + // determine the event id and set to array. |
|
| 2271 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2272 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2273 | + // loop thru events |
|
| 2274 | + if ($EVT_ID) { |
|
| 2275 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2276 | + // get list of events with no prices |
|
| 2277 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
|
| 2278 | + // remove this event from the list of events with no prices |
|
| 2279 | + if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
| 2280 | + unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2281 | + } |
|
| 2282 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2283 | + } else { |
|
| 2284 | + $success = false; |
|
| 2285 | + $msg = esc_html__( |
|
| 2286 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2287 | + 'event_espresso' |
|
| 2288 | + ); |
|
| 2289 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2290 | + } |
|
| 2291 | + if ($redirect_after) { |
|
| 2292 | + $this->_redirect_after_action( |
|
| 2293 | + $success, |
|
| 2294 | + 'Event', |
|
| 2295 | + 'deleted', |
|
| 2296 | + ['action' => 'default', 'status' => 'trash'] |
|
| 2297 | + ); |
|
| 2298 | + } |
|
| 2299 | + } |
|
| 2300 | + |
|
| 2301 | + |
|
| 2302 | + /** |
|
| 2303 | + * _delete_events |
|
| 2304 | + * |
|
| 2305 | + * @access protected |
|
| 2306 | + * @return void |
|
| 2307 | + * @throws EE_Error |
|
| 2308 | + * @throws InvalidArgumentException |
|
| 2309 | + * @throws InvalidDataTypeException |
|
| 2310 | + * @throws InvalidInterfaceException |
|
| 2311 | + * @throws ReflectionException |
|
| 2312 | + */ |
|
| 2313 | + protected function _delete_events() |
|
| 2314 | + { |
|
| 2315 | + $success = true; |
|
| 2316 | + // get list of events with no prices |
|
| 2317 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
|
| 2318 | + // determine the event id and set to array. |
|
| 2319 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []; |
|
| 2320 | + // loop thru events |
|
| 2321 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2322 | + $EVT_ID = absint($EVT_ID); |
|
| 2323 | + if ($EVT_ID) { |
|
| 2324 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2325 | + $success = $results !== false ? $success : false; |
|
| 2326 | + // remove this event from the list of events with no prices |
|
| 2327 | + unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2328 | + } else { |
|
| 2329 | + $success = false; |
|
| 2330 | + $msg = esc_html__( |
|
| 2331 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2332 | + 'event_espresso' |
|
| 2333 | + ); |
|
| 2334 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2335 | + } |
|
| 2336 | + } |
|
| 2337 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2338 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2339 | + $success = $success ? 2 : false; |
|
| 2340 | + $this->_redirect_after_action($success, 'Events', 'deleted', ['action' => 'default']); |
|
| 2341 | + } |
|
| 2342 | + |
|
| 2343 | + |
|
| 2344 | + /** |
|
| 2345 | + * _permanently_delete_event |
|
| 2346 | + * |
|
| 2347 | + * @access private |
|
| 2348 | + * @param int $EVT_ID |
|
| 2349 | + * @return bool |
|
| 2350 | + * @throws EE_Error |
|
| 2351 | + * @throws InvalidArgumentException |
|
| 2352 | + * @throws InvalidDataTypeException |
|
| 2353 | + * @throws InvalidInterfaceException |
|
| 2354 | + * @throws ReflectionException |
|
| 2355 | + */ |
|
| 2356 | + private function _permanently_delete_event($EVT_ID = 0) |
|
| 2357 | + { |
|
| 2358 | + // grab event id |
|
| 2359 | + if (! $EVT_ID) { |
|
| 2360 | + $msg = esc_html__( |
|
| 2361 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2362 | + 'event_espresso' |
|
| 2363 | + ); |
|
| 2364 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2365 | + return false; |
|
| 2366 | + } |
|
| 2367 | + if ( |
|
| 2368 | + ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2369 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2370 | + ) { |
|
| 2371 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2372 | + } |
|
| 2373 | + if (! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2374 | + return false; |
|
| 2375 | + } |
|
| 2376 | + // need to delete related tickets and prices first. |
|
| 2377 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2378 | + foreach ($datetimes as $datetime) { |
|
| 2379 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2380 | + $tickets = $datetime->get_many_related('Ticket'); |
|
| 2381 | + foreach ($tickets as $ticket) { |
|
| 2382 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2383 | + $ticket->delete_related_permanently('Price'); |
|
| 2384 | + $ticket->delete_permanently(); |
|
| 2385 | + } |
|
| 2386 | + $datetime->delete(); |
|
| 2387 | + } |
|
| 2388 | + // what about related venues or terms? |
|
| 2389 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2390 | + foreach ($venues as $venue) { |
|
| 2391 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2392 | + } |
|
| 2393 | + // any attached question groups? |
|
| 2394 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2395 | + if (! empty($question_groups)) { |
|
| 2396 | + foreach ($question_groups as $question_group) { |
|
| 2397 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2398 | + } |
|
| 2399 | + } |
|
| 2400 | + // Message Template Groups |
|
| 2401 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2402 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2403 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2404 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2405 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2406 | + } |
|
| 2407 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2408 | + // did it all go as planned ? |
|
| 2409 | + if ($success) { |
|
| 2410 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2411 | + EE_Error::add_success($msg); |
|
| 2412 | + } else { |
|
| 2413 | + $msg = sprintf( |
|
| 2414 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2415 | + $EVT_ID |
|
| 2416 | + ); |
|
| 2417 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2418 | + return false; |
|
| 2419 | + } |
|
| 2420 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2421 | + return true; |
|
| 2422 | + } |
|
| 2423 | + |
|
| 2424 | + |
|
| 2425 | + /** |
|
| 2426 | + * get total number of events |
|
| 2427 | + * |
|
| 2428 | + * @access public |
|
| 2429 | + * @return int |
|
| 2430 | + * @throws EE_Error |
|
| 2431 | + * @throws InvalidArgumentException |
|
| 2432 | + * @throws InvalidDataTypeException |
|
| 2433 | + * @throws InvalidInterfaceException |
|
| 2434 | + */ |
|
| 2435 | + public function total_events() |
|
| 2436 | + { |
|
| 2437 | + $count = EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2438 | + return $count; |
|
| 2439 | + } |
|
| 2440 | + |
|
| 2441 | + |
|
| 2442 | + /** |
|
| 2443 | + * get total number of draft events |
|
| 2444 | + * |
|
| 2445 | + * @access public |
|
| 2446 | + * @return int |
|
| 2447 | + * @throws EE_Error |
|
| 2448 | + * @throws InvalidArgumentException |
|
| 2449 | + * @throws InvalidDataTypeException |
|
| 2450 | + * @throws InvalidInterfaceException |
|
| 2451 | + */ |
|
| 2452 | + public function total_events_draft() |
|
| 2453 | + { |
|
| 2454 | + $where = [ |
|
| 2455 | + 'status' => ['IN', ['draft', 'auto-draft']], |
|
| 2456 | + ]; |
|
| 2457 | + $count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2458 | + return $count; |
|
| 2459 | + } |
|
| 2460 | + |
|
| 2461 | + |
|
| 2462 | + /** |
|
| 2463 | + * get total number of trashed events |
|
| 2464 | + * |
|
| 2465 | + * @access public |
|
| 2466 | + * @return int |
|
| 2467 | + * @throws EE_Error |
|
| 2468 | + * @throws InvalidArgumentException |
|
| 2469 | + * @throws InvalidDataTypeException |
|
| 2470 | + * @throws InvalidInterfaceException |
|
| 2471 | + */ |
|
| 2472 | + public function total_trashed_events() |
|
| 2473 | + { |
|
| 2474 | + $where = [ |
|
| 2475 | + 'status' => 'trash', |
|
| 2476 | + ]; |
|
| 2477 | + $count = EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2478 | + return $count; |
|
| 2479 | + } |
|
| 2480 | + |
|
| 2481 | + |
|
| 2482 | + /** |
|
| 2483 | + * _default_event_settings |
|
| 2484 | + * This generates the Default Settings Tab |
|
| 2485 | + * |
|
| 2486 | + * @return void |
|
| 2487 | + * @throws DomainException |
|
| 2488 | + * @throws EE_Error |
|
| 2489 | + * @throws InvalidArgumentException |
|
| 2490 | + * @throws InvalidDataTypeException |
|
| 2491 | + * @throws InvalidInterfaceException |
|
| 2492 | + */ |
|
| 2493 | + protected function _default_event_settings() |
|
| 2494 | + { |
|
| 2495 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2496 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2497 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2498 | + $this->display_admin_page_with_sidebar(); |
|
| 2499 | + } |
|
| 2500 | + |
|
| 2501 | + |
|
| 2502 | + /** |
|
| 2503 | + * Return the form for event settings. |
|
| 2504 | + * |
|
| 2505 | + * @return EE_Form_Section_Proper |
|
| 2506 | + * @throws EE_Error |
|
| 2507 | + */ |
|
| 2508 | + protected function _default_event_settings_form() |
|
| 2509 | + { |
|
| 2510 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2511 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2512 | + // exclude |
|
| 2513 | + [ |
|
| 2514 | + EEM_Registration::status_id_cancelled, |
|
| 2515 | + EEM_Registration::status_id_declined, |
|
| 2516 | + EEM_Registration::status_id_incomplete, |
|
| 2517 | + EEM_Registration::status_id_wait_list, |
|
| 2518 | + ], |
|
| 2519 | + true |
|
| 2520 | + ); |
|
| 2521 | + return new EE_Form_Section_Proper( |
|
| 2522 | + [ |
|
| 2523 | + 'name' => 'update_default_event_settings', |
|
| 2524 | + 'html_id' => 'update_default_event_settings', |
|
| 2525 | + 'html_class' => 'form-table', |
|
| 2526 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2527 | + 'subsections' => apply_filters( |
|
| 2528 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2529 | + [ |
|
| 2530 | + 'default_reg_status' => new EE_Select_Input( |
|
| 2531 | + $registration_stati_for_selection, |
|
| 2532 | + [ |
|
| 2533 | + 'default' => isset($registration_config->default_STS_ID) |
|
| 2534 | + && array_key_exists( |
|
| 2535 | + $registration_config->default_STS_ID, |
|
| 2536 | + $registration_stati_for_selection |
|
| 2537 | + ) |
|
| 2538 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2539 | + : EEM_Registration::status_id_pending_payment, |
|
| 2540 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2541 | + . EEH_Template::get_help_tab_link( |
|
| 2542 | + 'default_settings_status_help_tab' |
|
| 2543 | + ), |
|
| 2544 | + 'html_help_text' => esc_html__( |
|
| 2545 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2546 | + 'event_espresso' |
|
| 2547 | + ), |
|
| 2548 | + ] |
|
| 2549 | + ), |
|
| 2550 | + 'default_max_tickets' => new EE_Integer_Input( |
|
| 2551 | + [ |
|
| 2552 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2553 | + ? $registration_config->default_maximum_number_of_tickets |
|
| 2554 | + : EEM_Event::get_default_additional_limit(), |
|
| 2555 | + 'html_label_text' => esc_html__( |
|
| 2556 | + 'Default Maximum Tickets Allowed Per Order:', |
|
| 2557 | + 'event_espresso' |
|
| 2558 | + ) |
|
| 2559 | + . EEH_Template::get_help_tab_link( |
|
| 2560 | + 'default_maximum_tickets_help_tab"' |
|
| 2561 | + ), |
|
| 2562 | + 'html_help_text' => esc_html__( |
|
| 2563 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2564 | + 'event_espresso' |
|
| 2565 | + ), |
|
| 2566 | + ] |
|
| 2567 | + ), |
|
| 2568 | + ] |
|
| 2569 | + ), |
|
| 2570 | + ] |
|
| 2571 | + ); |
|
| 2572 | + } |
|
| 2573 | + |
|
| 2574 | + |
|
| 2575 | + /** |
|
| 2576 | + * @return void |
|
| 2577 | + * @throws EE_Error |
|
| 2578 | + * @throws InvalidArgumentException |
|
| 2579 | + * @throws InvalidDataTypeException |
|
| 2580 | + * @throws InvalidInterfaceException |
|
| 2581 | + */ |
|
| 2582 | + protected function _update_default_event_settings() |
|
| 2583 | + { |
|
| 2584 | + $form = $this->_default_event_settings_form(); |
|
| 2585 | + if ($form->was_submitted()) { |
|
| 2586 | + $form->receive_form_submission(); |
|
| 2587 | + if ($form->is_valid()) { |
|
| 2588 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2589 | + $valid_data = $form->valid_data(); |
|
| 2590 | + if (isset($valid_data['default_reg_status'])) { |
|
| 2591 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2592 | + } |
|
| 2593 | + if (isset($valid_data['default_max_tickets'])) { |
|
| 2594 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2595 | + } |
|
| 2596 | + do_action( |
|
| 2597 | + 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
| 2598 | + $valid_data, |
|
| 2599 | + EE_Registry::instance()->CFG, |
|
| 2600 | + $this |
|
| 2601 | + ); |
|
| 2602 | + // update because data was valid! |
|
| 2603 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2604 | + EE_Error::overwrite_success(); |
|
| 2605 | + EE_Error::add_success( |
|
| 2606 | + __('Default Event Settings were updated', 'event_espresso') |
|
| 2607 | + ); |
|
| 2608 | + } |
|
| 2609 | + } |
|
| 2610 | + $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2611 | + } |
|
| 2612 | + |
|
| 2613 | + |
|
| 2614 | + /************* Templates *************/ |
|
| 2615 | + protected function _template_settings() |
|
| 2616 | + { |
|
| 2617 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2618 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2619 | + . EVENTS_ASSETS_URL |
|
| 2620 | + . '/images/' |
|
| 2621 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2622 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2623 | + . '" />'; |
|
| 2624 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 2625 | + . esc_html__( |
|
| 2626 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2627 | + 'event_espresso' |
|
| 2628 | + ) . '</strong>'; |
|
| 2629 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2630 | + } |
|
| 2631 | + |
|
| 2632 | + |
|
| 2633 | + /** Event Category Stuff **/ |
|
| 2634 | + /** |
|
| 2635 | + * set the _category property with the category object for the loaded page. |
|
| 2636 | + * |
|
| 2637 | + * @access private |
|
| 2638 | + * @return void |
|
| 2639 | + */ |
|
| 2640 | + private function _set_category_object() |
|
| 2641 | + { |
|
| 2642 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2643 | + return; |
|
| 2644 | + } //already have the category object so get out. |
|
| 2645 | + // set default category object |
|
| 2646 | + $this->_set_empty_category_object(); |
|
| 2647 | + // only set if we've got an id |
|
| 2648 | + if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2649 | + return; |
|
| 2650 | + } |
|
| 2651 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2652 | + $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2653 | + if (! empty($term)) { |
|
| 2654 | + $this->_category->category_name = $term->name; |
|
| 2655 | + $this->_category->category_identifier = $term->slug; |
|
| 2656 | + $this->_category->category_desc = $term->description; |
|
| 2657 | + $this->_category->id = $term->term_id; |
|
| 2658 | + $this->_category->parent = $term->parent; |
|
| 2659 | + } |
|
| 2660 | + } |
|
| 2661 | + |
|
| 2662 | + |
|
| 2663 | + /** |
|
| 2664 | + * Clears out category properties. |
|
| 2665 | + */ |
|
| 2666 | + private function _set_empty_category_object() |
|
| 2667 | + { |
|
| 2668 | + $this->_category = new stdClass(); |
|
| 2669 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2670 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2671 | + } |
|
| 2672 | + |
|
| 2673 | + |
|
| 2674 | + /** |
|
| 2675 | + * @throws DomainException |
|
| 2676 | + * @throws EE_Error |
|
| 2677 | + * @throws InvalidArgumentException |
|
| 2678 | + * @throws InvalidDataTypeException |
|
| 2679 | + * @throws InvalidInterfaceException |
|
| 2680 | + */ |
|
| 2681 | + protected function _category_list_table() |
|
| 2682 | + { |
|
| 2683 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2684 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2685 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2686 | + 'add_category', |
|
| 2687 | + 'add_category', |
|
| 2688 | + [], |
|
| 2689 | + 'add-new-h2' |
|
| 2690 | + ); |
|
| 2691 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2692 | + } |
|
| 2693 | + |
|
| 2694 | + |
|
| 2695 | + /** |
|
| 2696 | + * Output category details view. |
|
| 2697 | + * |
|
| 2698 | + * @param string $view |
|
| 2699 | + * @throws DomainException |
|
| 2700 | + * @throws EE_Error |
|
| 2701 | + * @throws InvalidArgumentException |
|
| 2702 | + * @throws InvalidDataTypeException |
|
| 2703 | + * @throws InvalidInterfaceException |
|
| 2704 | + */ |
|
| 2705 | + protected function _category_details($view) |
|
| 2706 | + { |
|
| 2707 | + // load formatter helper |
|
| 2708 | + // load field generator helper |
|
| 2709 | + $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
| 2710 | + $this->_set_add_edit_form_tags($route); |
|
| 2711 | + $this->_set_category_object(); |
|
| 2712 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2713 | + $delete_action = 'delete_category'; |
|
| 2714 | + // custom redirect |
|
| 2715 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2716 | + ['action' => 'category_list'], |
|
| 2717 | + $this->_admin_base_url |
|
| 2718 | + ); |
|
| 2719 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2720 | + // take care of contents |
|
| 2721 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2722 | + $this->display_admin_page_with_sidebar(); |
|
| 2723 | + } |
|
| 2724 | + |
|
| 2725 | + |
|
| 2726 | + /** |
|
| 2727 | + * Output category details content. |
|
| 2728 | + * |
|
| 2729 | + * @throws DomainException |
|
| 2730 | + */ |
|
| 2731 | + protected function _category_details_content() |
|
| 2732 | + { |
|
| 2733 | + $editor_args['category_desc'] = [ |
|
| 2734 | + 'type' => 'wp_editor', |
|
| 2735 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2736 | + 'class' => 'my_editor_custom', |
|
| 2737 | + 'wpeditor_args' => ['media_buttons' => false], |
|
| 2738 | + ]; |
|
| 2739 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2740 | + $all_terms = get_terms( |
|
| 2741 | + [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2742 | + ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2743 | + ); |
|
| 2744 | + // setup category select for term parents. |
|
| 2745 | + $category_select_values[] = [ |
|
| 2746 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2747 | + 'id' => 0, |
|
| 2748 | + ]; |
|
| 2749 | + foreach ($all_terms as $term) { |
|
| 2750 | + $category_select_values[] = [ |
|
| 2751 | + 'text' => $term->name, |
|
| 2752 | + 'id' => $term->term_id, |
|
| 2753 | + ]; |
|
| 2754 | + } |
|
| 2755 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2756 | + 'category_parent', |
|
| 2757 | + $category_select_values, |
|
| 2758 | + $this->_category->parent |
|
| 2759 | + ); |
|
| 2760 | + $template_args = [ |
|
| 2761 | + 'category' => $this->_category, |
|
| 2762 | + 'category_select' => $category_select, |
|
| 2763 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2764 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2765 | + 'disable' => '', |
|
| 2766 | + 'disabled_message' => false, |
|
| 2767 | + ]; |
|
| 2768 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2769 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2770 | + } |
|
| 2771 | + |
|
| 2772 | + |
|
| 2773 | + /** |
|
| 2774 | + * Handles deleting categories. |
|
| 2775 | + */ |
|
| 2776 | + protected function _delete_categories() |
|
| 2777 | + { |
|
| 2778 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2779 | + : (array) $this->_req_data['category_id']; |
|
| 2780 | + foreach ($cat_ids as $cat_id) { |
|
| 2781 | + $this->_delete_category($cat_id); |
|
| 2782 | + } |
|
| 2783 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2784 | + $query_args = [ |
|
| 2785 | + 'action' => 'category_list', |
|
| 2786 | + ]; |
|
| 2787 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2788 | + } |
|
| 2789 | + |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * Handles deleting specific category. |
|
| 2793 | + * |
|
| 2794 | + * @param int $cat_id |
|
| 2795 | + */ |
|
| 2796 | + protected function _delete_category($cat_id) |
|
| 2797 | + { |
|
| 2798 | + $cat_id = absint($cat_id); |
|
| 2799 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2800 | + } |
|
| 2801 | + |
|
| 2802 | + |
|
| 2803 | + /** |
|
| 2804 | + * Handles triggering the update or insertion of a new category. |
|
| 2805 | + * |
|
| 2806 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2807 | + * @throws EE_Error |
|
| 2808 | + * @throws InvalidArgumentException |
|
| 2809 | + * @throws InvalidDataTypeException |
|
| 2810 | + * @throws InvalidInterfaceException |
|
| 2811 | + */ |
|
| 2812 | + protected function _insert_or_update_category($new_category) |
|
| 2813 | + { |
|
| 2814 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2815 | + $success = 0; // we already have a success message so lets not send another. |
|
| 2816 | + if ($cat_id) { |
|
| 2817 | + $query_args = [ |
|
| 2818 | + 'action' => 'edit_category', |
|
| 2819 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2820 | + ]; |
|
| 2821 | + } else { |
|
| 2822 | + $query_args = ['action' => 'add_category']; |
|
| 2823 | + } |
|
| 2824 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2825 | + } |
|
| 2826 | + |
|
| 2827 | + |
|
| 2828 | + /** |
|
| 2829 | + * Inserts or updates category |
|
| 2830 | + * |
|
| 2831 | + * @param bool $update (true indicates we're updating a category). |
|
| 2832 | + * @return bool|mixed|string |
|
| 2833 | + */ |
|
| 2834 | + private function _insert_category($update = false) |
|
| 2835 | + { |
|
| 2836 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2837 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2838 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2839 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2840 | + if (empty($category_name)) { |
|
| 2841 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2842 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2843 | + return false; |
|
| 2844 | + } |
|
| 2845 | + $term_args = [ |
|
| 2846 | + 'name' => $category_name, |
|
| 2847 | + 'description' => $category_desc, |
|
| 2848 | + 'parent' => $category_parent, |
|
| 2849 | + ]; |
|
| 2850 | + // was the category_identifier input disabled? |
|
| 2851 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2852 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2853 | + } |
|
| 2854 | + $insert_ids = $update |
|
| 2855 | + ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2856 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2857 | + if (! is_array($insert_ids)) { |
|
| 2858 | + $msg = esc_html__( |
|
| 2859 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2860 | + 'event_espresso' |
|
| 2861 | + ); |
|
| 2862 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2863 | + } else { |
|
| 2864 | + $cat_id = $insert_ids['term_id']; |
|
| 2865 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2866 | + EE_Error::add_success($msg); |
|
| 2867 | + } |
|
| 2868 | + return $cat_id; |
|
| 2869 | + } |
|
| 2870 | + |
|
| 2871 | + |
|
| 2872 | + /** |
|
| 2873 | + * Gets categories or count of categories matching the arguments in the request. |
|
| 2874 | + * |
|
| 2875 | + * @param int $per_page |
|
| 2876 | + * @param int $current_page |
|
| 2877 | + * @param bool $count |
|
| 2878 | + * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
| 2879 | + * @throws EE_Error |
|
| 2880 | + * @throws InvalidArgumentException |
|
| 2881 | + * @throws InvalidDataTypeException |
|
| 2882 | + * @throws InvalidInterfaceException |
|
| 2883 | + */ |
|
| 2884 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2885 | + { |
|
| 2886 | + // testing term stuff |
|
| 2887 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2888 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2889 | + $limit = ($current_page - 1) * $per_page; |
|
| 2890 | + $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2891 | + if (isset($this->_req_data['s'])) { |
|
| 2892 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2893 | + $where['OR'] = [ |
|
| 2894 | + 'Term.name' => ['LIKE', $sstr], |
|
| 2895 | + 'description' => ['LIKE', $sstr], |
|
| 2896 | + ]; |
|
| 2897 | + } |
|
| 2898 | + $query_params = [ |
|
| 2899 | + $where, |
|
| 2900 | + 'order_by' => [$orderby => $order], |
|
| 2901 | + 'limit' => $limit . ',' . $per_page, |
|
| 2902 | + 'force_join' => ['Term'], |
|
| 2903 | + ]; |
|
| 2904 | + $categories = $count |
|
| 2905 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2906 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2907 | + return $categories; |
|
| 2908 | + } |
|
| 2909 | + |
|
| 2910 | + /* end category stuff */ |
|
| 2911 | + /**************/ |
|
| 2912 | + |
|
| 2913 | + |
|
| 2914 | + /** |
|
| 2915 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2916 | + * |
|
| 2917 | + * @throws EE_Error |
|
| 2918 | + * @throws InvalidArgumentException |
|
| 2919 | + * @throws InvalidDataTypeException |
|
| 2920 | + * @throws InvalidInterfaceException |
|
| 2921 | + */ |
|
| 2922 | + public function save_timezonestring_setting() |
|
| 2923 | + { |
|
| 2924 | + $timezone_string = isset($this->_req_data['timezone_selected']) |
|
| 2925 | + ? $this->_req_data['timezone_selected'] |
|
| 2926 | + : ''; |
|
| 2927 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2928 | + EE_Error::add_error( |
|
| 2929 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2930 | + __FILE__, |
|
| 2931 | + __FUNCTION__, |
|
| 2932 | + __LINE__ |
|
| 2933 | + ); |
|
| 2934 | + $this->_template_args['error'] = true; |
|
| 2935 | + $this->_return_json(); |
|
| 2936 | + } |
|
| 2937 | + |
|
| 2938 | + update_option('timezone_string', $timezone_string); |
|
| 2939 | + EE_Error::add_success( |
|
| 2940 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2941 | + ); |
|
| 2942 | + $this->_template_args['success'] = true; |
|
| 2943 | + $this->_return_json(true, ['action' => 'create_new']); |
|
| 2944 | + } |
|
| 2945 | 2945 | } |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | ]; |
| 512 | 512 | // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated |
| 513 | 513 | $domain = $this->loader->getShared('EventEspresso\core\domain\Domain'); |
| 514 | - if (! $domain->isCaffeinated()) { |
|
| 514 | + if ( ! $domain->isCaffeinated()) { |
|
| 515 | 515 | $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
| 516 | 516 | $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
| 517 | 517 | } |
@@ -570,13 +570,13 @@ discard block |
||
| 570 | 570 | { |
| 571 | 571 | wp_register_style( |
| 572 | 572 | 'events-admin-css', |
| 573 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 573 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 574 | 574 | [], |
| 575 | 575 | EVENT_ESPRESSO_VERSION |
| 576 | 576 | ); |
| 577 | 577 | wp_register_style( |
| 578 | 578 | 'ee-cat-admin', |
| 579 | - EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 579 | + EVENTS_ASSETS_URL.'ee-cat-admin.css', |
|
| 580 | 580 | [], |
| 581 | 581 | EVENT_ESPRESSO_VERSION |
| 582 | 582 | ); |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | // scripts |
| 586 | 586 | wp_register_script( |
| 587 | 587 | 'event_editor_js', |
| 588 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 588 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 589 | 589 | ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
| 590 | 590 | EVENT_ESPRESSO_VERSION, |
| 591 | 591 | true |
@@ -611,16 +611,16 @@ discard block |
||
| 611 | 611 | wp_enqueue_style('espresso-ui-theme'); |
| 612 | 612 | wp_register_style( |
| 613 | 613 | 'event-editor-css', |
| 614 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 614 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 615 | 615 | ['ee-admin-css'], |
| 616 | 616 | EVENT_ESPRESSO_VERSION |
| 617 | 617 | ); |
| 618 | 618 | wp_enqueue_style('event-editor-css'); |
| 619 | 619 | // scripts |
| 620 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 620 | + if ( ! $this->admin_config->useAdvancedEditor()) { |
|
| 621 | 621 | wp_register_script( |
| 622 | 622 | 'event-datetime-metabox', |
| 623 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 623 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 624 | 624 | ['event_editor_js', 'ee-datepicker'], |
| 625 | 625 | EVENT_ESPRESSO_VERSION |
| 626 | 626 | ); |
@@ -690,15 +690,15 @@ discard block |
||
| 690 | 690 | public function verify_event_edit($event = null, $req_type = '') |
| 691 | 691 | { |
| 692 | 692 | // don't need to do this when processing |
| 693 | - if (! empty($req_type)) { |
|
| 693 | + if ( ! empty($req_type)) { |
|
| 694 | 694 | return; |
| 695 | 695 | } |
| 696 | 696 | // no event? |
| 697 | - if (! $event instanceof EE_Event) { |
|
| 697 | + if ( ! $event instanceof EE_Event) { |
|
| 698 | 698 | $event = $this->_cpt_model_obj; |
| 699 | 699 | } |
| 700 | 700 | // STILL no event? |
| 701 | - if (! $event instanceof EE_Event) { |
|
| 701 | + if ( ! $event instanceof EE_Event) { |
|
| 702 | 702 | return; |
| 703 | 703 | } |
| 704 | 704 | $orig_status = $event->status(); |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | ); |
| 739 | 739 | } |
| 740 | 740 | // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
| 741 | - if (! $event->tickets_on_sale()) { |
|
| 741 | + if ( ! $event->tickets_on_sale()) { |
|
| 742 | 742 | return; |
| 743 | 743 | } |
| 744 | 744 | // made it here so show warning |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | { |
| 785 | 785 | $has_timezone_string = get_option('timezone_string'); |
| 786 | 786 | // only nag them about setting their timezone if it's their first event, and they haven't already done it |
| 787 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 787 | + if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 788 | 788 | EE_Error::add_attention( |
| 789 | 789 | sprintf( |
| 790 | 790 | __( |
@@ -868,31 +868,31 @@ discard block |
||
| 868 | 868 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 869 | 869 | $statuses = [ |
| 870 | 870 | 'sold_out_status' => [ |
| 871 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 871 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
| 872 | 872 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 873 | 873 | ], |
| 874 | 874 | 'active_status' => [ |
| 875 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 875 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
| 876 | 876 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 877 | 877 | ], |
| 878 | 878 | 'upcoming_status' => [ |
| 879 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 879 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
| 880 | 880 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 881 | 881 | ], |
| 882 | 882 | 'postponed_status' => [ |
| 883 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 883 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
| 884 | 884 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 885 | 885 | ], |
| 886 | 886 | 'cancelled_status' => [ |
| 887 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 887 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
| 888 | 888 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 889 | 889 | ], |
| 890 | 890 | 'expired_status' => [ |
| 891 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 891 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
| 892 | 892 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 893 | 893 | ], |
| 894 | 894 | 'inactive_status' => [ |
| 895 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 895 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
| 896 | 896 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 897 | 897 | ], |
| 898 | 898 | ]; |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | */ |
| 908 | 908 | private function eventModel() |
| 909 | 909 | { |
| 910 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 910 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 911 | 911 | $this->_event_model = EEM_Event::instance(); |
| 912 | 912 | } |
| 913 | 913 | return $this->_event_model; |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | */ |
| 922 | 922 | private function datetimeModel($event_timezone_string = '') |
| 923 | 923 | { |
| 924 | - if (! $this->datetime_model instanceof EEM_Datetime) { |
|
| 924 | + if ( ! $this->datetime_model instanceof EEM_Datetime) { |
|
| 925 | 925 | $this->datetime_model = EEM_Datetime::instance($event_timezone_string); |
| 926 | 926 | } |
| 927 | 927 | return $this->datetime_model; |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | */ |
| 936 | 936 | private function ticketModel($event_timezone_string = '') |
| 937 | 937 | { |
| 938 | - if (! $this->ticket_model instanceof EEM_Ticket) { |
|
| 938 | + if ( ! $this->ticket_model instanceof EEM_Ticket) { |
|
| 939 | 939 | $this->ticket_model = EEM_Ticket::instance($event_timezone_string); |
| 940 | 940 | } |
| 941 | 941 | return $this->ticket_model; |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
| 956 | 956 | { |
| 957 | 957 | // make sure this is only when editing |
| 958 | - if (! empty($id)) { |
|
| 958 | + if ( ! empty($id)) { |
|
| 959 | 959 | $post = get_post($id); |
| 960 | 960 | $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
| 961 | 961 | . esc_html__('Shortcode', 'event_espresso') |
@@ -993,7 +993,7 @@ discard block |
||
| 993 | 993 | 'button' |
| 994 | 994 | ); |
| 995 | 995 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
| 996 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 996 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 997 | 997 | 'create_new', |
| 998 | 998 | 'add', |
| 999 | 999 | [], |
@@ -1056,7 +1056,7 @@ discard block |
||
| 1056 | 1056 | /** @var FeatureFlags $flags */ |
| 1057 | 1057 | $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags'); |
| 1058 | 1058 | // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
| 1059 | - if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1059 | + if ( ! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1060 | 1060 | $event_values['EVT_display_ticket_selector'] = |
| 1061 | 1061 | ! empty($this->_req_data['display_ticket_selector']) |
| 1062 | 1062 | ? 1 |
@@ -1169,7 +1169,7 @@ discard block |
||
| 1169 | 1169 | */ |
| 1170 | 1170 | protected function _default_venue_update(EE_Event $evtobj, $data) |
| 1171 | 1171 | { |
| 1172 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1172 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1173 | 1173 | $venue_model = EEM_Venue::instance(); |
| 1174 | 1174 | $rows_affected = null; |
| 1175 | 1175 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | 'status' => 'publish', |
| 1201 | 1201 | ]; |
| 1202 | 1202 | // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
| 1203 | - if (! empty($venue_id)) { |
|
| 1203 | + if ( ! empty($venue_id)) { |
|
| 1204 | 1204 | $update_where = [$venue_model->primary_key_name() => $venue_id]; |
| 1205 | 1205 | $rows_affected = $venue_model->update($venue_array, [$update_where]); |
| 1206 | 1206 | // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
@@ -1254,7 +1254,7 @@ discard block |
||
| 1254 | 1254 | 'DTT_order' => $row, |
| 1255 | 1255 | ]; |
| 1256 | 1256 | // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
| 1257 | - if (! empty($dtt['DTT_ID'])) { |
|
| 1257 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1258 | 1258 | $DTM = $this->datetimeModel($event_timezone_string)->get_one_by_ID($dtt['DTT_ID']); |
| 1259 | 1259 | $DTM->set_date_format($incoming_date_formats[0]); |
| 1260 | 1260 | $DTM->set_time_format($incoming_date_formats[1]); |
@@ -1262,7 +1262,7 @@ discard block |
||
| 1262 | 1262 | $DTM->set($field, $value); |
| 1263 | 1263 | } |
| 1264 | 1264 | // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
| 1265 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1265 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1266 | 1266 | } else { |
| 1267 | 1267 | $DTM = EE_Registry::instance()->load_class( |
| 1268 | 1268 | 'Datetime', |
@@ -1295,12 +1295,12 @@ discard block |
||
| 1295 | 1295 | foreach ($data['edit_tickets'] as $row => $tkt) { |
| 1296 | 1296 | $incoming_date_formats = ['Y-m-d', 'h:i a']; |
| 1297 | 1297 | $update_prices = false; |
| 1298 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1299 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
| 1298 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1299 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1300 | 1300 | // trim inputs to ensure any excess whitespace is removed. |
| 1301 | 1301 | $tkt = array_map('trim', $tkt); |
| 1302 | 1302 | if (empty($tkt['TKT_start_date'])) { |
| 1303 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1303 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | if (empty($tkt['TKT_end_date'])) { |
| 1306 | 1306 | // use the start date of the first datetime |
@@ -1335,7 +1335,7 @@ discard block |
||
| 1335 | 1335 | // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
| 1336 | 1336 | // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
| 1337 | 1337 | // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
| 1338 | - if (! empty($tkt['TKT_ID'])) { |
|
| 1338 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1339 | 1339 | $TKT = $this->ticketModel($event_timezone_string)->get_one_by_ID($tkt['TKT_ID']); |
| 1340 | 1340 | if ($TKT instanceof EE_Ticket) { |
| 1341 | 1341 | $ticket_sold = $TKT->count_related( |
@@ -1374,7 +1374,7 @@ discard block |
||
| 1374 | 1374 | $TKT->set('TKT_deleted', 1); |
| 1375 | 1375 | $TKT->save(); |
| 1376 | 1376 | // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
| 1377 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1377 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1378 | 1378 | // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
| 1379 | 1379 | $TKT = clone $TKT; |
| 1380 | 1380 | $TKT->set('TKT_ID', 0); |
@@ -1419,9 +1419,9 @@ discard block |
||
| 1419 | 1419 | } |
| 1420 | 1420 | // initially let's add the ticket to the dtt |
| 1421 | 1421 | $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
| 1422 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1422 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1423 | 1423 | // add prices to ticket |
| 1424 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1424 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1425 | 1425 | } |
| 1426 | 1426 | // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
| 1427 | 1427 | $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
@@ -1589,7 +1589,7 @@ discard block |
||
| 1589 | 1589 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1590 | 1590 | // load template |
| 1591 | 1591 | EEH_Template::display_template( |
| 1592 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1592 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1593 | 1593 | $publish_box_extra_args |
| 1594 | 1594 | ); |
| 1595 | 1595 | } |
@@ -1625,7 +1625,7 @@ discard block |
||
| 1625 | 1625 | /** @var FeatureFlags $flags */ |
| 1626 | 1626 | $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags'); |
| 1627 | 1627 | // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
| 1628 | - if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1628 | + if ( ! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) { |
|
| 1629 | 1629 | add_meta_box( |
| 1630 | 1630 | 'espresso_event_editor_event_options', |
| 1631 | 1631 | esc_html__('Event Registration Options', 'event_espresso'), |
@@ -1634,7 +1634,7 @@ discard block |
||
| 1634 | 1634 | 'side' |
| 1635 | 1635 | ); |
| 1636 | 1636 | } |
| 1637 | - if (! $use_advanced_editor) { |
|
| 1637 | + if ( ! $use_advanced_editor) { |
|
| 1638 | 1638 | add_meta_box( |
| 1639 | 1639 | 'espresso_event_editor_tickets', |
| 1640 | 1640 | esc_html__('Event Datetime & Ticket', 'event_espresso'), |
@@ -1647,7 +1647,7 @@ discard block |
||
| 1647 | 1647 | if ($flags->featureAllowed('use_reg_options_meta_box')) { |
| 1648 | 1648 | add_action( |
| 1649 | 1649 | 'add_meta_boxes_espresso_events', |
| 1650 | - function () { |
|
| 1650 | + function() { |
|
| 1651 | 1651 | global $current_screen; |
| 1652 | 1652 | remove_meta_box('authordiv', $current_screen, 'normal'); |
| 1653 | 1653 | }, |
@@ -1712,7 +1712,7 @@ discard block |
||
| 1712 | 1712 | 'default_where_conditions' => 'none', |
| 1713 | 1713 | ] |
| 1714 | 1714 | ); |
| 1715 | - if (! empty($related_tickets)) { |
|
| 1715 | + if ( ! empty($related_tickets)) { |
|
| 1716 | 1716 | $template_args['total_ticket_rows'] = count($related_tickets); |
| 1717 | 1717 | $row = 0; |
| 1718 | 1718 | foreach ($related_tickets as $ticket) { |
@@ -1746,7 +1746,7 @@ discard block |
||
| 1746 | 1746 | ); |
| 1747 | 1747 | $template = apply_filters( |
| 1748 | 1748 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1749 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1749 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1750 | 1750 | ); |
| 1751 | 1751 | EEH_Template::display_template($template, $template_args); |
| 1752 | 1752 | } |
@@ -1770,7 +1770,7 @@ discard block |
||
| 1770 | 1770 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1771 | 1771 | { |
| 1772 | 1772 | $template_args = [ |
| 1773 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1773 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1774 | 1774 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1775 | 1775 | : '', |
| 1776 | 1776 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1782,10 +1782,10 @@ discard block |
||
| 1782 | 1782 | 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
| 1783 | 1783 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
| 1784 | 1784 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
| 1785 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1786 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1785 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1786 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1787 | 1787 | ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
| 1788 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1788 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1789 | 1789 | : ' disabled=disabled', |
| 1790 | 1790 | ]; |
| 1791 | 1791 | $price = $ticket->ID() !== 0 |
@@ -1812,7 +1812,7 @@ discard block |
||
| 1812 | 1812 | ['order_by' => ['DTT_EVT_start' => 'ASC']] |
| 1813 | 1813 | ) |
| 1814 | 1814 | : null; |
| 1815 | - if (! empty($earliest_dtt)) { |
|
| 1815 | + if ( ! empty($earliest_dtt)) { |
|
| 1816 | 1816 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
| 1817 | 1817 | } else { |
| 1818 | 1818 | $template_args['TKT_end_date'] = date( |
@@ -1824,7 +1824,7 @@ discard block |
||
| 1824 | 1824 | $template_args = array_merge($template_args, $price_args); |
| 1825 | 1825 | $template = apply_filters( |
| 1826 | 1826 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1827 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1827 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1828 | 1828 | $ticket |
| 1829 | 1829 | ); |
| 1830 | 1830 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1879,7 +1879,7 @@ discard block |
||
| 1879 | 1879 | $default_reg_status_values |
| 1880 | 1880 | ); |
| 1881 | 1881 | EEH_Template::display_template( |
| 1882 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1882 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1883 | 1883 | $template_args |
| 1884 | 1884 | ); |
| 1885 | 1885 | } |
@@ -1909,7 +1909,7 @@ discard block |
||
| 1909 | 1909 | { |
| 1910 | 1910 | $EEME = $this->eventModel(); |
| 1911 | 1911 | $offset = ($current_page - 1) * $per_page; |
| 1912 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1912 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1913 | 1913 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
| 1914 | 1914 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
| 1915 | 1915 | if (isset($this->_req_data['month_range'])) { |
@@ -1938,7 +1938,7 @@ discard block |
||
| 1938 | 1938 | // categories? |
| 1939 | 1939 | $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
| 1940 | 1940 | ? $this->_req_data['EVT_CAT'] : null; |
| 1941 | - if (! empty($category)) { |
|
| 1941 | + if ( ! empty($category)) { |
|
| 1942 | 1942 | $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
| 1943 | 1943 | $where['Term_Taxonomy.term_id'] = $category; |
| 1944 | 1944 | } |
@@ -1946,7 +1946,7 @@ discard block |
||
| 1946 | 1946 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1947 | 1947 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
| 1948 | 1948 | $DateTime = new DateTime( |
| 1949 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1949 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1950 | 1950 | new DateTimeZone('UTC') |
| 1951 | 1951 | ); |
| 1952 | 1952 | $start = $DateTime->getTimestamp(); |
@@ -1972,7 +1972,7 @@ discard block |
||
| 1972 | 1972 | ->format(implode(' ', $start_formats)); |
| 1973 | 1973 | $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
| 1974 | 1974 | } |
| 1975 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1975 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1976 | 1976 | $where['EVT_wp_user'] = get_current_user_id(); |
| 1977 | 1977 | } elseif ( |
| 1978 | 1978 | ! isset($where['status']) |
@@ -1996,7 +1996,7 @@ discard block |
||
| 1996 | 1996 | } |
| 1997 | 1997 | // search query handling |
| 1998 | 1998 | if (isset($this->_req_data['s'])) { |
| 1999 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1999 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 2000 | 2000 | $where['OR'] = [ |
| 2001 | 2001 | 'EVT_name' => ['LIKE', $search_string], |
| 2002 | 2002 | 'EVT_desc' => ['LIKE', $search_string], |
@@ -2111,7 +2111,7 @@ discard block |
||
| 2111 | 2111 | // clean status |
| 2112 | 2112 | $event_status = sanitize_key($event_status); |
| 2113 | 2113 | // grab status |
| 2114 | - if (! empty($event_status)) { |
|
| 2114 | + if ( ! empty($event_status)) { |
|
| 2115 | 2115 | $success = $this->_change_event_status($EVT_ID, $event_status); |
| 2116 | 2116 | } else { |
| 2117 | 2117 | $success = false; |
@@ -2153,7 +2153,7 @@ discard block |
||
| 2153 | 2153 | // clean status |
| 2154 | 2154 | $event_status = sanitize_key($event_status); |
| 2155 | 2155 | // grab status |
| 2156 | - if (! empty($event_status)) { |
|
| 2156 | + if ( ! empty($event_status)) { |
|
| 2157 | 2157 | $success = true; |
| 2158 | 2158 | // determine the event id and set to array. |
| 2159 | 2159 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []; |
@@ -2205,7 +2205,7 @@ discard block |
||
| 2205 | 2205 | private function _change_event_status($EVT_ID = 0, $event_status = '') |
| 2206 | 2206 | { |
| 2207 | 2207 | // grab event id |
| 2208 | - if (! $EVT_ID) { |
|
| 2208 | + if ( ! $EVT_ID) { |
|
| 2209 | 2209 | $msg = esc_html__( |
| 2210 | 2210 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
| 2211 | 2211 | 'event_espresso' |
@@ -2276,8 +2276,8 @@ discard block |
||
| 2276 | 2276 | // get list of events with no prices |
| 2277 | 2277 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []); |
| 2278 | 2278 | // remove this event from the list of events with no prices |
| 2279 | - if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
| 2280 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2279 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2280 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2281 | 2281 | } |
| 2282 | 2282 | update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
| 2283 | 2283 | } else { |
@@ -2324,7 +2324,7 @@ discard block |
||
| 2324 | 2324 | $results = $this->_permanently_delete_event($EVT_ID); |
| 2325 | 2325 | $success = $results !== false ? $success : false; |
| 2326 | 2326 | // remove this event from the list of events with no prices |
| 2327 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
| 2327 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2328 | 2328 | } else { |
| 2329 | 2329 | $success = false; |
| 2330 | 2330 | $msg = esc_html__( |
@@ -2356,7 +2356,7 @@ discard block |
||
| 2356 | 2356 | private function _permanently_delete_event($EVT_ID = 0) |
| 2357 | 2357 | { |
| 2358 | 2358 | // grab event id |
| 2359 | - if (! $EVT_ID) { |
|
| 2359 | + if ( ! $EVT_ID) { |
|
| 2360 | 2360 | $msg = esc_html__( |
| 2361 | 2361 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
| 2362 | 2362 | 'event_espresso' |
@@ -2370,7 +2370,7 @@ discard block |
||
| 2370 | 2370 | ) { |
| 2371 | 2371 | $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
| 2372 | 2372 | } |
| 2373 | - if (! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2373 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2374 | 2374 | return false; |
| 2375 | 2375 | } |
| 2376 | 2376 | // need to delete related tickets and prices first. |
@@ -2392,7 +2392,7 @@ discard block |
||
| 2392 | 2392 | } |
| 2393 | 2393 | // any attached question groups? |
| 2394 | 2394 | $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
| 2395 | - if (! empty($question_groups)) { |
|
| 2395 | + if ( ! empty($question_groups)) { |
|
| 2396 | 2396 | foreach ($question_groups as $question_group) { |
| 2397 | 2397 | $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
| 2398 | 2398 | } |
@@ -2625,7 +2625,7 @@ discard block |
||
| 2625 | 2625 | . esc_html__( |
| 2626 | 2626 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
| 2627 | 2627 | 'event_espresso' |
| 2628 | - ) . '</strong>'; |
|
| 2628 | + ).'</strong>'; |
|
| 2629 | 2629 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2630 | 2630 | } |
| 2631 | 2631 | |
@@ -2645,12 +2645,12 @@ discard block |
||
| 2645 | 2645 | // set default category object |
| 2646 | 2646 | $this->_set_empty_category_object(); |
| 2647 | 2647 | // only set if we've got an id |
| 2648 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2648 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2649 | 2649 | return; |
| 2650 | 2650 | } |
| 2651 | 2651 | $category_id = absint($this->_req_data['EVT_CAT_ID']); |
| 2652 | 2652 | $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
| 2653 | - if (! empty($term)) { |
|
| 2653 | + if ( ! empty($term)) { |
|
| 2654 | 2654 | $this->_category->category_name = $term->name; |
| 2655 | 2655 | $this->_category->category_identifier = $term->slug; |
| 2656 | 2656 | $this->_category->category_desc = $term->description; |
@@ -2682,7 +2682,7 @@ discard block |
||
| 2682 | 2682 | { |
| 2683 | 2683 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2684 | 2684 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
| 2685 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2685 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 2686 | 2686 | 'add_category', |
| 2687 | 2687 | 'add_category', |
| 2688 | 2688 | [], |
@@ -2765,7 +2765,7 @@ discard block |
||
| 2765 | 2765 | 'disable' => '', |
| 2766 | 2766 | 'disabled_message' => false, |
| 2767 | 2767 | ]; |
| 2768 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2768 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2769 | 2769 | return EEH_Template::display_template($template, $template_args, true); |
| 2770 | 2770 | } |
| 2771 | 2771 | |
@@ -2854,7 +2854,7 @@ discard block |
||
| 2854 | 2854 | $insert_ids = $update |
| 2855 | 2855 | ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
| 2856 | 2856 | : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
| 2857 | - if (! is_array($insert_ids)) { |
|
| 2857 | + if ( ! is_array($insert_ids)) { |
|
| 2858 | 2858 | $msg = esc_html__( |
| 2859 | 2859 | 'An error occurred and the category has not been saved to the database.', |
| 2860 | 2860 | 'event_espresso' |
@@ -2889,7 +2889,7 @@ discard block |
||
| 2889 | 2889 | $limit = ($current_page - 1) * $per_page; |
| 2890 | 2890 | $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
| 2891 | 2891 | if (isset($this->_req_data['s'])) { |
| 2892 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2892 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2893 | 2893 | $where['OR'] = [ |
| 2894 | 2894 | 'Term.name' => ['LIKE', $sstr], |
| 2895 | 2895 | 'description' => ['LIKE', $sstr], |
@@ -2898,7 +2898,7 @@ discard block |
||
| 2898 | 2898 | $query_params = [ |
| 2899 | 2899 | $where, |
| 2900 | 2900 | 'order_by' => [$orderby => $order], |
| 2901 | - 'limit' => $limit . ',' . $per_page, |
|
| 2901 | + 'limit' => $limit.','.$per_page, |
|
| 2902 | 2902 | 'force_join' => ['Term'], |
| 2903 | 2903 | ]; |
| 2904 | 2904 | $categories = $count |
@@ -21,172 +21,172 @@ |
||
| 21 | 21 | class RouteHandler |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var JsonDataNodeHandler $data_node_handler |
|
| 26 | - */ |
|
| 27 | - private $data_node_handler; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var LoaderInterface $loader |
|
| 31 | - */ |
|
| 32 | - private $loader; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var RequestInterface $request |
|
| 36 | - */ |
|
| 37 | - protected $request; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var RouteCollection $routes |
|
| 41 | - */ |
|
| 42 | - private $routes; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var boolean $print_data_nodes |
|
| 46 | - */ |
|
| 47 | - private $print_data_nodes = true; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var string $route_request_type |
|
| 51 | - */ |
|
| 52 | - protected $route_request_type = ''; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * RouteHandler constructor. |
|
| 57 | - * |
|
| 58 | - * @param JsonDataNodeHandler $data_node_handler |
|
| 59 | - * @param LoaderInterface $loader |
|
| 60 | - * @param RequestInterface $request |
|
| 61 | - * @param RouteCollection $routes |
|
| 62 | - */ |
|
| 63 | - public function __construct( |
|
| 64 | - JsonDataNodeHandler $data_node_handler, |
|
| 65 | - LoaderInterface $loader, |
|
| 66 | - RequestInterface $request, |
|
| 67 | - RouteCollection $routes |
|
| 68 | - ) { |
|
| 69 | - $this->data_node_handler = $data_node_handler; |
|
| 70 | - $this->loader = $loader; |
|
| 71 | - $this->request = $request; |
|
| 72 | - $this->routes = $routes; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param string $fqcn Fully Qualified Class Name for Route |
|
| 78 | - * @param bool $handle if true [default] will immediately call RouteInterface::handleRequest() after adding |
|
| 79 | - * @throws Exception |
|
| 80 | - */ |
|
| 81 | - public function addRoute(string $fqcn, bool $handle = true) |
|
| 82 | - { |
|
| 83 | - try { |
|
| 84 | - $route = $this->loader->getShared($fqcn); |
|
| 85 | - $this->validateRoute($route, $fqcn); |
|
| 86 | - $this->routes->add($route); |
|
| 87 | - $this->handle($route, $handle); |
|
| 88 | - } catch (Exception $exception) { |
|
| 89 | - new ExceptionStackTraceDisplay( |
|
| 90 | - new DomainException( |
|
| 91 | - sprintf( |
|
| 92 | - esc_html__( |
|
| 93 | - 'The following error occurred while trying to handle the "%1$s" route:%2$s%3$s', |
|
| 94 | - 'event_espresso' |
|
| 95 | - ), |
|
| 96 | - $fqcn, |
|
| 97 | - '<br />', |
|
| 98 | - $exception->getMessage() |
|
| 99 | - ) |
|
| 100 | - ) |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function getRouteRequestType(): string |
|
| 110 | - { |
|
| 111 | - return $this->route_request_type; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param string $route_request_type |
|
| 117 | - */ |
|
| 118 | - public function setRouteRequestType(string $route_request_type = '') |
|
| 119 | - { |
|
| 120 | - $this->route_request_type = ! empty($route_request_type) ? $route_request_type : $this->route_request_type; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param RouteInterface $route |
|
| 126 | - * @param bool $handle if true [default] will immediately call RouteInterface::handleRequest() |
|
| 127 | - */ |
|
| 128 | - public function handle(RouteInterface $route, bool $handle = true) |
|
| 129 | - { |
|
| 130 | - if ($handle && $route->isNotHandled()) { |
|
| 131 | - $route->handleRequest(); |
|
| 132 | - if ($route instanceof PrimaryRoute) { |
|
| 133 | - $this->setRouteRequestType($route->getRouteRequestType()); |
|
| 134 | - } |
|
| 135 | - $data_node = $route->dataNode(); |
|
| 136 | - if ($data_node instanceof JsonDataNode) { |
|
| 137 | - $this->data_node_handler->addDataNode($data_node); |
|
| 138 | - $this->printDataNodes(); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * calls RouteInterface::handleRequest() on all Routes that |
|
| 146 | - * - match current request |
|
| 147 | - * - have yet to be handled |
|
| 148 | - * |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public function handleRoutesForCurrentRequest() |
|
| 152 | - { |
|
| 153 | - $this->routes->handleRoutesForCurrentRequest(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return void |
|
| 159 | - */ |
|
| 160 | - private function printDataNodes() |
|
| 161 | - { |
|
| 162 | - if ($this->print_data_nodes) { |
|
| 163 | - add_action('admin_footer', [$this->data_node_handler, 'printDataNode'], 0); |
|
| 164 | - add_action('wp_footer', [$this->data_node_handler, 'printDataNode'], 0); |
|
| 165 | - $this->print_data_nodes = false; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param RouteInterface $route |
|
| 172 | - * @param string $fqcn |
|
| 173 | - */ |
|
| 174 | - private function validateRoute(RouteInterface $route, string $fqcn) |
|
| 175 | - { |
|
| 176 | - if (! $route instanceof RouteInterface) { |
|
| 177 | - throw new InvalidClassException( |
|
| 178 | - sprintf( |
|
| 179 | - /* |
|
| 24 | + /** |
|
| 25 | + * @var JsonDataNodeHandler $data_node_handler |
|
| 26 | + */ |
|
| 27 | + private $data_node_handler; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var LoaderInterface $loader |
|
| 31 | + */ |
|
| 32 | + private $loader; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var RequestInterface $request |
|
| 36 | + */ |
|
| 37 | + protected $request; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var RouteCollection $routes |
|
| 41 | + */ |
|
| 42 | + private $routes; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var boolean $print_data_nodes |
|
| 46 | + */ |
|
| 47 | + private $print_data_nodes = true; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var string $route_request_type |
|
| 51 | + */ |
|
| 52 | + protected $route_request_type = ''; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * RouteHandler constructor. |
|
| 57 | + * |
|
| 58 | + * @param JsonDataNodeHandler $data_node_handler |
|
| 59 | + * @param LoaderInterface $loader |
|
| 60 | + * @param RequestInterface $request |
|
| 61 | + * @param RouteCollection $routes |
|
| 62 | + */ |
|
| 63 | + public function __construct( |
|
| 64 | + JsonDataNodeHandler $data_node_handler, |
|
| 65 | + LoaderInterface $loader, |
|
| 66 | + RequestInterface $request, |
|
| 67 | + RouteCollection $routes |
|
| 68 | + ) { |
|
| 69 | + $this->data_node_handler = $data_node_handler; |
|
| 70 | + $this->loader = $loader; |
|
| 71 | + $this->request = $request; |
|
| 72 | + $this->routes = $routes; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param string $fqcn Fully Qualified Class Name for Route |
|
| 78 | + * @param bool $handle if true [default] will immediately call RouteInterface::handleRequest() after adding |
|
| 79 | + * @throws Exception |
|
| 80 | + */ |
|
| 81 | + public function addRoute(string $fqcn, bool $handle = true) |
|
| 82 | + { |
|
| 83 | + try { |
|
| 84 | + $route = $this->loader->getShared($fqcn); |
|
| 85 | + $this->validateRoute($route, $fqcn); |
|
| 86 | + $this->routes->add($route); |
|
| 87 | + $this->handle($route, $handle); |
|
| 88 | + } catch (Exception $exception) { |
|
| 89 | + new ExceptionStackTraceDisplay( |
|
| 90 | + new DomainException( |
|
| 91 | + sprintf( |
|
| 92 | + esc_html__( |
|
| 93 | + 'The following error occurred while trying to handle the "%1$s" route:%2$s%3$s', |
|
| 94 | + 'event_espresso' |
|
| 95 | + ), |
|
| 96 | + $fqcn, |
|
| 97 | + '<br />', |
|
| 98 | + $exception->getMessage() |
|
| 99 | + ) |
|
| 100 | + ) |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function getRouteRequestType(): string |
|
| 110 | + { |
|
| 111 | + return $this->route_request_type; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param string $route_request_type |
|
| 117 | + */ |
|
| 118 | + public function setRouteRequestType(string $route_request_type = '') |
|
| 119 | + { |
|
| 120 | + $this->route_request_type = ! empty($route_request_type) ? $route_request_type : $this->route_request_type; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param RouteInterface $route |
|
| 126 | + * @param bool $handle if true [default] will immediately call RouteInterface::handleRequest() |
|
| 127 | + */ |
|
| 128 | + public function handle(RouteInterface $route, bool $handle = true) |
|
| 129 | + { |
|
| 130 | + if ($handle && $route->isNotHandled()) { |
|
| 131 | + $route->handleRequest(); |
|
| 132 | + if ($route instanceof PrimaryRoute) { |
|
| 133 | + $this->setRouteRequestType($route->getRouteRequestType()); |
|
| 134 | + } |
|
| 135 | + $data_node = $route->dataNode(); |
|
| 136 | + if ($data_node instanceof JsonDataNode) { |
|
| 137 | + $this->data_node_handler->addDataNode($data_node); |
|
| 138 | + $this->printDataNodes(); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * calls RouteInterface::handleRequest() on all Routes that |
|
| 146 | + * - match current request |
|
| 147 | + * - have yet to be handled |
|
| 148 | + * |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public function handleRoutesForCurrentRequest() |
|
| 152 | + { |
|
| 153 | + $this->routes->handleRoutesForCurrentRequest(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return void |
|
| 159 | + */ |
|
| 160 | + private function printDataNodes() |
|
| 161 | + { |
|
| 162 | + if ($this->print_data_nodes) { |
|
| 163 | + add_action('admin_footer', [$this->data_node_handler, 'printDataNode'], 0); |
|
| 164 | + add_action('wp_footer', [$this->data_node_handler, 'printDataNode'], 0); |
|
| 165 | + $this->print_data_nodes = false; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param RouteInterface $route |
|
| 172 | + * @param string $fqcn |
|
| 173 | + */ |
|
| 174 | + private function validateRoute(RouteInterface $route, string $fqcn) |
|
| 175 | + { |
|
| 176 | + if (! $route instanceof RouteInterface) { |
|
| 177 | + throw new InvalidClassException( |
|
| 178 | + sprintf( |
|
| 179 | + /* |
|
| 180 | 180 | * translators: |
| 181 | 181 | * The supplied FQCN (Fully\Qualified\Class\Name) must be an instance of RouteInterface. |
| 182 | 182 | */ |
| 183 | - esc_html__( |
|
| 184 | - 'The supplied FQCN (%1$s) must be an instance of RouteInterface.', |
|
| 185 | - 'event_espresso' |
|
| 186 | - ), |
|
| 187 | - $fqcn |
|
| 188 | - ) |
|
| 189 | - ); |
|
| 190 | - } |
|
| 191 | - } |
|
| 183 | + esc_html__( |
|
| 184 | + 'The supplied FQCN (%1$s) must be an instance of RouteInterface.', |
|
| 185 | + 'event_espresso' |
|
| 186 | + ), |
|
| 187 | + $fqcn |
|
| 188 | + ) |
|
| 189 | + ); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | 192 | } |
@@ -17,705 +17,705 @@ |
||
| 17 | 17 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * $_GET parameters |
|
| 22 | - * |
|
| 23 | - * @var array $get |
|
| 24 | - */ |
|
| 25 | - private $get; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * $_POST parameters |
|
| 29 | - * |
|
| 30 | - * @var array $post |
|
| 31 | - */ |
|
| 32 | - private $post; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * $_COOKIE parameters |
|
| 36 | - * |
|
| 37 | - * @var array $cookie |
|
| 38 | - */ |
|
| 39 | - private $cookie; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * $_SERVER parameters |
|
| 43 | - * |
|
| 44 | - * @var array $server |
|
| 45 | - */ |
|
| 46 | - private $server; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * $_FILES parameters |
|
| 50 | - * |
|
| 51 | - * @var array $files |
|
| 52 | - */ |
|
| 53 | - private $files; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * $_REQUEST parameters |
|
| 57 | - * |
|
| 58 | - * @var array $request |
|
| 59 | - */ |
|
| 60 | - private $request; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var RequestTypeContextCheckerInterface |
|
| 64 | - */ |
|
| 65 | - private $request_type; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * IP address for request |
|
| 69 | - * |
|
| 70 | - * @var string $ip_address |
|
| 71 | - */ |
|
| 72 | - private $ip_address; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @var string $user_agent |
|
| 76 | - */ |
|
| 77 | - private $user_agent; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * true if current user appears to be some kind of bot |
|
| 81 | - * |
|
| 82 | - * @var bool $is_bot |
|
| 83 | - */ |
|
| 84 | - private $is_bot; |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param array $get |
|
| 89 | - * @param array $post |
|
| 90 | - * @param array $cookie |
|
| 91 | - * @param array $server |
|
| 92 | - * @param array $files |
|
| 93 | - */ |
|
| 94 | - public function __construct(array $get, array $post, array $cookie, array $server, array $files = array()) |
|
| 95 | - { |
|
| 96 | - // grab request vars |
|
| 97 | - $this->get = $get; |
|
| 98 | - $this->post = $post; |
|
| 99 | - $this->cookie = $cookie; |
|
| 100 | - $this->server = $server; |
|
| 101 | - $this->files = $files; |
|
| 102 | - $this->request = array_merge($this->get, $this->post); |
|
| 103 | - $this->ip_address = $this->visitorIp(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param RequestTypeContextCheckerInterface $type |
|
| 109 | - */ |
|
| 110 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
| 111 | - { |
|
| 112 | - $this->request_type = $type; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @return array |
|
| 118 | - */ |
|
| 119 | - public function getParams() |
|
| 120 | - { |
|
| 121 | - return $this->get; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - public function postParams() |
|
| 129 | - { |
|
| 130 | - return $this->post; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return array |
|
| 136 | - */ |
|
| 137 | - public function cookieParams() |
|
| 138 | - { |
|
| 139 | - return $this->cookie; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return array |
|
| 145 | - */ |
|
| 146 | - public function serverParams() |
|
| 147 | - { |
|
| 148 | - return $this->server; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function filesParams() |
|
| 156 | - { |
|
| 157 | - return $this->files; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * returns contents of $_REQUEST |
|
| 163 | - * |
|
| 164 | - * @return array |
|
| 165 | - */ |
|
| 166 | - public function requestParams() |
|
| 167 | - { |
|
| 168 | - return $this->request; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @param $key |
|
| 174 | - * @param $value |
|
| 175 | - * @param bool $override_ee |
|
| 176 | - * @return void |
|
| 177 | - */ |
|
| 178 | - public function setRequestParam($key, $value, $override_ee = false) |
|
| 179 | - { |
|
| 180 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 181 | - if ($key !== 'ee' || empty($this->request['ee']) || $override_ee) { |
|
| 182 | - $this->request[ $key ] = $value; |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * returns the value for a request param if the given key exists |
|
| 189 | - * |
|
| 190 | - * @param $key |
|
| 191 | - * @param null $default |
|
| 192 | - * @return mixed |
|
| 193 | - */ |
|
| 194 | - public function getRequestParam($key, $default = null) |
|
| 195 | - { |
|
| 196 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * check if param exists |
|
| 202 | - * |
|
| 203 | - * @param $key |
|
| 204 | - * @return bool |
|
| 205 | - */ |
|
| 206 | - public function requestParamIsSet($key) |
|
| 207 | - { |
|
| 208 | - return $this->requestParameterDrillDown($key); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 214 | - * and return the value for the first match found |
|
| 215 | - * wildcards can be either of the following: |
|
| 216 | - * ? to represent a single character of any type |
|
| 217 | - * * to represent one or more characters of any type |
|
| 218 | - * |
|
| 219 | - * @param string $pattern |
|
| 220 | - * @param null|mixed $default |
|
| 221 | - * @return mixed |
|
| 222 | - */ |
|
| 223 | - public function getMatch($pattern, $default = null) |
|
| 224 | - { |
|
| 225 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 231 | - * wildcards can be either of the following: |
|
| 232 | - * ? to represent a single character of any type |
|
| 233 | - * * to represent one or more characters of any type |
|
| 234 | - * returns true if a match is found or false if not |
|
| 235 | - * |
|
| 236 | - * @param string $pattern |
|
| 237 | - * @return bool |
|
| 238 | - */ |
|
| 239 | - public function matches($pattern) |
|
| 240 | - { |
|
| 241 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
| 247 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
| 248 | - * and used to search through the current request's parameter keys |
|
| 249 | - * @param array $request_params The array of request parameters to search through |
|
| 250 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
| 251 | - * Default is null |
|
| 252 | - * @param string $return [optional] Controls what kind of value is returned. |
|
| 253 | - * Options are: |
|
| 254 | - * 'bool' will return true or false if match is found or not |
|
| 255 | - * 'key' will return the first key found that matches the supplied pattern |
|
| 256 | - * 'value' will return the value for the first request parameter |
|
| 257 | - * whose key matches the supplied pattern |
|
| 258 | - * Default is 'value' |
|
| 259 | - * @return boolean|string |
|
| 260 | - */ |
|
| 261 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
| 262 | - { |
|
| 263 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
| 264 | - ? $return |
|
| 265 | - : 'is_set'; |
|
| 266 | - // replace wildcard chars with regex chars |
|
| 267 | - $pattern = str_replace( |
|
| 268 | - array("\*", "\?"), |
|
| 269 | - array('.*', '.'), |
|
| 270 | - preg_quote($pattern, '/') |
|
| 271 | - ); |
|
| 272 | - foreach ($request_params as $key => $request_param) { |
|
| 273 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 274 | - // return value for request param |
|
| 275 | - if ($return === 'value') { |
|
| 276 | - return $request_params[ $key ]; |
|
| 277 | - } |
|
| 278 | - // or actual key or true just to indicate it was found |
|
| 279 | - return $return === 'key' ? $key : true; |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - // match not found so return default value or false |
|
| 283 | - return $return === 'value' ? $default : false; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 289 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 290 | - * by using square brackets to surround keys for deeper array elements. |
|
| 291 | - * For example : |
|
| 292 | - * if the supplied $key was: "first[second][third]" |
|
| 293 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
| 294 | - * Given the following request parameters: |
|
| 295 | - * array( |
|
| 296 | - * 'first' => array( |
|
| 297 | - * 'second' => array( |
|
| 298 | - * 'third' => 'has a value' |
|
| 299 | - * ) |
|
| 300 | - * ) |
|
| 301 | - * ) |
|
| 302 | - * would return true if default parameters were set |
|
| 303 | - * |
|
| 304 | - * @param string $callback |
|
| 305 | - * @param $key |
|
| 306 | - * @param null $default |
|
| 307 | - * @param array $request_params |
|
| 308 | - * @return bool|mixed|null |
|
| 309 | - */ |
|
| 310 | - private function requestParameterDrillDown( |
|
| 311 | - $key, |
|
| 312 | - $default = null, |
|
| 313 | - $callback = 'is_set', |
|
| 314 | - array $request_params = array() |
|
| 315 | - ) { |
|
| 316 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
| 317 | - ? $callback |
|
| 318 | - : 'is_set'; |
|
| 319 | - $request_params = ! empty($request_params) |
|
| 320 | - ? $request_params |
|
| 321 | - : $this->request; |
|
| 322 | - // does incoming key represent an array like 'first[second][third]' ? |
|
| 323 | - if (strpos($key, '[') !== false) { |
|
| 324 | - // turn it into an actual array |
|
| 325 | - $key = str_replace(']', '', $key); |
|
| 326 | - $keys = explode('[', $key); |
|
| 327 | - $key = array_shift($keys); |
|
| 328 | - if ($callback === 'match') { |
|
| 329 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
| 330 | - $key = $real_key ? $real_key : $key; |
|
| 331 | - } |
|
| 332 | - // check if top level key exists |
|
| 333 | - if (isset($request_params[ $key ])) { |
|
| 334 | - // build a new key to pass along like: 'second[third]' |
|
| 335 | - // or just 'second' depending on depth of keys |
|
| 336 | - $key_string = array_shift($keys); |
|
| 337 | - if (! empty($keys)) { |
|
| 338 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 339 | - } |
|
| 340 | - return $this->requestParameterDrillDown( |
|
| 341 | - $key_string, |
|
| 342 | - $default, |
|
| 343 | - $callback, |
|
| 344 | - $request_params[ $key ] |
|
| 345 | - ); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - if ($callback === 'is_set') { |
|
| 349 | - return isset($request_params[ $key ]); |
|
| 350 | - } |
|
| 351 | - if ($callback === 'match') { |
|
| 352 | - return $this->match($key, $request_params, $default); |
|
| 353 | - } |
|
| 354 | - return isset($request_params[ $key ]) |
|
| 355 | - ? $request_params[ $key ] |
|
| 356 | - : $default; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * remove param |
|
| 362 | - * |
|
| 363 | - * @param $key |
|
| 364 | - * @param bool $unset_from_global_too |
|
| 365 | - */ |
|
| 366 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 367 | - { |
|
| 368 | - // because unset may not actually remove var |
|
| 369 | - $this->request[ $key ] = null; |
|
| 370 | - unset($this->request[ $key ]); |
|
| 371 | - if ($unset_from_global_too) { |
|
| 372 | - unset($_REQUEST[ $key ]); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * remove params |
|
| 379 | - * |
|
| 380 | - * @param array $keys |
|
| 381 | - * @param bool $unset_from_global_too |
|
| 382 | - */ |
|
| 383 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
| 384 | - { |
|
| 385 | - foreach ($keys as $key) { |
|
| 386 | - $this->unSetRequestParam($key, $unset_from_global_too); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @return string |
|
| 393 | - */ |
|
| 394 | - public function ipAddress() |
|
| 395 | - { |
|
| 396 | - return $this->ip_address; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * attempt to get IP address of current visitor from server |
|
| 402 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
| 403 | - * |
|
| 404 | - * @access public |
|
| 405 | - * @return string |
|
| 406 | - */ |
|
| 407 | - private function visitorIp() |
|
| 408 | - { |
|
| 409 | - $visitor_ip = '0.0.0.0'; |
|
| 410 | - $server_keys = array( |
|
| 411 | - 'HTTP_CLIENT_IP', |
|
| 412 | - 'HTTP_X_FORWARDED_FOR', |
|
| 413 | - 'HTTP_X_FORWARDED', |
|
| 414 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 415 | - 'HTTP_FORWARDED_FOR', |
|
| 416 | - 'HTTP_FORWARDED', |
|
| 417 | - 'REMOTE_ADDR', |
|
| 418 | - ); |
|
| 419 | - foreach ($server_keys as $key) { |
|
| 420 | - if (isset($this->server[ $key ])) { |
|
| 421 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
| 422 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
| 423 | - $visitor_ip = $ip; |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - return $visitor_ip; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
| 434 | - * |
|
| 435 | - * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
| 436 | - * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
| 437 | - * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
| 438 | - * @param boolean $remove_query_params whether or not to return the uri with all query params removed. |
|
| 439 | - * @return string |
|
| 440 | - */ |
|
| 441 | - public function requestUri($relativeToWpRoot = false, $remove_query_params = false) |
|
| 442 | - { |
|
| 443 | - $request_uri = filter_input( |
|
| 444 | - INPUT_SERVER, |
|
| 445 | - 'REQUEST_URI', |
|
| 446 | - FILTER_SANITIZE_URL, |
|
| 447 | - FILTER_NULL_ON_FAILURE |
|
| 448 | - ); |
|
| 449 | - if (empty($request_uri)) { |
|
| 450 | - // fallback sanitization if the above fails |
|
| 451 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
| 452 | - } |
|
| 453 | - if ($remove_query_params) { |
|
| 454 | - $request_uri_parts = explode('?', $request_uri); |
|
| 455 | - $request_uri = reset($request_uri_parts); |
|
| 456 | - } |
|
| 457 | - if ($relativeToWpRoot) { |
|
| 458 | - $home_path = untrailingslashit( |
|
| 459 | - parse_url( |
|
| 460 | - home_url(), |
|
| 461 | - PHP_URL_PATH |
|
| 462 | - ) |
|
| 463 | - ); |
|
| 464 | - $request_uri = str_replace( |
|
| 465 | - $home_path, |
|
| 466 | - '', |
|
| 467 | - $request_uri |
|
| 468 | - ); |
|
| 469 | - } |
|
| 470 | - return $request_uri; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * @return string |
|
| 475 | - */ |
|
| 476 | - public function userAgent() |
|
| 477 | - { |
|
| 478 | - return $this->user_agent; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * @param string $user_agent |
|
| 484 | - */ |
|
| 485 | - public function setUserAgent($user_agent = '') |
|
| 486 | - { |
|
| 487 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
| 488 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
| 489 | - } |
|
| 490 | - $this->user_agent = $user_agent; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * @return bool |
|
| 496 | - */ |
|
| 497 | - public function isBot() |
|
| 498 | - { |
|
| 499 | - return $this->is_bot; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * @param bool $is_bot |
|
| 505 | - */ |
|
| 506 | - public function setIsBot($is_bot) |
|
| 507 | - { |
|
| 508 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * @return bool |
|
| 514 | - */ |
|
| 515 | - public function isActivation() |
|
| 516 | - { |
|
| 517 | - return $this->request_type->isActivation(); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @param $is_activation |
|
| 523 | - * @return bool |
|
| 524 | - */ |
|
| 525 | - public function setIsActivation($is_activation) |
|
| 526 | - { |
|
| 527 | - return $this->request_type->setIsActivation($is_activation); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * @return bool |
|
| 533 | - */ |
|
| 534 | - public function isAdmin() |
|
| 535 | - { |
|
| 536 | - return $this->request_type->isAdmin(); |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * @return bool |
|
| 542 | - */ |
|
| 543 | - public function isAdminAjax() |
|
| 544 | - { |
|
| 545 | - return $this->request_type->isAdminAjax(); |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * @return bool |
|
| 551 | - */ |
|
| 552 | - public function isAjax() |
|
| 553 | - { |
|
| 554 | - return $this->request_type->isAjax(); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * @return bool |
|
| 560 | - */ |
|
| 561 | - public function isEeAjax() |
|
| 562 | - { |
|
| 563 | - return $this->request_type->isEeAjax(); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * @return bool |
|
| 569 | - */ |
|
| 570 | - public function isOtherAjax() |
|
| 571 | - { |
|
| 572 | - return $this->request_type->isOtherAjax(); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * @return bool |
|
| 578 | - */ |
|
| 579 | - public function isApi() |
|
| 580 | - { |
|
| 581 | - return $this->request_type->isApi(); |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * @return bool |
|
| 587 | - */ |
|
| 588 | - public function isCli() |
|
| 589 | - { |
|
| 590 | - return $this->request_type->isCli(); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * @return bool |
|
| 596 | - */ |
|
| 597 | - public function isCron() |
|
| 598 | - { |
|
| 599 | - return $this->request_type->isCron(); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * @return bool |
|
| 605 | - */ |
|
| 606 | - public function isFeed() |
|
| 607 | - { |
|
| 608 | - return $this->request_type->isFeed(); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * @return bool |
|
| 614 | - */ |
|
| 615 | - public function isFrontend() |
|
| 616 | - { |
|
| 617 | - return $this->request_type->isFrontend(); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @return bool |
|
| 623 | - */ |
|
| 624 | - public function isFrontAjax() |
|
| 625 | - { |
|
| 626 | - return $this->request_type->isFrontAjax(); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * @return bool |
|
| 632 | - */ |
|
| 633 | - public function isGQL() |
|
| 634 | - { |
|
| 635 | - return $this->request_type->isGQL(); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * @return bool |
|
| 641 | - */ |
|
| 642 | - public function isIframe() |
|
| 643 | - { |
|
| 644 | - return $this->request_type->isIframe(); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * @return bool |
|
| 651 | - */ |
|
| 652 | - public function isUnitTesting() |
|
| 653 | - { |
|
| 654 | - return $this->request_type->isUnitTesting(); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * @return bool |
|
| 660 | - */ |
|
| 661 | - public function isWordPressApi() |
|
| 662 | - { |
|
| 663 | - return $this->request_type->isWordPressApi(); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * @return bool |
|
| 670 | - */ |
|
| 671 | - public function isWordPressHeartbeat() |
|
| 672 | - { |
|
| 673 | - return $this->request_type->isWordPressHeartbeat(); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * @return bool |
|
| 680 | - */ |
|
| 681 | - public function isWordPressScrape() |
|
| 682 | - { |
|
| 683 | - return $this->request_type->isWordPressScrape(); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * @return string |
|
| 689 | - */ |
|
| 690 | - public function slug() |
|
| 691 | - { |
|
| 692 | - return $this->request_type->slug(); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed |
|
| 698 | - * |
|
| 699 | - * @return string |
|
| 700 | - * @since $VID:$ |
|
| 701 | - */ |
|
| 702 | - public function requestPath() |
|
| 703 | - { |
|
| 704 | - return $this->requestUri(true, true); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * returns true if the last segment of the current request path (without params) matches the provided string |
|
| 710 | - * |
|
| 711 | - * @param string $uri_segment |
|
| 712 | - * @return bool |
|
| 713 | - * @since $VID:$ |
|
| 714 | - */ |
|
| 715 | - public function currentPageIs($uri_segment) |
|
| 716 | - { |
|
| 717 | - $request_path = $this->requestPath(); |
|
| 718 | - $current_page = explode('/', $request_path); |
|
| 719 | - return end($current_page) === $uri_segment; |
|
| 720 | - } |
|
| 20 | + /** |
|
| 21 | + * $_GET parameters |
|
| 22 | + * |
|
| 23 | + * @var array $get |
|
| 24 | + */ |
|
| 25 | + private $get; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * $_POST parameters |
|
| 29 | + * |
|
| 30 | + * @var array $post |
|
| 31 | + */ |
|
| 32 | + private $post; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * $_COOKIE parameters |
|
| 36 | + * |
|
| 37 | + * @var array $cookie |
|
| 38 | + */ |
|
| 39 | + private $cookie; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * $_SERVER parameters |
|
| 43 | + * |
|
| 44 | + * @var array $server |
|
| 45 | + */ |
|
| 46 | + private $server; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * $_FILES parameters |
|
| 50 | + * |
|
| 51 | + * @var array $files |
|
| 52 | + */ |
|
| 53 | + private $files; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * $_REQUEST parameters |
|
| 57 | + * |
|
| 58 | + * @var array $request |
|
| 59 | + */ |
|
| 60 | + private $request; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var RequestTypeContextCheckerInterface |
|
| 64 | + */ |
|
| 65 | + private $request_type; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * IP address for request |
|
| 69 | + * |
|
| 70 | + * @var string $ip_address |
|
| 71 | + */ |
|
| 72 | + private $ip_address; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @var string $user_agent |
|
| 76 | + */ |
|
| 77 | + private $user_agent; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * true if current user appears to be some kind of bot |
|
| 81 | + * |
|
| 82 | + * @var bool $is_bot |
|
| 83 | + */ |
|
| 84 | + private $is_bot; |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param array $get |
|
| 89 | + * @param array $post |
|
| 90 | + * @param array $cookie |
|
| 91 | + * @param array $server |
|
| 92 | + * @param array $files |
|
| 93 | + */ |
|
| 94 | + public function __construct(array $get, array $post, array $cookie, array $server, array $files = array()) |
|
| 95 | + { |
|
| 96 | + // grab request vars |
|
| 97 | + $this->get = $get; |
|
| 98 | + $this->post = $post; |
|
| 99 | + $this->cookie = $cookie; |
|
| 100 | + $this->server = $server; |
|
| 101 | + $this->files = $files; |
|
| 102 | + $this->request = array_merge($this->get, $this->post); |
|
| 103 | + $this->ip_address = $this->visitorIp(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param RequestTypeContextCheckerInterface $type |
|
| 109 | + */ |
|
| 110 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
| 111 | + { |
|
| 112 | + $this->request_type = $type; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @return array |
|
| 118 | + */ |
|
| 119 | + public function getParams() |
|
| 120 | + { |
|
| 121 | + return $this->get; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + public function postParams() |
|
| 129 | + { |
|
| 130 | + return $this->post; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return array |
|
| 136 | + */ |
|
| 137 | + public function cookieParams() |
|
| 138 | + { |
|
| 139 | + return $this->cookie; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return array |
|
| 145 | + */ |
|
| 146 | + public function serverParams() |
|
| 147 | + { |
|
| 148 | + return $this->server; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function filesParams() |
|
| 156 | + { |
|
| 157 | + return $this->files; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * returns contents of $_REQUEST |
|
| 163 | + * |
|
| 164 | + * @return array |
|
| 165 | + */ |
|
| 166 | + public function requestParams() |
|
| 167 | + { |
|
| 168 | + return $this->request; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @param $key |
|
| 174 | + * @param $value |
|
| 175 | + * @param bool $override_ee |
|
| 176 | + * @return void |
|
| 177 | + */ |
|
| 178 | + public function setRequestParam($key, $value, $override_ee = false) |
|
| 179 | + { |
|
| 180 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 181 | + if ($key !== 'ee' || empty($this->request['ee']) || $override_ee) { |
|
| 182 | + $this->request[ $key ] = $value; |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * returns the value for a request param if the given key exists |
|
| 189 | + * |
|
| 190 | + * @param $key |
|
| 191 | + * @param null $default |
|
| 192 | + * @return mixed |
|
| 193 | + */ |
|
| 194 | + public function getRequestParam($key, $default = null) |
|
| 195 | + { |
|
| 196 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * check if param exists |
|
| 202 | + * |
|
| 203 | + * @param $key |
|
| 204 | + * @return bool |
|
| 205 | + */ |
|
| 206 | + public function requestParamIsSet($key) |
|
| 207 | + { |
|
| 208 | + return $this->requestParameterDrillDown($key); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 214 | + * and return the value for the first match found |
|
| 215 | + * wildcards can be either of the following: |
|
| 216 | + * ? to represent a single character of any type |
|
| 217 | + * * to represent one or more characters of any type |
|
| 218 | + * |
|
| 219 | + * @param string $pattern |
|
| 220 | + * @param null|mixed $default |
|
| 221 | + * @return mixed |
|
| 222 | + */ |
|
| 223 | + public function getMatch($pattern, $default = null) |
|
| 224 | + { |
|
| 225 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 231 | + * wildcards can be either of the following: |
|
| 232 | + * ? to represent a single character of any type |
|
| 233 | + * * to represent one or more characters of any type |
|
| 234 | + * returns true if a match is found or false if not |
|
| 235 | + * |
|
| 236 | + * @param string $pattern |
|
| 237 | + * @return bool |
|
| 238 | + */ |
|
| 239 | + public function matches($pattern) |
|
| 240 | + { |
|
| 241 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
| 247 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
| 248 | + * and used to search through the current request's parameter keys |
|
| 249 | + * @param array $request_params The array of request parameters to search through |
|
| 250 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
| 251 | + * Default is null |
|
| 252 | + * @param string $return [optional] Controls what kind of value is returned. |
|
| 253 | + * Options are: |
|
| 254 | + * 'bool' will return true or false if match is found or not |
|
| 255 | + * 'key' will return the first key found that matches the supplied pattern |
|
| 256 | + * 'value' will return the value for the first request parameter |
|
| 257 | + * whose key matches the supplied pattern |
|
| 258 | + * Default is 'value' |
|
| 259 | + * @return boolean|string |
|
| 260 | + */ |
|
| 261 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
| 262 | + { |
|
| 263 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
| 264 | + ? $return |
|
| 265 | + : 'is_set'; |
|
| 266 | + // replace wildcard chars with regex chars |
|
| 267 | + $pattern = str_replace( |
|
| 268 | + array("\*", "\?"), |
|
| 269 | + array('.*', '.'), |
|
| 270 | + preg_quote($pattern, '/') |
|
| 271 | + ); |
|
| 272 | + foreach ($request_params as $key => $request_param) { |
|
| 273 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 274 | + // return value for request param |
|
| 275 | + if ($return === 'value') { |
|
| 276 | + return $request_params[ $key ]; |
|
| 277 | + } |
|
| 278 | + // or actual key or true just to indicate it was found |
|
| 279 | + return $return === 'key' ? $key : true; |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + // match not found so return default value or false |
|
| 283 | + return $return === 'value' ? $default : false; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 289 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 290 | + * by using square brackets to surround keys for deeper array elements. |
|
| 291 | + * For example : |
|
| 292 | + * if the supplied $key was: "first[second][third]" |
|
| 293 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
| 294 | + * Given the following request parameters: |
|
| 295 | + * array( |
|
| 296 | + * 'first' => array( |
|
| 297 | + * 'second' => array( |
|
| 298 | + * 'third' => 'has a value' |
|
| 299 | + * ) |
|
| 300 | + * ) |
|
| 301 | + * ) |
|
| 302 | + * would return true if default parameters were set |
|
| 303 | + * |
|
| 304 | + * @param string $callback |
|
| 305 | + * @param $key |
|
| 306 | + * @param null $default |
|
| 307 | + * @param array $request_params |
|
| 308 | + * @return bool|mixed|null |
|
| 309 | + */ |
|
| 310 | + private function requestParameterDrillDown( |
|
| 311 | + $key, |
|
| 312 | + $default = null, |
|
| 313 | + $callback = 'is_set', |
|
| 314 | + array $request_params = array() |
|
| 315 | + ) { |
|
| 316 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
| 317 | + ? $callback |
|
| 318 | + : 'is_set'; |
|
| 319 | + $request_params = ! empty($request_params) |
|
| 320 | + ? $request_params |
|
| 321 | + : $this->request; |
|
| 322 | + // does incoming key represent an array like 'first[second][third]' ? |
|
| 323 | + if (strpos($key, '[') !== false) { |
|
| 324 | + // turn it into an actual array |
|
| 325 | + $key = str_replace(']', '', $key); |
|
| 326 | + $keys = explode('[', $key); |
|
| 327 | + $key = array_shift($keys); |
|
| 328 | + if ($callback === 'match') { |
|
| 329 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
| 330 | + $key = $real_key ? $real_key : $key; |
|
| 331 | + } |
|
| 332 | + // check if top level key exists |
|
| 333 | + if (isset($request_params[ $key ])) { |
|
| 334 | + // build a new key to pass along like: 'second[third]' |
|
| 335 | + // or just 'second' depending on depth of keys |
|
| 336 | + $key_string = array_shift($keys); |
|
| 337 | + if (! empty($keys)) { |
|
| 338 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 339 | + } |
|
| 340 | + return $this->requestParameterDrillDown( |
|
| 341 | + $key_string, |
|
| 342 | + $default, |
|
| 343 | + $callback, |
|
| 344 | + $request_params[ $key ] |
|
| 345 | + ); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + if ($callback === 'is_set') { |
|
| 349 | + return isset($request_params[ $key ]); |
|
| 350 | + } |
|
| 351 | + if ($callback === 'match') { |
|
| 352 | + return $this->match($key, $request_params, $default); |
|
| 353 | + } |
|
| 354 | + return isset($request_params[ $key ]) |
|
| 355 | + ? $request_params[ $key ] |
|
| 356 | + : $default; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * remove param |
|
| 362 | + * |
|
| 363 | + * @param $key |
|
| 364 | + * @param bool $unset_from_global_too |
|
| 365 | + */ |
|
| 366 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 367 | + { |
|
| 368 | + // because unset may not actually remove var |
|
| 369 | + $this->request[ $key ] = null; |
|
| 370 | + unset($this->request[ $key ]); |
|
| 371 | + if ($unset_from_global_too) { |
|
| 372 | + unset($_REQUEST[ $key ]); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * remove params |
|
| 379 | + * |
|
| 380 | + * @param array $keys |
|
| 381 | + * @param bool $unset_from_global_too |
|
| 382 | + */ |
|
| 383 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
| 384 | + { |
|
| 385 | + foreach ($keys as $key) { |
|
| 386 | + $this->unSetRequestParam($key, $unset_from_global_too); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @return string |
|
| 393 | + */ |
|
| 394 | + public function ipAddress() |
|
| 395 | + { |
|
| 396 | + return $this->ip_address; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * attempt to get IP address of current visitor from server |
|
| 402 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
| 403 | + * |
|
| 404 | + * @access public |
|
| 405 | + * @return string |
|
| 406 | + */ |
|
| 407 | + private function visitorIp() |
|
| 408 | + { |
|
| 409 | + $visitor_ip = '0.0.0.0'; |
|
| 410 | + $server_keys = array( |
|
| 411 | + 'HTTP_CLIENT_IP', |
|
| 412 | + 'HTTP_X_FORWARDED_FOR', |
|
| 413 | + 'HTTP_X_FORWARDED', |
|
| 414 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 415 | + 'HTTP_FORWARDED_FOR', |
|
| 416 | + 'HTTP_FORWARDED', |
|
| 417 | + 'REMOTE_ADDR', |
|
| 418 | + ); |
|
| 419 | + foreach ($server_keys as $key) { |
|
| 420 | + if (isset($this->server[ $key ])) { |
|
| 421 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
| 422 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
| 423 | + $visitor_ip = $ip; |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + return $visitor_ip; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
| 434 | + * |
|
| 435 | + * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
| 436 | + * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
| 437 | + * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
| 438 | + * @param boolean $remove_query_params whether or not to return the uri with all query params removed. |
|
| 439 | + * @return string |
|
| 440 | + */ |
|
| 441 | + public function requestUri($relativeToWpRoot = false, $remove_query_params = false) |
|
| 442 | + { |
|
| 443 | + $request_uri = filter_input( |
|
| 444 | + INPUT_SERVER, |
|
| 445 | + 'REQUEST_URI', |
|
| 446 | + FILTER_SANITIZE_URL, |
|
| 447 | + FILTER_NULL_ON_FAILURE |
|
| 448 | + ); |
|
| 449 | + if (empty($request_uri)) { |
|
| 450 | + // fallback sanitization if the above fails |
|
| 451 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
| 452 | + } |
|
| 453 | + if ($remove_query_params) { |
|
| 454 | + $request_uri_parts = explode('?', $request_uri); |
|
| 455 | + $request_uri = reset($request_uri_parts); |
|
| 456 | + } |
|
| 457 | + if ($relativeToWpRoot) { |
|
| 458 | + $home_path = untrailingslashit( |
|
| 459 | + parse_url( |
|
| 460 | + home_url(), |
|
| 461 | + PHP_URL_PATH |
|
| 462 | + ) |
|
| 463 | + ); |
|
| 464 | + $request_uri = str_replace( |
|
| 465 | + $home_path, |
|
| 466 | + '', |
|
| 467 | + $request_uri |
|
| 468 | + ); |
|
| 469 | + } |
|
| 470 | + return $request_uri; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * @return string |
|
| 475 | + */ |
|
| 476 | + public function userAgent() |
|
| 477 | + { |
|
| 478 | + return $this->user_agent; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @param string $user_agent |
|
| 484 | + */ |
|
| 485 | + public function setUserAgent($user_agent = '') |
|
| 486 | + { |
|
| 487 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
| 488 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
| 489 | + } |
|
| 490 | + $this->user_agent = $user_agent; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * @return bool |
|
| 496 | + */ |
|
| 497 | + public function isBot() |
|
| 498 | + { |
|
| 499 | + return $this->is_bot; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * @param bool $is_bot |
|
| 505 | + */ |
|
| 506 | + public function setIsBot($is_bot) |
|
| 507 | + { |
|
| 508 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * @return bool |
|
| 514 | + */ |
|
| 515 | + public function isActivation() |
|
| 516 | + { |
|
| 517 | + return $this->request_type->isActivation(); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @param $is_activation |
|
| 523 | + * @return bool |
|
| 524 | + */ |
|
| 525 | + public function setIsActivation($is_activation) |
|
| 526 | + { |
|
| 527 | + return $this->request_type->setIsActivation($is_activation); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * @return bool |
|
| 533 | + */ |
|
| 534 | + public function isAdmin() |
|
| 535 | + { |
|
| 536 | + return $this->request_type->isAdmin(); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * @return bool |
|
| 542 | + */ |
|
| 543 | + public function isAdminAjax() |
|
| 544 | + { |
|
| 545 | + return $this->request_type->isAdminAjax(); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * @return bool |
|
| 551 | + */ |
|
| 552 | + public function isAjax() |
|
| 553 | + { |
|
| 554 | + return $this->request_type->isAjax(); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * @return bool |
|
| 560 | + */ |
|
| 561 | + public function isEeAjax() |
|
| 562 | + { |
|
| 563 | + return $this->request_type->isEeAjax(); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * @return bool |
|
| 569 | + */ |
|
| 570 | + public function isOtherAjax() |
|
| 571 | + { |
|
| 572 | + return $this->request_type->isOtherAjax(); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * @return bool |
|
| 578 | + */ |
|
| 579 | + public function isApi() |
|
| 580 | + { |
|
| 581 | + return $this->request_type->isApi(); |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * @return bool |
|
| 587 | + */ |
|
| 588 | + public function isCli() |
|
| 589 | + { |
|
| 590 | + return $this->request_type->isCli(); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * @return bool |
|
| 596 | + */ |
|
| 597 | + public function isCron() |
|
| 598 | + { |
|
| 599 | + return $this->request_type->isCron(); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * @return bool |
|
| 605 | + */ |
|
| 606 | + public function isFeed() |
|
| 607 | + { |
|
| 608 | + return $this->request_type->isFeed(); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * @return bool |
|
| 614 | + */ |
|
| 615 | + public function isFrontend() |
|
| 616 | + { |
|
| 617 | + return $this->request_type->isFrontend(); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @return bool |
|
| 623 | + */ |
|
| 624 | + public function isFrontAjax() |
|
| 625 | + { |
|
| 626 | + return $this->request_type->isFrontAjax(); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * @return bool |
|
| 632 | + */ |
|
| 633 | + public function isGQL() |
|
| 634 | + { |
|
| 635 | + return $this->request_type->isGQL(); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * @return bool |
|
| 641 | + */ |
|
| 642 | + public function isIframe() |
|
| 643 | + { |
|
| 644 | + return $this->request_type->isIframe(); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * @return bool |
|
| 651 | + */ |
|
| 652 | + public function isUnitTesting() |
|
| 653 | + { |
|
| 654 | + return $this->request_type->isUnitTesting(); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * @return bool |
|
| 660 | + */ |
|
| 661 | + public function isWordPressApi() |
|
| 662 | + { |
|
| 663 | + return $this->request_type->isWordPressApi(); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * @return bool |
|
| 670 | + */ |
|
| 671 | + public function isWordPressHeartbeat() |
|
| 672 | + { |
|
| 673 | + return $this->request_type->isWordPressHeartbeat(); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * @return bool |
|
| 680 | + */ |
|
| 681 | + public function isWordPressScrape() |
|
| 682 | + { |
|
| 683 | + return $this->request_type->isWordPressScrape(); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + |
|
| 687 | + /** |
|
| 688 | + * @return string |
|
| 689 | + */ |
|
| 690 | + public function slug() |
|
| 691 | + { |
|
| 692 | + return $this->request_type->slug(); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed |
|
| 698 | + * |
|
| 699 | + * @return string |
|
| 700 | + * @since $VID:$ |
|
| 701 | + */ |
|
| 702 | + public function requestPath() |
|
| 703 | + { |
|
| 704 | + return $this->requestUri(true, true); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * returns true if the last segment of the current request path (without params) matches the provided string |
|
| 710 | + * |
|
| 711 | + * @param string $uri_segment |
|
| 712 | + * @return bool |
|
| 713 | + * @since $VID:$ |
|
| 714 | + */ |
|
| 715 | + public function currentPageIs($uri_segment) |
|
| 716 | + { |
|
| 717 | + $request_path = $this->requestPath(); |
|
| 718 | + $current_page = explode('/', $request_path); |
|
| 719 | + return end($current_page) === $uri_segment; |
|
| 720 | + } |
|
| 721 | 721 | } |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | { |
| 180 | 180 | // don't allow "ee" to be overwritten unless explicitly instructed to do so |
| 181 | 181 | if ($key !== 'ee' || empty($this->request['ee']) || $override_ee) { |
| 182 | - $this->request[ $key ] = $value; |
|
| 182 | + $this->request[$key] = $value; |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
@@ -270,10 +270,10 @@ discard block |
||
| 270 | 270 | preg_quote($pattern, '/') |
| 271 | 271 | ); |
| 272 | 272 | foreach ($request_params as $key => $request_param) { |
| 273 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 273 | + if (preg_match('/^'.$pattern.'$/is', $key)) { |
|
| 274 | 274 | // return value for request param |
| 275 | 275 | if ($return === 'value') { |
| 276 | - return $request_params[ $key ]; |
|
| 276 | + return $request_params[$key]; |
|
| 277 | 277 | } |
| 278 | 278 | // or actual key or true just to indicate it was found |
| 279 | 279 | return $return === 'key' ? $key : true; |
@@ -330,29 +330,29 @@ discard block |
||
| 330 | 330 | $key = $real_key ? $real_key : $key; |
| 331 | 331 | } |
| 332 | 332 | // check if top level key exists |
| 333 | - if (isset($request_params[ $key ])) { |
|
| 333 | + if (isset($request_params[$key])) { |
|
| 334 | 334 | // build a new key to pass along like: 'second[third]' |
| 335 | 335 | // or just 'second' depending on depth of keys |
| 336 | 336 | $key_string = array_shift($keys); |
| 337 | - if (! empty($keys)) { |
|
| 338 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 337 | + if ( ! empty($keys)) { |
|
| 338 | + $key_string .= '['.implode('][', $keys).']'; |
|
| 339 | 339 | } |
| 340 | 340 | return $this->requestParameterDrillDown( |
| 341 | 341 | $key_string, |
| 342 | 342 | $default, |
| 343 | 343 | $callback, |
| 344 | - $request_params[ $key ] |
|
| 344 | + $request_params[$key] |
|
| 345 | 345 | ); |
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | if ($callback === 'is_set') { |
| 349 | - return isset($request_params[ $key ]); |
|
| 349 | + return isset($request_params[$key]); |
|
| 350 | 350 | } |
| 351 | 351 | if ($callback === 'match') { |
| 352 | 352 | return $this->match($key, $request_params, $default); |
| 353 | 353 | } |
| 354 | - return isset($request_params[ $key ]) |
|
| 355 | - ? $request_params[ $key ] |
|
| 354 | + return isset($request_params[$key]) |
|
| 355 | + ? $request_params[$key] |
|
| 356 | 356 | : $default; |
| 357 | 357 | } |
| 358 | 358 | |
@@ -366,10 +366,10 @@ discard block |
||
| 366 | 366 | public function unSetRequestParam($key, $unset_from_global_too = false) |
| 367 | 367 | { |
| 368 | 368 | // because unset may not actually remove var |
| 369 | - $this->request[ $key ] = null; |
|
| 370 | - unset($this->request[ $key ]); |
|
| 369 | + $this->request[$key] = null; |
|
| 370 | + unset($this->request[$key]); |
|
| 371 | 371 | if ($unset_from_global_too) { |
| 372 | - unset($_REQUEST[ $key ]); |
|
| 372 | + unset($_REQUEST[$key]); |
|
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
@@ -417,8 +417,8 @@ discard block |
||
| 417 | 417 | 'REMOTE_ADDR', |
| 418 | 418 | ); |
| 419 | 419 | foreach ($server_keys as $key) { |
| 420 | - if (isset($this->server[ $key ])) { |
|
| 421 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
| 420 | + if (isset($this->server[$key])) { |
|
| 421 | + foreach (array_map('trim', explode(',', $this->server[$key])) as $ip) { |
|
| 422 | 422 | if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
| 423 | 423 | $visitor_ip = $ip; |
| 424 | 424 | } |
@@ -16,175 +16,175 @@ |
||
| 16 | 16 | interface RequestInterface extends RequestTypeContextCheckerInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param RequestTypeContextCheckerInterface $type |
|
| 21 | - */ |
|
| 22 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @return array |
|
| 26 | - */ |
|
| 27 | - public function getParams(); |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @return array |
|
| 32 | - */ |
|
| 33 | - public function postParams(); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - public function cookieParams(); |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - public function serverParams(); |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function filesParams(); |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * returns contents of $_REQUEST |
|
| 56 | - * |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public function requestParams(); |
|
| 19 | + /** |
|
| 20 | + * @param RequestTypeContextCheckerInterface $type |
|
| 21 | + */ |
|
| 22 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @return array |
|
| 26 | + */ |
|
| 27 | + public function getParams(); |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @return array |
|
| 32 | + */ |
|
| 33 | + public function postParams(); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + public function cookieParams(); |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + public function serverParams(); |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function filesParams(); |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * returns contents of $_REQUEST |
|
| 56 | + * |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public function requestParams(); |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param string $key |
|
| 64 | - * @param string $value |
|
| 65 | - * @param bool $override_ee |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function setRequestParam($key, $value, $override_ee = false); |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * returns the value for a request param if the given key exists |
|
| 73 | - * |
|
| 74 | - * @param string $key |
|
| 75 | - * @param null $default |
|
| 76 | - * @return mixed |
|
| 77 | - */ |
|
| 78 | - public function getRequestParam($key, $default = null); |
|
| 62 | + /** |
|
| 63 | + * @param string $key |
|
| 64 | + * @param string $value |
|
| 65 | + * @param bool $override_ee |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function setRequestParam($key, $value, $override_ee = false); |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * returns the value for a request param if the given key exists |
|
| 73 | + * |
|
| 74 | + * @param string $key |
|
| 75 | + * @param null $default |
|
| 76 | + * @return mixed |
|
| 77 | + */ |
|
| 78 | + public function getRequestParam($key, $default = null); |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * check if param exists |
|
| 83 | - * |
|
| 84 | - * @param string $key |
|
| 85 | - * @return bool |
|
| 86 | - */ |
|
| 87 | - public function requestParamIsSet($key); |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 92 | - * and return the value for the first match found |
|
| 93 | - * wildcards can be either of the following: |
|
| 94 | - * ? to represent a single character of any type |
|
| 95 | - * * to represent one or more characters of any type |
|
| 96 | - * |
|
| 97 | - * @param string $pattern |
|
| 98 | - * @param null|mixed $default |
|
| 99 | - * @return false|int |
|
| 100 | - */ |
|
| 101 | - public function getMatch($pattern, $default = null); |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 106 | - * wildcards can be either of the following: |
|
| 107 | - * ? to represent a single character of any type |
|
| 108 | - * * to represent one or more characters of any type |
|
| 109 | - * returns true if a match is found or false if not |
|
| 110 | - * |
|
| 111 | - * @param string $pattern |
|
| 112 | - * @return false|int |
|
| 113 | - */ |
|
| 114 | - public function matches($pattern); |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * remove param |
|
| 119 | - * |
|
| 120 | - * @param string $key |
|
| 121 | - * @param bool $unset_from_global_too |
|
| 122 | - */ |
|
| 123 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * remove params |
|
| 128 | - * |
|
| 129 | - * @param array $keys |
|
| 130 | - * @param bool $unset_from_global_too |
|
| 131 | - */ |
|
| 132 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @return string |
|
| 137 | - */ |
|
| 138 | - public function ipAddress(); |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param boolean $relativeToWpRoot whether or not to return the uri relative to WordPress' home URL. |
|
| 143 | - * @param boolean $remove_query_params whether or not to return the uri with all query params removed. |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function requestUri($relativeToWpRoot = false, $remove_query_params = false); |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public function userAgent(); |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param string $user_agent |
|
| 157 | - */ |
|
| 158 | - public function setUserAgent($user_agent = ''); |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return bool |
|
| 163 | - */ |
|
| 164 | - public function isBot(); |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param bool $is_bot |
|
| 169 | - */ |
|
| 170 | - public function setIsBot($is_bot); |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed |
|
| 175 | - * |
|
| 176 | - * @return string |
|
| 177 | - * @since $VID:$ |
|
| 178 | - */ |
|
| 179 | - public function requestPath(); |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * returns true if the last segment of the current request path (without params) matches the provided string |
|
| 184 | - * |
|
| 185 | - * @param string $uri_segment |
|
| 186 | - * @return bool |
|
| 187 | - * @since $VID:$ |
|
| 188 | - */ |
|
| 189 | - public function currentPageIs($uri_segment); |
|
| 81 | + /** |
|
| 82 | + * check if param exists |
|
| 83 | + * |
|
| 84 | + * @param string $key |
|
| 85 | + * @return bool |
|
| 86 | + */ |
|
| 87 | + public function requestParamIsSet($key); |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 92 | + * and return the value for the first match found |
|
| 93 | + * wildcards can be either of the following: |
|
| 94 | + * ? to represent a single character of any type |
|
| 95 | + * * to represent one or more characters of any type |
|
| 96 | + * |
|
| 97 | + * @param string $pattern |
|
| 98 | + * @param null|mixed $default |
|
| 99 | + * @return false|int |
|
| 100 | + */ |
|
| 101 | + public function getMatch($pattern, $default = null); |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 106 | + * wildcards can be either of the following: |
|
| 107 | + * ? to represent a single character of any type |
|
| 108 | + * * to represent one or more characters of any type |
|
| 109 | + * returns true if a match is found or false if not |
|
| 110 | + * |
|
| 111 | + * @param string $pattern |
|
| 112 | + * @return false|int |
|
| 113 | + */ |
|
| 114 | + public function matches($pattern); |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * remove param |
|
| 119 | + * |
|
| 120 | + * @param string $key |
|
| 121 | + * @param bool $unset_from_global_too |
|
| 122 | + */ |
|
| 123 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * remove params |
|
| 128 | + * |
|
| 129 | + * @param array $keys |
|
| 130 | + * @param bool $unset_from_global_too |
|
| 131 | + */ |
|
| 132 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @return string |
|
| 137 | + */ |
|
| 138 | + public function ipAddress(); |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param boolean $relativeToWpRoot whether or not to return the uri relative to WordPress' home URL. |
|
| 143 | + * @param boolean $remove_query_params whether or not to return the uri with all query params removed. |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function requestUri($relativeToWpRoot = false, $remove_query_params = false); |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public function userAgent(); |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param string $user_agent |
|
| 157 | + */ |
|
| 158 | + public function setUserAgent($user_agent = ''); |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @return bool |
|
| 163 | + */ |
|
| 164 | + public function isBot(); |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param bool $is_bot |
|
| 169 | + */ |
|
| 170 | + public function setIsBot($is_bot); |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed |
|
| 175 | + * |
|
| 176 | + * @return string |
|
| 177 | + * @since $VID:$ |
|
| 178 | + */ |
|
| 179 | + public function requestPath(); |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * returns true if the last segment of the current request path (without params) matches the provided string |
|
| 184 | + * |
|
| 185 | + * @param string $uri_segment |
|
| 186 | + * @return bool |
|
| 187 | + * @since $VID:$ |
|
| 188 | + */ |
|
| 189 | + public function currentPageIs($uri_segment); |
|
| 190 | 190 | } |
@@ -15,11 +15,11 @@ |
||
| 15 | 15 | class WordPressPluginsPage extends RouteMatchSpecification |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @inheritDoc |
|
| 20 | - */ |
|
| 21 | - public function isMatchingRoute() |
|
| 22 | - { |
|
| 23 | - return $this->request->isAdmin() && $this->request->currentPageIs('plugins.php'); |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * @inheritDoc |
|
| 20 | + */ |
|
| 21 | + public function isMatchingRoute() |
|
| 22 | + { |
|
| 23 | + return $this->request->isAdmin() && $this->request->currentPageIs('plugins.php'); |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -17,65 +17,65 @@ |
||
| 17 | 17 | class RestApiRequests extends Route |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * returns true if the current request matches this route |
|
| 22 | - * |
|
| 23 | - * @return bool |
|
| 24 | - * @since $VID:$ |
|
| 25 | - */ |
|
| 26 | - public function matchesCurrentRequest(): bool |
|
| 27 | - { |
|
| 28 | - return $this->request->isAdmin() || $this->request->isApi() || $this->request->isWordPressApi(); |
|
| 29 | - } |
|
| 20 | + /** |
|
| 21 | + * returns true if the current request matches this route |
|
| 22 | + * |
|
| 23 | + * @return bool |
|
| 24 | + * @since $VID:$ |
|
| 25 | + */ |
|
| 26 | + public function matchesCurrentRequest(): bool |
|
| 27 | + { |
|
| 28 | + return $this->request->isAdmin() || $this->request->isApi() || $this->request->isWordPressApi(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @since $VID:$ |
|
| 34 | - */ |
|
| 35 | - protected function registerDependencies() |
|
| 36 | - { |
|
| 37 | - $this->dependency_map->registerDependencies( |
|
| 38 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields', |
|
| 39 | - ['EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache] |
|
| 40 | - ); |
|
| 41 | - $this->dependency_map->registerDependencies( |
|
| 42 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory', |
|
| 43 | - ['EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache] |
|
| 44 | - ); |
|
| 45 | - $this->dependency_map->registerDependencies( |
|
| 46 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 47 | - ['EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache] |
|
| 48 | - ); |
|
| 49 | - $this->dependency_map->registerDependencies( |
|
| 50 | - 'EventEspresso\core\libraries\rest_api\calculations\Datetime', |
|
| 51 | - [ |
|
| 52 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 53 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 54 | - ] |
|
| 55 | - ); |
|
| 56 | - $this->dependency_map->registerDependencies( |
|
| 57 | - 'EventEspresso\core\libraries\rest_api\calculations\Event', |
|
| 58 | - [ |
|
| 59 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 60 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 61 | - ] |
|
| 62 | - ); |
|
| 63 | - $this->dependency_map->registerDependencies( |
|
| 64 | - 'EventEspresso\core\libraries\rest_api\calculations\Registration', |
|
| 65 | - ['EEM_Registration' => EE_Dependency_Map::load_from_cache] |
|
| 66 | - ); |
|
| 67 | - } |
|
| 32 | + /** |
|
| 33 | + * @since $VID:$ |
|
| 34 | + */ |
|
| 35 | + protected function registerDependencies() |
|
| 36 | + { |
|
| 37 | + $this->dependency_map->registerDependencies( |
|
| 38 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields', |
|
| 39 | + ['EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache] |
|
| 40 | + ); |
|
| 41 | + $this->dependency_map->registerDependencies( |
|
| 42 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory', |
|
| 43 | + ['EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache] |
|
| 44 | + ); |
|
| 45 | + $this->dependency_map->registerDependencies( |
|
| 46 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 47 | + ['EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache] |
|
| 48 | + ); |
|
| 49 | + $this->dependency_map->registerDependencies( |
|
| 50 | + 'EventEspresso\core\libraries\rest_api\calculations\Datetime', |
|
| 51 | + [ |
|
| 52 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 53 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 54 | + ] |
|
| 55 | + ); |
|
| 56 | + $this->dependency_map->registerDependencies( |
|
| 57 | + 'EventEspresso\core\libraries\rest_api\calculations\Event', |
|
| 58 | + [ |
|
| 59 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 60 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 61 | + ] |
|
| 62 | + ); |
|
| 63 | + $this->dependency_map->registerDependencies( |
|
| 64 | + 'EventEspresso\core\libraries\rest_api\calculations\Registration', |
|
| 65 | + ['EEM_Registration' => EE_Dependency_Map::load_from_cache] |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * implements logic required to run during request |
|
| 72 | - * |
|
| 73 | - * @return bool |
|
| 74 | - * @since $VID:$ |
|
| 75 | - */ |
|
| 76 | - protected function requestHandler(): bool |
|
| 77 | - { |
|
| 78 | - EED_Core_Rest_Api::set_hooks_both(); |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 70 | + /** |
|
| 71 | + * implements logic required to run during request |
|
| 72 | + * |
|
| 73 | + * @return bool |
|
| 74 | + * @since $VID:$ |
|
| 75 | + */ |
|
| 76 | + protected function requestHandler(): bool |
|
| 77 | + { |
|
| 78 | + EED_Core_Rest_Api::set_hooks_both(); |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -21,1021 +21,1021 @@ |
||
| 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 | - * @type EE_Dependency_Map $_instance |
|
| 55 | - */ |
|
| 56 | - protected static $_instance; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var ClassInterfaceCache $class_cache |
|
| 60 | - */ |
|
| 61 | - private $class_cache; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @type RequestInterface $request |
|
| 65 | - */ |
|
| 66 | - protected $request; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @type LegacyRequestInterface $legacy_request |
|
| 70 | - */ |
|
| 71 | - protected $legacy_request; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @type ResponseInterface $response |
|
| 75 | - */ |
|
| 76 | - protected $response; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @type LoaderInterface $loader |
|
| 80 | - */ |
|
| 81 | - protected $loader; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @type array $_dependency_map |
|
| 85 | - */ |
|
| 86 | - protected $_dependency_map = []; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @type array $_class_loaders |
|
| 90 | - */ |
|
| 91 | - protected $_class_loaders = []; |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * EE_Dependency_Map constructor. |
|
| 96 | - * |
|
| 97 | - * @param ClassInterfaceCache $class_cache |
|
| 98 | - */ |
|
| 99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
| 100 | - { |
|
| 101 | - $this->class_cache = $class_cache; |
|
| 102 | - do_action('EE_Dependency_Map____construct', $this); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return void |
|
| 108 | - * @throws InvalidAliasException |
|
| 109 | - */ |
|
| 110 | - public function initialize() |
|
| 111 | - { |
|
| 112 | - $this->_register_core_dependencies(); |
|
| 113 | - $this->_register_core_class_loaders(); |
|
| 114 | - $this->_register_core_aliases(); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @singleton method used to instantiate class object |
|
| 120 | - * @param ClassInterfaceCache|null $class_cache |
|
| 121 | - * @return EE_Dependency_Map |
|
| 122 | - */ |
|
| 123 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
| 124 | - { |
|
| 125 | - // check if class object is instantiated, and instantiated properly |
|
| 126 | - if ( |
|
| 127 | - ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
| 128 | - && $class_cache instanceof ClassInterfaceCache |
|
| 129 | - ) { |
|
| 130 | - EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
| 131 | - } |
|
| 132 | - return EE_Dependency_Map::$_instance; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param RequestInterface $request |
|
| 138 | - */ |
|
| 139 | - public function setRequest(RequestInterface $request) |
|
| 140 | - { |
|
| 141 | - $this->request = $request; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param LegacyRequestInterface $legacy_request |
|
| 147 | - */ |
|
| 148 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 149 | - { |
|
| 150 | - $this->legacy_request = $legacy_request; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param ResponseInterface $response |
|
| 156 | - */ |
|
| 157 | - public function setResponse(ResponseInterface $response) |
|
| 158 | - { |
|
| 159 | - $this->response = $response; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param LoaderInterface $loader |
|
| 165 | - */ |
|
| 166 | - public function setLoader(LoaderInterface $loader) |
|
| 167 | - { |
|
| 168 | - $this->loader = $loader; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @param string $class |
|
| 174 | - * @param array $dependencies |
|
| 175 | - * @param int $overwrite |
|
| 176 | - * @return bool |
|
| 177 | - */ |
|
| 178 | - public static function register_dependencies( |
|
| 179 | - $class, |
|
| 180 | - array $dependencies, |
|
| 181 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 182 | - ) { |
|
| 183 | - return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 189 | - * to the class specified by the first parameter. |
|
| 190 | - * IMPORTANT !!! |
|
| 191 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 192 | - * the order of the constructor parameters for the class in question. |
|
| 193 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 194 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 195 | - * |
|
| 196 | - * @param string $class |
|
| 197 | - * @param array $dependencies |
|
| 198 | - * @param int $overwrite |
|
| 199 | - * @return bool |
|
| 200 | - */ |
|
| 201 | - public function registerDependencies( |
|
| 202 | - $class, |
|
| 203 | - array $dependencies, |
|
| 204 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 205 | - ) { |
|
| 206 | - $class = trim($class, '\\'); |
|
| 207 | - $registered = false; |
|
| 208 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
| 209 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
| 210 | - } |
|
| 211 | - // we need to make sure that any aliases used when registering a dependency |
|
| 212 | - // get resolved to the correct class name |
|
| 213 | - foreach ($dependencies as $dependency => $load_source) { |
|
| 214 | - $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
| 215 | - if ( |
|
| 216 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 217 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 218 | - ) { |
|
| 219 | - unset($dependencies[ $dependency ]); |
|
| 220 | - $dependencies[ $alias ] = $load_source; |
|
| 221 | - $registered = true; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - // now add our two lists of dependencies together. |
|
| 225 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 226 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 227 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 228 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 229 | - // especially with numerically indexed arrays |
|
| 230 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
| 231 | - // now we need to ensure that the resulting dependencies |
|
| 232 | - // array only has the entries that are required for the class |
|
| 233 | - // so first count how many dependencies were originally registered for the class |
|
| 234 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
| 235 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 236 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 237 | - // then truncate the final array to match that count |
|
| 238 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 239 | - // otherwise just take the incoming array because nothing previously existed |
|
| 240 | - : $dependencies; |
|
| 241 | - return $registered; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param string $class_name |
|
| 247 | - * @param string $loader |
|
| 248 | - * @return bool |
|
| 249 | - * @throws DomainException |
|
| 250 | - */ |
|
| 251 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 252 | - { |
|
| 253 | - return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @param string $class_name |
|
| 259 | - * @param string $loader |
|
| 260 | - * @return bool |
|
| 261 | - * @throws DomainException |
|
| 262 | - */ |
|
| 263 | - public function registerClassLoader($class_name, $loader = 'load_core') |
|
| 264 | - { |
|
| 265 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 266 | - throw new DomainException( |
|
| 267 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 268 | - ); |
|
| 269 | - } |
|
| 270 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 271 | - if ( |
|
| 272 | - ! is_callable($loader) |
|
| 273 | - && ( |
|
| 274 | - strpos($loader, 'load_') !== 0 |
|
| 275 | - || ! method_exists('EE_Registry', $loader) |
|
| 276 | - ) |
|
| 277 | - ) { |
|
| 278 | - throw new DomainException( |
|
| 279 | - sprintf( |
|
| 280 | - esc_html__( |
|
| 281 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 282 | - 'event_espresso' |
|
| 283 | - ), |
|
| 284 | - $loader |
|
| 285 | - ) |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
| 289 | - if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
| 290 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 291 | - return true; |
|
| 292 | - } |
|
| 293 | - return false; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @return array |
|
| 299 | - */ |
|
| 300 | - public function dependency_map() |
|
| 301 | - { |
|
| 302 | - return $this->_dependency_map; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 308 | - * |
|
| 309 | - * @param string $class_name |
|
| 310 | - * @return boolean |
|
| 311 | - */ |
|
| 312 | - public function has($class_name = '') |
|
| 313 | - { |
|
| 314 | - // all legacy models have the same dependencies |
|
| 315 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 316 | - $class_name = 'LEGACY_MODELS'; |
|
| 317 | - } |
|
| 318 | - return isset($this->_dependency_map[ $class_name ]); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 324 | - * |
|
| 325 | - * @param string $class_name |
|
| 326 | - * @param string $dependency |
|
| 327 | - * @return bool |
|
| 328 | - */ |
|
| 329 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 330 | - { |
|
| 331 | - // all legacy models have the same dependencies |
|
| 332 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 333 | - $class_name = 'LEGACY_MODELS'; |
|
| 334 | - } |
|
| 335 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 336 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 342 | - * |
|
| 343 | - * @param string $class_name |
|
| 344 | - * @param string $dependency |
|
| 345 | - * @return int |
|
| 346 | - */ |
|
| 347 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 348 | - { |
|
| 349 | - // all legacy models have the same dependencies |
|
| 350 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 351 | - $class_name = 'LEGACY_MODELS'; |
|
| 352 | - } |
|
| 353 | - $dependency = $this->getFqnForAlias($dependency); |
|
| 354 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 355 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 356 | - : EE_Dependency_Map::not_registered; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @param string $class_name |
|
| 362 | - * @return string | Closure |
|
| 363 | - */ |
|
| 364 | - public function class_loader($class_name) |
|
| 365 | - { |
|
| 366 | - // all legacy models use load_model() |
|
| 367 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 368 | - return 'load_model'; |
|
| 369 | - } |
|
| 370 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
| 371 | - // perform strpos() first to avoid loading regex every time we load a class |
|
| 372 | - if ( |
|
| 373 | - strpos($class_name, 'EE_CPT_') === 0 |
|
| 374 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
| 375 | - ) { |
|
| 376 | - return 'load_core'; |
|
| 377 | - } |
|
| 378 | - $class_name = $this->getFqnForAlias($class_name); |
|
| 379 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @return array |
|
| 385 | - */ |
|
| 386 | - public function class_loaders() |
|
| 387 | - { |
|
| 388 | - return $this->_class_loaders; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * adds an alias for a classname |
|
| 394 | - * |
|
| 395 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 396 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 397 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 398 | - * @throws InvalidAliasException |
|
| 399 | - */ |
|
| 400 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
| 401 | - { |
|
| 402 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
| 408 | - * WHY? |
|
| 409 | - * Because if a class is type hinting for a concretion, |
|
| 410 | - * then why would we need to find another class to supply it? |
|
| 411 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 412 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 413 | - * Don't go looking for some substitute. |
|
| 414 | - * Whereas if a class is type hinting for an interface... |
|
| 415 | - * then we need to find an actual class to use. |
|
| 416 | - * So the interface IS the alias for some other FQN, |
|
| 417 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 418 | - * represents some other class. |
|
| 419 | - * |
|
| 420 | - * @param string $fqn |
|
| 421 | - * @param string $for_class |
|
| 422 | - * @return bool |
|
| 423 | - */ |
|
| 424 | - public function isAlias($fqn = '', $for_class = '') |
|
| 425 | - { |
|
| 426 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 432 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 433 | - * for example: |
|
| 434 | - * if the following two entries were added to the _aliases array: |
|
| 435 | - * array( |
|
| 436 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 437 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 438 | - * ) |
|
| 439 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 440 | - * to load an instance of 'some\namespace\classname' |
|
| 441 | - * |
|
| 442 | - * @param string $alias |
|
| 443 | - * @param string $for_class |
|
| 444 | - * @return string |
|
| 445 | - */ |
|
| 446 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
| 447 | - { |
|
| 448 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 454 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 455 | - * This is done by using the following class constants: |
|
| 456 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 457 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 458 | - */ |
|
| 459 | - protected function _register_core_dependencies() |
|
| 460 | - { |
|
| 461 | - $this->_dependency_map = [ |
|
| 462 | - 'EE_Request_Handler' => [ |
|
| 463 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 464 | - ], |
|
| 465 | - 'EE_System' => [ |
|
| 466 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 467 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 469 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 470 | - 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - ], |
|
| 472 | - 'EE_Admin' => [ |
|
| 473 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 474 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 475 | - ], |
|
| 476 | - 'EE_Cart' => [ |
|
| 477 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 478 | - ], |
|
| 479 | - 'EE_Messenger_Collection_Loader' => [ |
|
| 480 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 481 | - ], |
|
| 482 | - 'EE_Message_Type_Collection_Loader' => [ |
|
| 483 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 484 | - ], |
|
| 485 | - 'EE_Message_Resource_Manager' => [ |
|
| 486 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 487 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 488 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 489 | - ], |
|
| 490 | - 'EE_Message_Factory' => [ |
|
| 491 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - ], |
|
| 493 | - 'EE_messages' => [ |
|
| 494 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 495 | - ], |
|
| 496 | - 'EE_Messages_Generator' => [ |
|
| 497 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 498 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 499 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 500 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 501 | - ], |
|
| 502 | - 'EE_Messages_Processor' => [ |
|
| 503 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 504 | - ], |
|
| 505 | - 'EE_Messages_Queue' => [ |
|
| 506 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 507 | - ], |
|
| 508 | - 'EE_Messages_Template_Defaults' => [ |
|
| 509 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 510 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 511 | - ], |
|
| 512 | - 'EE_Message_To_Generate_From_Request' => [ |
|
| 513 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 514 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 515 | - ], |
|
| 516 | - 'EventEspresso\core\services\commands\CommandBus' => [ |
|
| 517 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 518 | - ], |
|
| 519 | - 'EventEspresso\services\commands\CommandHandler' => [ |
|
| 520 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 521 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 522 | - ], |
|
| 523 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
| 524 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 525 | - ], |
|
| 526 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
| 527 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 528 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - ], |
|
| 530 | - 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
| 531 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 532 | - ], |
|
| 533 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
| 534 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 535 | - ], |
|
| 536 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
| 537 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 538 | - ], |
|
| 539 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
| 540 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 541 | - ], |
|
| 542 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
| 543 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ], |
|
| 545 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
| 546 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - ], |
|
| 548 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
| 549 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 550 | - ], |
|
| 551 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
| 552 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 553 | - ], |
|
| 554 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
| 555 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - ], |
|
| 557 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
| 558 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 559 | - ], |
|
| 560 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
| 561 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 562 | - ], |
|
| 563 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
| 564 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - ], |
|
| 566 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
| 567 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - ], |
|
| 569 | - 'EventEspresso\core\services\database\TableManager' => [ |
|
| 570 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 571 | - ], |
|
| 572 | - 'EE_Data_Migration_Class_Base' => [ |
|
| 573 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 574 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 575 | - ], |
|
| 576 | - 'EE_DMS_Core_4_1_0' => [ |
|
| 577 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 578 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 579 | - ], |
|
| 580 | - 'EE_DMS_Core_4_2_0' => [ |
|
| 581 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 582 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 583 | - ], |
|
| 584 | - 'EE_DMS_Core_4_3_0' => [ |
|
| 585 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 586 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 587 | - ], |
|
| 588 | - 'EE_DMS_Core_4_4_0' => [ |
|
| 589 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 590 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | - ], |
|
| 592 | - 'EE_DMS_Core_4_5_0' => [ |
|
| 593 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 594 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 595 | - ], |
|
| 596 | - 'EE_DMS_Core_4_6_0' => [ |
|
| 597 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 598 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 599 | - ], |
|
| 600 | - 'EE_DMS_Core_4_7_0' => [ |
|
| 601 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 602 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - ], |
|
| 604 | - 'EE_DMS_Core_4_8_0' => [ |
|
| 605 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 606 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 607 | - ], |
|
| 608 | - 'EE_DMS_Core_4_9_0' => [ |
|
| 609 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 610 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 611 | - ], |
|
| 612 | - 'EE_DMS_Core_4_10_0' => [ |
|
| 613 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 614 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
| 616 | - ], |
|
| 617 | - 'EE_DMS_Core_4_11_0' => [ |
|
| 618 | - 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
| 619 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 620 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 621 | - ], |
|
| 622 | - 'EventEspresso\core\services\assets\Registry' => [ |
|
| 623 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
| 624 | - 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
| 625 | - ], |
|
| 626 | - 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
| 627 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 628 | - ], |
|
| 629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
| 630 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 631 | - ], |
|
| 632 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
| 633 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 634 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 635 | - ], |
|
| 636 | - 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
| 637 | - null, |
|
| 638 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 639 | - ], |
|
| 640 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
| 641 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 642 | - ], |
|
| 643 | - 'LEGACY_MODELS' => [ |
|
| 644 | - null, |
|
| 645 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 646 | - ], |
|
| 647 | - 'EE_Module_Request_Router' => [ |
|
| 648 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 649 | - ], |
|
| 650 | - 'EE_Registration_Processor' => [ |
|
| 651 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 652 | - ], |
|
| 653 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
| 654 | - null, |
|
| 655 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 656 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 657 | - ], |
|
| 658 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
| 659 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 660 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 661 | - ], |
|
| 662 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
| 663 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 664 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 665 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 666 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 667 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 668 | - ], |
|
| 669 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
| 670 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 671 | - ], |
|
| 672 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
| 673 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 674 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 675 | - ], |
|
| 676 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
| 677 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 678 | - ], |
|
| 679 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
| 680 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 681 | - ], |
|
| 682 | - 'EE_CPT_Strategy' => [ |
|
| 683 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 684 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 685 | - ], |
|
| 686 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
| 687 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 688 | - ], |
|
| 689 | - 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
| 690 | - null, |
|
| 691 | - null, |
|
| 692 | - null, |
|
| 693 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 694 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 695 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 696 | - ], |
|
| 697 | - 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
| 698 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 699 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 700 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 701 | - ], |
|
| 702 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
| 703 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 704 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 705 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 706 | - ], |
|
| 707 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
| 708 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
| 709 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 710 | - ], |
|
| 711 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
| 712 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
| 713 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
| 714 | - ], |
|
| 715 | - 'EE_URL_Validation_Strategy' => [ |
|
| 716 | - null, |
|
| 717 | - null, |
|
| 718 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
| 719 | - ], |
|
| 720 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
| 721 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 722 | - ], |
|
| 723 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
| 724 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 725 | - ], |
|
| 726 | - 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
| 727 | - 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
| 728 | - 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
| 729 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
| 730 | - null, |
|
| 731 | - ], |
|
| 732 | - 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
| 733 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
| 734 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 735 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 736 | - 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
| 737 | - ], |
|
| 738 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
| 739 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
| 740 | - ], |
|
| 741 | - 'EventEspresso\core\services\routing\Router' => [ |
|
| 742 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 743 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 744 | - 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
| 745 | - ], |
|
| 746 | - 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
| 747 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 748 | - ], |
|
| 749 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
| 750 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 751 | - ], |
|
| 752 | - 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
| 753 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
| 754 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 755 | - ], |
|
| 756 | - 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
| 757 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 758 | - ], |
|
| 759 | - 'EventEspresso\core\services\addon\AddonManager' => [ |
|
| 760 | - 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
| 761 | - 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
| 762 | - 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
| 763 | - 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
| 764 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
| 765 | - ], |
|
| 766 | - 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
| 767 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 768 | - ], |
|
| 769 | - ]; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Registers how core classes are loaded. |
|
| 775 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 776 | - * 'EE_Request_Handler' => 'load_core' |
|
| 777 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 778 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 779 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 780 | - * 'Some_Class' => function () { |
|
| 781 | - * return new Some_Class(); |
|
| 782 | - * }, |
|
| 783 | - * This is required for instantiating dependencies |
|
| 784 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 785 | - * 'Required_Interface' => function () { |
|
| 786 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 787 | - * }, |
|
| 788 | - */ |
|
| 789 | - protected function _register_core_class_loaders() |
|
| 790 | - { |
|
| 791 | - $this->_class_loaders = [ |
|
| 792 | - // load_core |
|
| 793 | - 'EE_Dependency_Map' => function () { |
|
| 794 | - return $this; |
|
| 795 | - }, |
|
| 796 | - 'EE_Capabilities' => 'load_core', |
|
| 797 | - 'EE_Encryption' => 'load_core', |
|
| 798 | - 'EE_Front_Controller' => 'load_core', |
|
| 799 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 800 | - 'EE_Registry' => 'load_core', |
|
| 801 | - 'EE_Request' => function () { |
|
| 802 | - return $this->legacy_request; |
|
| 803 | - }, |
|
| 804 | - 'EventEspresso\core\services\request\Request' => function () { |
|
| 805 | - return $this->request; |
|
| 806 | - }, |
|
| 807 | - 'EventEspresso\core\services\request\Response' => function () { |
|
| 808 | - return $this->response; |
|
| 809 | - }, |
|
| 810 | - 'EE_Base' => 'load_core', |
|
| 811 | - 'EE_Request_Handler' => 'load_core', |
|
| 812 | - 'EE_Session' => 'load_core', |
|
| 813 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 814 | - 'EE_System' => 'load_core', |
|
| 815 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 816 | - 'EE_Register_CPTs' => 'load_core', |
|
| 817 | - 'EE_Admin' => 'load_core', |
|
| 818 | - 'EE_CPT_Strategy' => 'load_core', |
|
| 819 | - // load_class |
|
| 820 | - 'EE_Registration_Processor' => 'load_class', |
|
| 821 | - // load_lib |
|
| 822 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 823 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 824 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 825 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 826 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 827 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 828 | - 'EE_Message_Repository' => 'load_lib', |
|
| 829 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 830 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 831 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 832 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 833 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
| 834 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
| 835 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
| 836 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
| 837 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
| 838 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
| 839 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
| 840 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
| 841 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
| 842 | - 'EE_DMS_Core_4_11_0' => 'load_dms', |
|
| 843 | - 'EE_Messages_Generator' => static function () { |
|
| 844 | - return EE_Registry::instance()->load_lib( |
|
| 845 | - 'Messages_Generator', |
|
| 846 | - [], |
|
| 847 | - false, |
|
| 848 | - false |
|
| 849 | - ); |
|
| 850 | - }, |
|
| 851 | - 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
| 852 | - return EE_Registry::instance()->load_lib( |
|
| 853 | - 'Messages_Template_Defaults', |
|
| 854 | - $arguments, |
|
| 855 | - false, |
|
| 856 | - false |
|
| 857 | - ); |
|
| 858 | - }, |
|
| 859 | - // load_helper |
|
| 860 | - 'EEH_Parse_Shortcodes' => static function () { |
|
| 861 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 862 | - return new EEH_Parse_Shortcodes(); |
|
| 863 | - } |
|
| 864 | - return null; |
|
| 865 | - }, |
|
| 866 | - 'EE_Template_Config' => static function () { |
|
| 867 | - return EE_Config::instance()->template_settings; |
|
| 868 | - }, |
|
| 869 | - 'EE_Currency_Config' => static function () { |
|
| 870 | - return EE_Config::instance()->currency; |
|
| 871 | - }, |
|
| 872 | - 'EE_Registration_Config' => static function () { |
|
| 873 | - return EE_Config::instance()->registration; |
|
| 874 | - }, |
|
| 875 | - 'EE_Core_Config' => static function () { |
|
| 876 | - return EE_Config::instance()->core; |
|
| 877 | - }, |
|
| 878 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
| 879 | - return LoaderFactory::getLoader(); |
|
| 880 | - }, |
|
| 881 | - 'EE_Network_Config' => static function () { |
|
| 882 | - return EE_Network_Config::instance(); |
|
| 883 | - }, |
|
| 884 | - 'EE_Config' => static function () { |
|
| 885 | - return EE_Config::instance(); |
|
| 886 | - }, |
|
| 887 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
| 888 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
| 889 | - }, |
|
| 890 | - 'EE_Admin_Config' => static function () { |
|
| 891 | - return EE_Config::instance()->admin; |
|
| 892 | - }, |
|
| 893 | - 'EE_Organization_Config' => static function () { |
|
| 894 | - return EE_Config::instance()->organization; |
|
| 895 | - }, |
|
| 896 | - 'EE_Network_Core_Config' => static function () { |
|
| 897 | - return EE_Network_Config::instance()->core; |
|
| 898 | - }, |
|
| 899 | - 'EE_Environment_Config' => static function () { |
|
| 900 | - return EE_Config::instance()->environment; |
|
| 901 | - }, |
|
| 902 | - 'EED_Core_Rest_Api' => static function () { |
|
| 903 | - return EED_Core_Rest_Api::instance(); |
|
| 904 | - }, |
|
| 905 | - 'WP_REST_Server' => static function () { |
|
| 906 | - return rest_get_server(); |
|
| 907 | - }, |
|
| 908 | - 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
| 909 | - return EE_Psr4AutoloaderInit::psr4_loader(); |
|
| 910 | - }, |
|
| 911 | - ]; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - /** |
|
| 916 | - * can be used for supplying alternate names for classes, |
|
| 917 | - * or for connecting interface names to instantiable classes |
|
| 918 | - * |
|
| 919 | - * @throws InvalidAliasException |
|
| 920 | - */ |
|
| 921 | - protected function _register_core_aliases() |
|
| 922 | - { |
|
| 923 | - $aliases = [ |
|
| 924 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 925 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 926 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 927 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 928 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 929 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 930 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 931 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 932 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 933 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 934 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 935 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 936 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 937 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 938 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 939 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 940 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 941 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 942 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 943 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 944 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 945 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 946 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 947 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 948 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 949 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 950 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 951 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 952 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 953 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 954 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 955 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 956 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 957 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 958 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 959 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 960 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 961 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
| 962 | - 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
| 963 | - ]; |
|
| 964 | - foreach ($aliases as $alias => $fqn) { |
|
| 965 | - if (is_array($fqn)) { |
|
| 966 | - foreach ($fqn as $class => $for_class) { |
|
| 967 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 968 | - } |
|
| 969 | - continue; |
|
| 970 | - } |
|
| 971 | - $this->class_cache->addAlias($fqn, $alias); |
|
| 972 | - } |
|
| 973 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 974 | - $this->class_cache->addAlias( |
|
| 975 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 976 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 977 | - ); |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 984 | - * request Primarily used by unit tests. |
|
| 985 | - */ |
|
| 986 | - public function reset() |
|
| 987 | - { |
|
| 988 | - $this->_register_core_class_loaders(); |
|
| 989 | - $this->_register_core_dependencies(); |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
| 995 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 996 | - * WHY? |
|
| 997 | - * Because if a class is type hinting for a concretion, |
|
| 998 | - * then why would we need to find another class to supply it? |
|
| 999 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 1000 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 1001 | - * Don't go looking for some substitute. |
|
| 1002 | - * Whereas if a class is type hinting for an interface... |
|
| 1003 | - * then we need to find an actual class to use. |
|
| 1004 | - * So the interface IS the alias for some other FQN, |
|
| 1005 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 1006 | - * represents some other class. |
|
| 1007 | - * |
|
| 1008 | - * @param string $fqn |
|
| 1009 | - * @param string $for_class |
|
| 1010 | - * @return bool |
|
| 1011 | - * @deprecated 4.9.62.p |
|
| 1012 | - */ |
|
| 1013 | - public function has_alias($fqn = '', $for_class = '') |
|
| 1014 | - { |
|
| 1015 | - return $this->isAlias($fqn, $for_class); |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 1021 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 1022 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 1023 | - * for example: |
|
| 1024 | - * if the following two entries were added to the _aliases array: |
|
| 1025 | - * array( |
|
| 1026 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 1027 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 1028 | - * ) |
|
| 1029 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 1030 | - * to load an instance of 'some\namespace\classname' |
|
| 1031 | - * |
|
| 1032 | - * @param string $alias |
|
| 1033 | - * @param string $for_class |
|
| 1034 | - * @return string |
|
| 1035 | - * @deprecated 4.9.62.p |
|
| 1036 | - */ |
|
| 1037 | - public function get_alias($alias = '', $for_class = '') |
|
| 1038 | - { |
|
| 1039 | - return $this->getFqnForAlias($alias, $for_class); |
|
| 1040 | - } |
|
| 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 | + * @type EE_Dependency_Map $_instance |
|
| 55 | + */ |
|
| 56 | + protected static $_instance; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var ClassInterfaceCache $class_cache |
|
| 60 | + */ |
|
| 61 | + private $class_cache; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @type RequestInterface $request |
|
| 65 | + */ |
|
| 66 | + protected $request; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @type LegacyRequestInterface $legacy_request |
|
| 70 | + */ |
|
| 71 | + protected $legacy_request; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @type ResponseInterface $response |
|
| 75 | + */ |
|
| 76 | + protected $response; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @type LoaderInterface $loader |
|
| 80 | + */ |
|
| 81 | + protected $loader; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @type array $_dependency_map |
|
| 85 | + */ |
|
| 86 | + protected $_dependency_map = []; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @type array $_class_loaders |
|
| 90 | + */ |
|
| 91 | + protected $_class_loaders = []; |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * EE_Dependency_Map constructor. |
|
| 96 | + * |
|
| 97 | + * @param ClassInterfaceCache $class_cache |
|
| 98 | + */ |
|
| 99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
| 100 | + { |
|
| 101 | + $this->class_cache = $class_cache; |
|
| 102 | + do_action('EE_Dependency_Map____construct', $this); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return void |
|
| 108 | + * @throws InvalidAliasException |
|
| 109 | + */ |
|
| 110 | + public function initialize() |
|
| 111 | + { |
|
| 112 | + $this->_register_core_dependencies(); |
|
| 113 | + $this->_register_core_class_loaders(); |
|
| 114 | + $this->_register_core_aliases(); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @singleton method used to instantiate class object |
|
| 120 | + * @param ClassInterfaceCache|null $class_cache |
|
| 121 | + * @return EE_Dependency_Map |
|
| 122 | + */ |
|
| 123 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
| 124 | + { |
|
| 125 | + // check if class object is instantiated, and instantiated properly |
|
| 126 | + if ( |
|
| 127 | + ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
| 128 | + && $class_cache instanceof ClassInterfaceCache |
|
| 129 | + ) { |
|
| 130 | + EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
| 131 | + } |
|
| 132 | + return EE_Dependency_Map::$_instance; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param RequestInterface $request |
|
| 138 | + */ |
|
| 139 | + public function setRequest(RequestInterface $request) |
|
| 140 | + { |
|
| 141 | + $this->request = $request; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param LegacyRequestInterface $legacy_request |
|
| 147 | + */ |
|
| 148 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 149 | + { |
|
| 150 | + $this->legacy_request = $legacy_request; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param ResponseInterface $response |
|
| 156 | + */ |
|
| 157 | + public function setResponse(ResponseInterface $response) |
|
| 158 | + { |
|
| 159 | + $this->response = $response; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param LoaderInterface $loader |
|
| 165 | + */ |
|
| 166 | + public function setLoader(LoaderInterface $loader) |
|
| 167 | + { |
|
| 168 | + $this->loader = $loader; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @param string $class |
|
| 174 | + * @param array $dependencies |
|
| 175 | + * @param int $overwrite |
|
| 176 | + * @return bool |
|
| 177 | + */ |
|
| 178 | + public static function register_dependencies( |
|
| 179 | + $class, |
|
| 180 | + array $dependencies, |
|
| 181 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 182 | + ) { |
|
| 183 | + return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 189 | + * to the class specified by the first parameter. |
|
| 190 | + * IMPORTANT !!! |
|
| 191 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 192 | + * the order of the constructor parameters for the class in question. |
|
| 193 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 194 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 195 | + * |
|
| 196 | + * @param string $class |
|
| 197 | + * @param array $dependencies |
|
| 198 | + * @param int $overwrite |
|
| 199 | + * @return bool |
|
| 200 | + */ |
|
| 201 | + public function registerDependencies( |
|
| 202 | + $class, |
|
| 203 | + array $dependencies, |
|
| 204 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 205 | + ) { |
|
| 206 | + $class = trim($class, '\\'); |
|
| 207 | + $registered = false; |
|
| 208 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
| 209 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
| 210 | + } |
|
| 211 | + // we need to make sure that any aliases used when registering a dependency |
|
| 212 | + // get resolved to the correct class name |
|
| 213 | + foreach ($dependencies as $dependency => $load_source) { |
|
| 214 | + $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
| 215 | + if ( |
|
| 216 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 217 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 218 | + ) { |
|
| 219 | + unset($dependencies[ $dependency ]); |
|
| 220 | + $dependencies[ $alias ] = $load_source; |
|
| 221 | + $registered = true; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + // now add our two lists of dependencies together. |
|
| 225 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 226 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 227 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 228 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 229 | + // especially with numerically indexed arrays |
|
| 230 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
| 231 | + // now we need to ensure that the resulting dependencies |
|
| 232 | + // array only has the entries that are required for the class |
|
| 233 | + // so first count how many dependencies were originally registered for the class |
|
| 234 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
| 235 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 236 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 237 | + // then truncate the final array to match that count |
|
| 238 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 239 | + // otherwise just take the incoming array because nothing previously existed |
|
| 240 | + : $dependencies; |
|
| 241 | + return $registered; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param string $class_name |
|
| 247 | + * @param string $loader |
|
| 248 | + * @return bool |
|
| 249 | + * @throws DomainException |
|
| 250 | + */ |
|
| 251 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 252 | + { |
|
| 253 | + return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param string $class_name |
|
| 259 | + * @param string $loader |
|
| 260 | + * @return bool |
|
| 261 | + * @throws DomainException |
|
| 262 | + */ |
|
| 263 | + public function registerClassLoader($class_name, $loader = 'load_core') |
|
| 264 | + { |
|
| 265 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 266 | + throw new DomainException( |
|
| 267 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 268 | + ); |
|
| 269 | + } |
|
| 270 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 271 | + if ( |
|
| 272 | + ! is_callable($loader) |
|
| 273 | + && ( |
|
| 274 | + strpos($loader, 'load_') !== 0 |
|
| 275 | + || ! method_exists('EE_Registry', $loader) |
|
| 276 | + ) |
|
| 277 | + ) { |
|
| 278 | + throw new DomainException( |
|
| 279 | + sprintf( |
|
| 280 | + esc_html__( |
|
| 281 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 282 | + 'event_espresso' |
|
| 283 | + ), |
|
| 284 | + $loader |
|
| 285 | + ) |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
| 289 | + if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
| 290 | + EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 291 | + return true; |
|
| 292 | + } |
|
| 293 | + return false; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @return array |
|
| 299 | + */ |
|
| 300 | + public function dependency_map() |
|
| 301 | + { |
|
| 302 | + return $this->_dependency_map; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 308 | + * |
|
| 309 | + * @param string $class_name |
|
| 310 | + * @return boolean |
|
| 311 | + */ |
|
| 312 | + public function has($class_name = '') |
|
| 313 | + { |
|
| 314 | + // all legacy models have the same dependencies |
|
| 315 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 316 | + $class_name = 'LEGACY_MODELS'; |
|
| 317 | + } |
|
| 318 | + return isset($this->_dependency_map[ $class_name ]); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 324 | + * |
|
| 325 | + * @param string $class_name |
|
| 326 | + * @param string $dependency |
|
| 327 | + * @return bool |
|
| 328 | + */ |
|
| 329 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 330 | + { |
|
| 331 | + // all legacy models have the same dependencies |
|
| 332 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 333 | + $class_name = 'LEGACY_MODELS'; |
|
| 334 | + } |
|
| 335 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 336 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 342 | + * |
|
| 343 | + * @param string $class_name |
|
| 344 | + * @param string $dependency |
|
| 345 | + * @return int |
|
| 346 | + */ |
|
| 347 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 348 | + { |
|
| 349 | + // all legacy models have the same dependencies |
|
| 350 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 351 | + $class_name = 'LEGACY_MODELS'; |
|
| 352 | + } |
|
| 353 | + $dependency = $this->getFqnForAlias($dependency); |
|
| 354 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 355 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 356 | + : EE_Dependency_Map::not_registered; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @param string $class_name |
|
| 362 | + * @return string | Closure |
|
| 363 | + */ |
|
| 364 | + public function class_loader($class_name) |
|
| 365 | + { |
|
| 366 | + // all legacy models use load_model() |
|
| 367 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 368 | + return 'load_model'; |
|
| 369 | + } |
|
| 370 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
| 371 | + // perform strpos() first to avoid loading regex every time we load a class |
|
| 372 | + if ( |
|
| 373 | + strpos($class_name, 'EE_CPT_') === 0 |
|
| 374 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
| 375 | + ) { |
|
| 376 | + return 'load_core'; |
|
| 377 | + } |
|
| 378 | + $class_name = $this->getFqnForAlias($class_name); |
|
| 379 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @return array |
|
| 385 | + */ |
|
| 386 | + public function class_loaders() |
|
| 387 | + { |
|
| 388 | + return $this->_class_loaders; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * adds an alias for a classname |
|
| 394 | + * |
|
| 395 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 396 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 397 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 398 | + * @throws InvalidAliasException |
|
| 399 | + */ |
|
| 400 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
| 401 | + { |
|
| 402 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
| 408 | + * WHY? |
|
| 409 | + * Because if a class is type hinting for a concretion, |
|
| 410 | + * then why would we need to find another class to supply it? |
|
| 411 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 412 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 413 | + * Don't go looking for some substitute. |
|
| 414 | + * Whereas if a class is type hinting for an interface... |
|
| 415 | + * then we need to find an actual class to use. |
|
| 416 | + * So the interface IS the alias for some other FQN, |
|
| 417 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 418 | + * represents some other class. |
|
| 419 | + * |
|
| 420 | + * @param string $fqn |
|
| 421 | + * @param string $for_class |
|
| 422 | + * @return bool |
|
| 423 | + */ |
|
| 424 | + public function isAlias($fqn = '', $for_class = '') |
|
| 425 | + { |
|
| 426 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 432 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 433 | + * for example: |
|
| 434 | + * if the following two entries were added to the _aliases array: |
|
| 435 | + * array( |
|
| 436 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 437 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 438 | + * ) |
|
| 439 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 440 | + * to load an instance of 'some\namespace\classname' |
|
| 441 | + * |
|
| 442 | + * @param string $alias |
|
| 443 | + * @param string $for_class |
|
| 444 | + * @return string |
|
| 445 | + */ |
|
| 446 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
| 447 | + { |
|
| 448 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 454 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 455 | + * This is done by using the following class constants: |
|
| 456 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 457 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 458 | + */ |
|
| 459 | + protected function _register_core_dependencies() |
|
| 460 | + { |
|
| 461 | + $this->_dependency_map = [ |
|
| 462 | + 'EE_Request_Handler' => [ |
|
| 463 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 464 | + ], |
|
| 465 | + 'EE_System' => [ |
|
| 466 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 467 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 469 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 470 | + 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + ], |
|
| 472 | + 'EE_Admin' => [ |
|
| 473 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 474 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 475 | + ], |
|
| 476 | + 'EE_Cart' => [ |
|
| 477 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 478 | + ], |
|
| 479 | + 'EE_Messenger_Collection_Loader' => [ |
|
| 480 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 481 | + ], |
|
| 482 | + 'EE_Message_Type_Collection_Loader' => [ |
|
| 483 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 484 | + ], |
|
| 485 | + 'EE_Message_Resource_Manager' => [ |
|
| 486 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 487 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 488 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 489 | + ], |
|
| 490 | + 'EE_Message_Factory' => [ |
|
| 491 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + ], |
|
| 493 | + 'EE_messages' => [ |
|
| 494 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 495 | + ], |
|
| 496 | + 'EE_Messages_Generator' => [ |
|
| 497 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 498 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 499 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 500 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 501 | + ], |
|
| 502 | + 'EE_Messages_Processor' => [ |
|
| 503 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 504 | + ], |
|
| 505 | + 'EE_Messages_Queue' => [ |
|
| 506 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 507 | + ], |
|
| 508 | + 'EE_Messages_Template_Defaults' => [ |
|
| 509 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 510 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 511 | + ], |
|
| 512 | + 'EE_Message_To_Generate_From_Request' => [ |
|
| 513 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 514 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 515 | + ], |
|
| 516 | + 'EventEspresso\core\services\commands\CommandBus' => [ |
|
| 517 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 518 | + ], |
|
| 519 | + 'EventEspresso\services\commands\CommandHandler' => [ |
|
| 520 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 521 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 522 | + ], |
|
| 523 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
| 524 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 525 | + ], |
|
| 526 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
| 527 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 528 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + ], |
|
| 530 | + 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
| 531 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 532 | + ], |
|
| 533 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
| 534 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 535 | + ], |
|
| 536 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
| 537 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 538 | + ], |
|
| 539 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
| 540 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 541 | + ], |
|
| 542 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
| 543 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ], |
|
| 545 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
| 546 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + ], |
|
| 548 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
| 549 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 550 | + ], |
|
| 551 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
| 552 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 553 | + ], |
|
| 554 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
| 555 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + ], |
|
| 557 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
| 558 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 559 | + ], |
|
| 560 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
| 561 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 562 | + ], |
|
| 563 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
| 564 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + ], |
|
| 566 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
| 567 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + ], |
|
| 569 | + 'EventEspresso\core\services\database\TableManager' => [ |
|
| 570 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 571 | + ], |
|
| 572 | + 'EE_Data_Migration_Class_Base' => [ |
|
| 573 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 574 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 575 | + ], |
|
| 576 | + 'EE_DMS_Core_4_1_0' => [ |
|
| 577 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 578 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 579 | + ], |
|
| 580 | + 'EE_DMS_Core_4_2_0' => [ |
|
| 581 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 582 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 583 | + ], |
|
| 584 | + 'EE_DMS_Core_4_3_0' => [ |
|
| 585 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 586 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 587 | + ], |
|
| 588 | + 'EE_DMS_Core_4_4_0' => [ |
|
| 589 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 590 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 591 | + ], |
|
| 592 | + 'EE_DMS_Core_4_5_0' => [ |
|
| 593 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 594 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 595 | + ], |
|
| 596 | + 'EE_DMS_Core_4_6_0' => [ |
|
| 597 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 598 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 599 | + ], |
|
| 600 | + 'EE_DMS_Core_4_7_0' => [ |
|
| 601 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 602 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + ], |
|
| 604 | + 'EE_DMS_Core_4_8_0' => [ |
|
| 605 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 606 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 607 | + ], |
|
| 608 | + 'EE_DMS_Core_4_9_0' => [ |
|
| 609 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 610 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 611 | + ], |
|
| 612 | + 'EE_DMS_Core_4_10_0' => [ |
|
| 613 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 614 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
| 616 | + ], |
|
| 617 | + 'EE_DMS_Core_4_11_0' => [ |
|
| 618 | + 'EE_DMS_Core_4_10_0' => EE_Dependency_Map::load_from_cache, |
|
| 619 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 620 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 621 | + ], |
|
| 622 | + 'EventEspresso\core\services\assets\Registry' => [ |
|
| 623 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
| 624 | + 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
| 625 | + ], |
|
| 626 | + 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
| 627 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 628 | + ], |
|
| 629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
| 630 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 631 | + ], |
|
| 632 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
| 633 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 634 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 635 | + ], |
|
| 636 | + 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
| 637 | + null, |
|
| 638 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 639 | + ], |
|
| 640 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
| 641 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 642 | + ], |
|
| 643 | + 'LEGACY_MODELS' => [ |
|
| 644 | + null, |
|
| 645 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 646 | + ], |
|
| 647 | + 'EE_Module_Request_Router' => [ |
|
| 648 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 649 | + ], |
|
| 650 | + 'EE_Registration_Processor' => [ |
|
| 651 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 652 | + ], |
|
| 653 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
| 654 | + null, |
|
| 655 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 656 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 657 | + ], |
|
| 658 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
| 659 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 660 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 661 | + ], |
|
| 662 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
| 663 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 664 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 665 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 666 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 667 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 668 | + ], |
|
| 669 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
| 670 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 671 | + ], |
|
| 672 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
| 673 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 674 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 675 | + ], |
|
| 676 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
| 677 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 678 | + ], |
|
| 679 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
| 680 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 681 | + ], |
|
| 682 | + 'EE_CPT_Strategy' => [ |
|
| 683 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 684 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 685 | + ], |
|
| 686 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
| 687 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 688 | + ], |
|
| 689 | + 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
| 690 | + null, |
|
| 691 | + null, |
|
| 692 | + null, |
|
| 693 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 694 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 695 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 696 | + ], |
|
| 697 | + 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
| 698 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 699 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 700 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 701 | + ], |
|
| 702 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
| 703 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 704 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 705 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 706 | + ], |
|
| 707 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
| 708 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
| 709 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 710 | + ], |
|
| 711 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
| 712 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
| 713 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
| 714 | + ], |
|
| 715 | + 'EE_URL_Validation_Strategy' => [ |
|
| 716 | + null, |
|
| 717 | + null, |
|
| 718 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
| 719 | + ], |
|
| 720 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
| 721 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 722 | + ], |
|
| 723 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
| 724 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 725 | + ], |
|
| 726 | + 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
| 727 | + 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
| 728 | + 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
| 729 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
| 730 | + null, |
|
| 731 | + ], |
|
| 732 | + 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
| 733 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
| 734 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 735 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 736 | + 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
| 737 | + ], |
|
| 738 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
| 739 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
| 740 | + ], |
|
| 741 | + 'EventEspresso\core\services\routing\Router' => [ |
|
| 742 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 743 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 744 | + 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
| 745 | + ], |
|
| 746 | + 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
| 747 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 748 | + ], |
|
| 749 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
| 750 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 751 | + ], |
|
| 752 | + 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
| 753 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
| 754 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 755 | + ], |
|
| 756 | + 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => [ |
|
| 757 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 758 | + ], |
|
| 759 | + 'EventEspresso\core\services\addon\AddonManager' => [ |
|
| 760 | + 'EventEspresso\core\services\addon\AddonCollection' => EE_Dependency_Map::load_from_cache, |
|
| 761 | + 'EventEspresso\core\Psr4Autoloader' => EE_Dependency_Map::load_from_cache, |
|
| 762 | + 'EventEspresso\core\services\addon\api\v1\RegisterAddon' => EE_Dependency_Map::load_from_cache, |
|
| 763 | + 'EventEspresso\core\services\addon\api\IncompatibleAddonHandler' => EE_Dependency_Map::load_from_cache, |
|
| 764 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => EE_Dependency_Map::load_from_cache, |
|
| 765 | + ], |
|
| 766 | + 'EventEspresso\core\services\addon\api\ThirdPartyPluginHandler' => [ |
|
| 767 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 768 | + ], |
|
| 769 | + ]; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Registers how core classes are loaded. |
|
| 775 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 776 | + * 'EE_Request_Handler' => 'load_core' |
|
| 777 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 778 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 779 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 780 | + * 'Some_Class' => function () { |
|
| 781 | + * return new Some_Class(); |
|
| 782 | + * }, |
|
| 783 | + * This is required for instantiating dependencies |
|
| 784 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 785 | + * 'Required_Interface' => function () { |
|
| 786 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 787 | + * }, |
|
| 788 | + */ |
|
| 789 | + protected function _register_core_class_loaders() |
|
| 790 | + { |
|
| 791 | + $this->_class_loaders = [ |
|
| 792 | + // load_core |
|
| 793 | + 'EE_Dependency_Map' => function () { |
|
| 794 | + return $this; |
|
| 795 | + }, |
|
| 796 | + 'EE_Capabilities' => 'load_core', |
|
| 797 | + 'EE_Encryption' => 'load_core', |
|
| 798 | + 'EE_Front_Controller' => 'load_core', |
|
| 799 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 800 | + 'EE_Registry' => 'load_core', |
|
| 801 | + 'EE_Request' => function () { |
|
| 802 | + return $this->legacy_request; |
|
| 803 | + }, |
|
| 804 | + 'EventEspresso\core\services\request\Request' => function () { |
|
| 805 | + return $this->request; |
|
| 806 | + }, |
|
| 807 | + 'EventEspresso\core\services\request\Response' => function () { |
|
| 808 | + return $this->response; |
|
| 809 | + }, |
|
| 810 | + 'EE_Base' => 'load_core', |
|
| 811 | + 'EE_Request_Handler' => 'load_core', |
|
| 812 | + 'EE_Session' => 'load_core', |
|
| 813 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 814 | + 'EE_System' => 'load_core', |
|
| 815 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 816 | + 'EE_Register_CPTs' => 'load_core', |
|
| 817 | + 'EE_Admin' => 'load_core', |
|
| 818 | + 'EE_CPT_Strategy' => 'load_core', |
|
| 819 | + // load_class |
|
| 820 | + 'EE_Registration_Processor' => 'load_class', |
|
| 821 | + // load_lib |
|
| 822 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 823 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 824 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 825 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 826 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 827 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 828 | + 'EE_Message_Repository' => 'load_lib', |
|
| 829 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 830 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 831 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 832 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 833 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
| 834 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
| 835 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
| 836 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
| 837 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
| 838 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
| 839 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
| 840 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
| 841 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
| 842 | + 'EE_DMS_Core_4_11_0' => 'load_dms', |
|
| 843 | + 'EE_Messages_Generator' => static function () { |
|
| 844 | + return EE_Registry::instance()->load_lib( |
|
| 845 | + 'Messages_Generator', |
|
| 846 | + [], |
|
| 847 | + false, |
|
| 848 | + false |
|
| 849 | + ); |
|
| 850 | + }, |
|
| 851 | + 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
| 852 | + return EE_Registry::instance()->load_lib( |
|
| 853 | + 'Messages_Template_Defaults', |
|
| 854 | + $arguments, |
|
| 855 | + false, |
|
| 856 | + false |
|
| 857 | + ); |
|
| 858 | + }, |
|
| 859 | + // load_helper |
|
| 860 | + 'EEH_Parse_Shortcodes' => static function () { |
|
| 861 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 862 | + return new EEH_Parse_Shortcodes(); |
|
| 863 | + } |
|
| 864 | + return null; |
|
| 865 | + }, |
|
| 866 | + 'EE_Template_Config' => static function () { |
|
| 867 | + return EE_Config::instance()->template_settings; |
|
| 868 | + }, |
|
| 869 | + 'EE_Currency_Config' => static function () { |
|
| 870 | + return EE_Config::instance()->currency; |
|
| 871 | + }, |
|
| 872 | + 'EE_Registration_Config' => static function () { |
|
| 873 | + return EE_Config::instance()->registration; |
|
| 874 | + }, |
|
| 875 | + 'EE_Core_Config' => static function () { |
|
| 876 | + return EE_Config::instance()->core; |
|
| 877 | + }, |
|
| 878 | + 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
| 879 | + return LoaderFactory::getLoader(); |
|
| 880 | + }, |
|
| 881 | + 'EE_Network_Config' => static function () { |
|
| 882 | + return EE_Network_Config::instance(); |
|
| 883 | + }, |
|
| 884 | + 'EE_Config' => static function () { |
|
| 885 | + return EE_Config::instance(); |
|
| 886 | + }, |
|
| 887 | + 'EventEspresso\core\domain\Domain' => static function () { |
|
| 888 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
| 889 | + }, |
|
| 890 | + 'EE_Admin_Config' => static function () { |
|
| 891 | + return EE_Config::instance()->admin; |
|
| 892 | + }, |
|
| 893 | + 'EE_Organization_Config' => static function () { |
|
| 894 | + return EE_Config::instance()->organization; |
|
| 895 | + }, |
|
| 896 | + 'EE_Network_Core_Config' => static function () { |
|
| 897 | + return EE_Network_Config::instance()->core; |
|
| 898 | + }, |
|
| 899 | + 'EE_Environment_Config' => static function () { |
|
| 900 | + return EE_Config::instance()->environment; |
|
| 901 | + }, |
|
| 902 | + 'EED_Core_Rest_Api' => static function () { |
|
| 903 | + return EED_Core_Rest_Api::instance(); |
|
| 904 | + }, |
|
| 905 | + 'WP_REST_Server' => static function () { |
|
| 906 | + return rest_get_server(); |
|
| 907 | + }, |
|
| 908 | + 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
| 909 | + return EE_Psr4AutoloaderInit::psr4_loader(); |
|
| 910 | + }, |
|
| 911 | + ]; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + /** |
|
| 916 | + * can be used for supplying alternate names for classes, |
|
| 917 | + * or for connecting interface names to instantiable classes |
|
| 918 | + * |
|
| 919 | + * @throws InvalidAliasException |
|
| 920 | + */ |
|
| 921 | + protected function _register_core_aliases() |
|
| 922 | + { |
|
| 923 | + $aliases = [ |
|
| 924 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 925 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 926 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 927 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 928 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 929 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 930 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 931 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 932 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 933 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 934 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 935 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 936 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 937 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 938 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 939 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 940 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 941 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 942 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 943 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 944 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 945 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 946 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 947 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 948 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 949 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 950 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 951 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 952 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 953 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 954 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 955 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 956 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 957 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 958 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 959 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 960 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 961 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
| 962 | + 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
| 963 | + ]; |
|
| 964 | + foreach ($aliases as $alias => $fqn) { |
|
| 965 | + if (is_array($fqn)) { |
|
| 966 | + foreach ($fqn as $class => $for_class) { |
|
| 967 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 968 | + } |
|
| 969 | + continue; |
|
| 970 | + } |
|
| 971 | + $this->class_cache->addAlias($fqn, $alias); |
|
| 972 | + } |
|
| 973 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 974 | + $this->class_cache->addAlias( |
|
| 975 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 976 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 977 | + ); |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 984 | + * request Primarily used by unit tests. |
|
| 985 | + */ |
|
| 986 | + public function reset() |
|
| 987 | + { |
|
| 988 | + $this->_register_core_class_loaders(); |
|
| 989 | + $this->_register_core_dependencies(); |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
| 995 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 996 | + * WHY? |
|
| 997 | + * Because if a class is type hinting for a concretion, |
|
| 998 | + * then why would we need to find another class to supply it? |
|
| 999 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 1000 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 1001 | + * Don't go looking for some substitute. |
|
| 1002 | + * Whereas if a class is type hinting for an interface... |
|
| 1003 | + * then we need to find an actual class to use. |
|
| 1004 | + * So the interface IS the alias for some other FQN, |
|
| 1005 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 1006 | + * represents some other class. |
|
| 1007 | + * |
|
| 1008 | + * @param string $fqn |
|
| 1009 | + * @param string $for_class |
|
| 1010 | + * @return bool |
|
| 1011 | + * @deprecated 4.9.62.p |
|
| 1012 | + */ |
|
| 1013 | + public function has_alias($fqn = '', $for_class = '') |
|
| 1014 | + { |
|
| 1015 | + return $this->isAlias($fqn, $for_class); |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 1021 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 1022 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 1023 | + * for example: |
|
| 1024 | + * if the following two entries were added to the _aliases array: |
|
| 1025 | + * array( |
|
| 1026 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 1027 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 1028 | + * ) |
|
| 1029 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 1030 | + * to load an instance of 'some\namespace\classname' |
|
| 1031 | + * |
|
| 1032 | + * @param string $alias |
|
| 1033 | + * @param string $for_class |
|
| 1034 | + * @return string |
|
| 1035 | + * @deprecated 4.9.62.p |
|
| 1036 | + */ |
|
| 1037 | + public function get_alias($alias = '', $for_class = '') |
|
| 1038 | + { |
|
| 1039 | + return $this->getFqnForAlias($alias, $for_class); |
|
| 1040 | + } |
|
| 1041 | 1041 | } |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | ) { |
| 206 | 206 | $class = trim($class, '\\'); |
| 207 | 207 | $registered = false; |
| 208 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
| 209 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
| 208 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[$class])) { |
|
| 209 | + EE_Dependency_Map::$_instance->_dependency_map[$class] = []; |
|
| 210 | 210 | } |
| 211 | 211 | // we need to make sure that any aliases used when registering a dependency |
| 212 | 212 | // get resolved to the correct class name |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
| 215 | 215 | if ( |
| 216 | 216 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
| 217 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 217 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[$class][$alias]) |
|
| 218 | 218 | ) { |
| 219 | - unset($dependencies[ $dependency ]); |
|
| 220 | - $dependencies[ $alias ] = $load_source; |
|
| 219 | + unset($dependencies[$dependency]); |
|
| 220 | + $dependencies[$alias] = $load_source; |
|
| 221 | 221 | $registered = true; |
| 222 | 222 | } |
| 223 | 223 | } |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
| 228 | 228 | // Union is way faster than array_merge() but should be used with caution... |
| 229 | 229 | // especially with numerically indexed arrays |
| 230 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
| 230 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[$class]; |
|
| 231 | 231 | // now we need to ensure that the resulting dependencies |
| 232 | 232 | // array only has the entries that are required for the class |
| 233 | 233 | // so first count how many dependencies were originally registered for the class |
| 234 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
| 234 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[$class]); |
|
| 235 | 235 | // if that count is non-zero (meaning dependencies were already registered) |
| 236 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 236 | + EE_Dependency_Map::$_instance->_dependency_map[$class] = $dependency_count |
|
| 237 | 237 | // then truncate the final array to match that count |
| 238 | 238 | ? array_slice($dependencies, 0, $dependency_count) |
| 239 | 239 | // otherwise just take the incoming array because nothing previously existed |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | public function registerClassLoader($class_name, $loader = 'load_core') |
| 264 | 264 | { |
| 265 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 265 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 266 | 266 | throw new DomainException( |
| 267 | 267 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
| 268 | 268 | ); |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | ); |
| 287 | 287 | } |
| 288 | 288 | $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
| 289 | - if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
| 290 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 289 | + if ( ! isset(EE_Dependency_Map::$_instance->_class_loaders[$class_name])) { |
|
| 290 | + EE_Dependency_Map::$_instance->_class_loaders[$class_name] = $loader; |
|
| 291 | 291 | return true; |
| 292 | 292 | } |
| 293 | 293 | return false; |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | if (strpos($class_name, 'EEM_') === 0) { |
| 316 | 316 | $class_name = 'LEGACY_MODELS'; |
| 317 | 317 | } |
| 318 | - return isset($this->_dependency_map[ $class_name ]); |
|
| 318 | + return isset($this->_dependency_map[$class_name]); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $class_name = 'LEGACY_MODELS'; |
| 334 | 334 | } |
| 335 | 335 | $dependency = $this->getFqnForAlias($dependency, $class_name); |
| 336 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
| 336 | + return isset($this->_dependency_map[$class_name][$dependency]); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | } |
| 353 | 353 | $dependency = $this->getFqnForAlias($dependency); |
| 354 | 354 | return $this->has_dependency_for_class($class_name, $dependency) |
| 355 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 355 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 356 | 356 | : EE_Dependency_Map::not_registered; |
| 357 | 357 | } |
| 358 | 358 | |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | return 'load_core'; |
| 377 | 377 | } |
| 378 | 378 | $class_name = $this->getFqnForAlias($class_name); |
| 379 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 379 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | { |
| 791 | 791 | $this->_class_loaders = [ |
| 792 | 792 | // load_core |
| 793 | - 'EE_Dependency_Map' => function () { |
|
| 793 | + 'EE_Dependency_Map' => function() { |
|
| 794 | 794 | return $this; |
| 795 | 795 | }, |
| 796 | 796 | 'EE_Capabilities' => 'load_core', |
@@ -798,13 +798,13 @@ discard block |
||
| 798 | 798 | 'EE_Front_Controller' => 'load_core', |
| 799 | 799 | 'EE_Module_Request_Router' => 'load_core', |
| 800 | 800 | 'EE_Registry' => 'load_core', |
| 801 | - 'EE_Request' => function () { |
|
| 801 | + 'EE_Request' => function() { |
|
| 802 | 802 | return $this->legacy_request; |
| 803 | 803 | }, |
| 804 | - 'EventEspresso\core\services\request\Request' => function () { |
|
| 804 | + 'EventEspresso\core\services\request\Request' => function() { |
|
| 805 | 805 | return $this->request; |
| 806 | 806 | }, |
| 807 | - 'EventEspresso\core\services\request\Response' => function () { |
|
| 807 | + 'EventEspresso\core\services\request\Response' => function() { |
|
| 808 | 808 | return $this->response; |
| 809 | 809 | }, |
| 810 | 810 | 'EE_Base' => 'load_core', |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | 'EE_DMS_Core_4_9_0' => 'load_dms', |
| 841 | 841 | 'EE_DMS_Core_4_10_0' => 'load_dms', |
| 842 | 842 | 'EE_DMS_Core_4_11_0' => 'load_dms', |
| 843 | - 'EE_Messages_Generator' => static function () { |
|
| 843 | + 'EE_Messages_Generator' => static function() { |
|
| 844 | 844 | return EE_Registry::instance()->load_lib( |
| 845 | 845 | 'Messages_Generator', |
| 846 | 846 | [], |
@@ -848,7 +848,7 @@ discard block |
||
| 848 | 848 | false |
| 849 | 849 | ); |
| 850 | 850 | }, |
| 851 | - 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
| 851 | + 'EE_Messages_Template_Defaults' => static function($arguments = []) { |
|
| 852 | 852 | return EE_Registry::instance()->load_lib( |
| 853 | 853 | 'Messages_Template_Defaults', |
| 854 | 854 | $arguments, |
@@ -857,55 +857,55 @@ discard block |
||
| 857 | 857 | ); |
| 858 | 858 | }, |
| 859 | 859 | // load_helper |
| 860 | - 'EEH_Parse_Shortcodes' => static function () { |
|
| 860 | + 'EEH_Parse_Shortcodes' => static function() { |
|
| 861 | 861 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 862 | 862 | return new EEH_Parse_Shortcodes(); |
| 863 | 863 | } |
| 864 | 864 | return null; |
| 865 | 865 | }, |
| 866 | - 'EE_Template_Config' => static function () { |
|
| 866 | + 'EE_Template_Config' => static function() { |
|
| 867 | 867 | return EE_Config::instance()->template_settings; |
| 868 | 868 | }, |
| 869 | - 'EE_Currency_Config' => static function () { |
|
| 869 | + 'EE_Currency_Config' => static function() { |
|
| 870 | 870 | return EE_Config::instance()->currency; |
| 871 | 871 | }, |
| 872 | - 'EE_Registration_Config' => static function () { |
|
| 872 | + 'EE_Registration_Config' => static function() { |
|
| 873 | 873 | return EE_Config::instance()->registration; |
| 874 | 874 | }, |
| 875 | - 'EE_Core_Config' => static function () { |
|
| 875 | + 'EE_Core_Config' => static function() { |
|
| 876 | 876 | return EE_Config::instance()->core; |
| 877 | 877 | }, |
| 878 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
| 878 | + 'EventEspresso\core\services\loaders\Loader' => static function() { |
|
| 879 | 879 | return LoaderFactory::getLoader(); |
| 880 | 880 | }, |
| 881 | - 'EE_Network_Config' => static function () { |
|
| 881 | + 'EE_Network_Config' => static function() { |
|
| 882 | 882 | return EE_Network_Config::instance(); |
| 883 | 883 | }, |
| 884 | - 'EE_Config' => static function () { |
|
| 884 | + 'EE_Config' => static function() { |
|
| 885 | 885 | return EE_Config::instance(); |
| 886 | 886 | }, |
| 887 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
| 887 | + 'EventEspresso\core\domain\Domain' => static function() { |
|
| 888 | 888 | return DomainFactory::getEventEspressoCoreDomain(); |
| 889 | 889 | }, |
| 890 | - 'EE_Admin_Config' => static function () { |
|
| 890 | + 'EE_Admin_Config' => static function() { |
|
| 891 | 891 | return EE_Config::instance()->admin; |
| 892 | 892 | }, |
| 893 | - 'EE_Organization_Config' => static function () { |
|
| 893 | + 'EE_Organization_Config' => static function() { |
|
| 894 | 894 | return EE_Config::instance()->organization; |
| 895 | 895 | }, |
| 896 | - 'EE_Network_Core_Config' => static function () { |
|
| 896 | + 'EE_Network_Core_Config' => static function() { |
|
| 897 | 897 | return EE_Network_Config::instance()->core; |
| 898 | 898 | }, |
| 899 | - 'EE_Environment_Config' => static function () { |
|
| 899 | + 'EE_Environment_Config' => static function() { |
|
| 900 | 900 | return EE_Config::instance()->environment; |
| 901 | 901 | }, |
| 902 | - 'EED_Core_Rest_Api' => static function () { |
|
| 902 | + 'EED_Core_Rest_Api' => static function() { |
|
| 903 | 903 | return EED_Core_Rest_Api::instance(); |
| 904 | 904 | }, |
| 905 | - 'WP_REST_Server' => static function () { |
|
| 905 | + 'WP_REST_Server' => static function() { |
|
| 906 | 906 | return rest_get_server(); |
| 907 | 907 | }, |
| 908 | - 'EventEspresso\core\Psr4Autoloader' => static function () { |
|
| 908 | + 'EventEspresso\core\Psr4Autoloader' => static function() { |
|
| 909 | 909 | return EE_Psr4AutoloaderInit::psr4_loader(); |
| 910 | 910 | }, |
| 911 | 911 | ]; |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | } |
| 971 | 971 | $this->class_cache->addAlias($fqn, $alias); |
| 972 | 972 | } |
| 973 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 973 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 974 | 974 | $this->class_cache->addAlias( |
| 975 | 975 | 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
| 976 | 976 | 'EventEspresso\core\services\notices\NoticeConverterInterface' |
@@ -25,1166 +25,1166 @@ |
||
| 25 | 25 | final class EE_System implements ResettableInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 30 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 31 | - */ |
|
| 32 | - const req_type_normal = 0; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Indicates this is a brand new installation of EE so we should install |
|
| 36 | - * tables and default data etc |
|
| 37 | - */ |
|
| 38 | - const req_type_new_activation = 1; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 42 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 43 | - * and that default data is setup too |
|
| 44 | - */ |
|
| 45 | - const req_type_reactivation = 2; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * indicates that EE has been upgraded since its previous request. |
|
| 49 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 50 | - */ |
|
| 51 | - const req_type_upgrade = 3; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 55 | - */ |
|
| 56 | - const req_type_downgrade = 4; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @deprecated since version 4.6.0.dev.006 |
|
| 60 | - * Now whenever a new_activation is detected the request type is still just |
|
| 61 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we're in maintenance mode |
|
| 62 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 63 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 64 | - * (Specifically, when the migration manager indicates migrations are finished |
|
| 65 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 66 | - */ |
|
| 67 | - const req_type_activation_but_not_installed = 5; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 71 | - */ |
|
| 72 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @var AddonManager $addon_manager |
|
| 76 | - */ |
|
| 77 | - private $addon_manager; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @var EE_System $_instance |
|
| 81 | - */ |
|
| 82 | - private static $_instance; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @var EE_Registry $registry |
|
| 86 | - */ |
|
| 87 | - private $registry; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @var LoaderInterface $loader |
|
| 91 | - */ |
|
| 92 | - private $loader; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @var EE_Capabilities $capabilities |
|
| 96 | - */ |
|
| 97 | - private $capabilities; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
| 101 | - */ |
|
| 102 | - private $maintenance_mode; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @var RequestInterface $request |
|
| 106 | - */ |
|
| 107 | - private $request; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 111 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 112 | - * |
|
| 113 | - * @var int $_req_type |
|
| 114 | - */ |
|
| 115 | - private $_req_type; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
| 119 | - * |
|
| 120 | - * @var boolean $_major_version_change |
|
| 121 | - */ |
|
| 122 | - private $_major_version_change = false; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @var Router $router |
|
| 126 | - */ |
|
| 127 | - private $router; |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @singleton method used to instantiate class object |
|
| 132 | - * @param LoaderInterface|null $loader |
|
| 133 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
| 134 | - * @param EE_Registry|null $registry |
|
| 135 | - * @param RequestInterface|null $request |
|
| 136 | - * @param Router|null $router |
|
| 137 | - * @return EE_System |
|
| 138 | - */ |
|
| 139 | - public static function instance( |
|
| 140 | - LoaderInterface $loader = null, |
|
| 141 | - EE_Maintenance_Mode $maintenance_mode = null, |
|
| 142 | - EE_Registry $registry = null, |
|
| 143 | - RequestInterface $request = null, |
|
| 144 | - Router $router = null |
|
| 145 | - ): EE_System { |
|
| 146 | - // check if class object is instantiated |
|
| 147 | - if (! self::$_instance instanceof EE_System) { |
|
| 148 | - self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router); |
|
| 149 | - } |
|
| 150 | - return self::$_instance; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * resets the instance and returns it |
|
| 156 | - * |
|
| 157 | - * @return EE_System |
|
| 158 | - */ |
|
| 159 | - public static function reset(): EE_System |
|
| 160 | - { |
|
| 161 | - self::$_instance->_req_type = null; |
|
| 162 | - // make sure none of the old hooks are left hanging around |
|
| 163 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 164 | - // we need to reset the migration manager in order for it to detect DMSs properly |
|
| 165 | - EE_Data_Migration_Manager::reset(); |
|
| 166 | - self::instance()->detect_activations_or_upgrades(); |
|
| 167 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 168 | - return self::instance(); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * sets hooks for running rest of system |
|
| 174 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 175 | - * starting EE Addons from any other point may lead to problems |
|
| 176 | - * |
|
| 177 | - * @param LoaderInterface $loader |
|
| 178 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
| 179 | - * @param EE_Registry $registry |
|
| 180 | - * @param RequestInterface $request |
|
| 181 | - * @param Router $router |
|
| 182 | - */ |
|
| 183 | - private function __construct( |
|
| 184 | - LoaderInterface $loader, |
|
| 185 | - EE_Maintenance_Mode $maintenance_mode, |
|
| 186 | - EE_Registry $registry, |
|
| 187 | - RequestInterface $request, |
|
| 188 | - Router $router |
|
| 189 | - ) { |
|
| 190 | - $this->registry = $registry; |
|
| 191 | - $this->loader = $loader; |
|
| 192 | - $this->request = $request; |
|
| 193 | - $this->router = $router; |
|
| 194 | - $this->maintenance_mode = $maintenance_mode; |
|
| 195 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
| 196 | - add_action( |
|
| 197 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 198 | - [$this, 'loadCapabilities'], |
|
| 199 | - 5 |
|
| 200 | - ); |
|
| 201 | - add_action( |
|
| 202 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 203 | - [$this, 'loadCommandBus'], |
|
| 204 | - 7 |
|
| 205 | - ); |
|
| 206 | - add_action( |
|
| 207 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 208 | - [$this, 'loadPluginApi'], |
|
| 209 | - 9 |
|
| 210 | - ); |
|
| 211 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 212 | - add_action( |
|
| 213 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 214 | - [$this, 'load_espresso_addons'] |
|
| 215 | - ); |
|
| 216 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
| 217 | - // because the newly-activated addon didn't get a chance to run at all |
|
| 218 | - add_action('activate_plugin', [$this, 'load_espresso_addons'], 1); |
|
| 219 | - // detect whether install or upgrade |
|
| 220 | - add_action( |
|
| 221 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 222 | - [$this, 'detect_activations_or_upgrades'], |
|
| 223 | - 3 |
|
| 224 | - ); |
|
| 225 | - // load EE_Config, EE_Textdomain, etc |
|
| 226 | - add_action( |
|
| 227 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 228 | - [$this, 'load_core_configuration'], |
|
| 229 | - 5 |
|
| 230 | - ); |
|
| 231 | - // load specifications for matching routes to current request |
|
| 232 | - add_action( |
|
| 233 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 234 | - [$this, 'loadRouteMatchSpecifications'] |
|
| 235 | - ); |
|
| 236 | - // load EE_Config, EE_Textdomain, etc |
|
| 237 | - add_action( |
|
| 238 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 239 | - [$this, 'register_shortcodes_modules_and_widgets'], |
|
| 240 | - 7 |
|
| 241 | - ); |
|
| 242 | - // you wanna get going? I wanna get going... let's get going! |
|
| 243 | - add_action( |
|
| 244 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 245 | - [$this, 'brew_espresso'], |
|
| 246 | - 9 |
|
| 247 | - ); |
|
| 248 | - // other housekeeping |
|
| 249 | - // exclude EE critical pages from wp_list_pages |
|
| 250 | - add_filter( |
|
| 251 | - 'wp_list_pages_excludes', |
|
| 252 | - [$this, 'remove_pages_from_wp_list_pages'], |
|
| 253 | - 10 |
|
| 254 | - ); |
|
| 255 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 256 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 257 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * load and setup EE_Capabilities |
|
| 263 | - * |
|
| 264 | - * @return void |
|
| 265 | - */ |
|
| 266 | - public function loadCapabilities() |
|
| 267 | - { |
|
| 268 | - $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
| 269 | - add_action( |
|
| 270 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 271 | - function () { |
|
| 272 | - LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
| 273 | - } |
|
| 274 | - ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * create and cache the CommandBus, and also add middleware |
|
| 280 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
| 281 | - * which is why we need to load the CommandBus after Caps are set up |
|
| 282 | - * |
|
| 283 | - * @return void |
|
| 284 | - */ |
|
| 285 | - public function loadCommandBus() |
|
| 286 | - { |
|
| 287 | - $this->loader->getShared( |
|
| 288 | - 'CommandBusInterface', |
|
| 289 | - [ |
|
| 290 | - null, |
|
| 291 | - apply_filters( |
|
| 292 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 293 | - [ |
|
| 294 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
| 295 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
| 296 | - ] |
|
| 297 | - ), |
|
| 298 | - ] |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * @return void |
|
| 305 | - * @throws Exception |
|
| 306 | - */ |
|
| 307 | - public function loadPluginApi() |
|
| 308 | - { |
|
| 309 | - $this->addon_manager = $this->loader->getShared(AddonManager::class); |
|
| 310 | - $this->addon_manager->initialize(); |
|
| 311 | - $this->loader->getShared('EE_Request_Handler'); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * load_espresso_addons |
|
| 317 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 318 | - * this is hooked into both: |
|
| 319 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 320 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 321 | - * and the WP 'activate_plugin' hook point |
|
| 322 | - * |
|
| 323 | - * @return void |
|
| 324 | - * @throws Exception |
|
| 325 | - */ |
|
| 326 | - public function load_espresso_addons() |
|
| 327 | - { |
|
| 328 | - // looking for hooks? they've been moved into the AddonManager to maintain compatibility |
|
| 329 | - $this->addon_manager->loadAddons(); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * detect_activations_or_upgrades |
|
| 335 | - * Checks for activation or upgrade of core first; |
|
| 336 | - * then also checks if any registered addons have been activated or upgraded |
|
| 337 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 338 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 339 | - * |
|
| 340 | - * @access public |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - public function detect_activations_or_upgrades() |
|
| 344 | - { |
|
| 345 | - // first off: let's make sure to handle core |
|
| 346 | - $this->detect_if_activation_or_upgrade(); |
|
| 347 | - foreach ($this->registry->addons as $addon) { |
|
| 348 | - if ($addon instanceof EE_Addon) { |
|
| 349 | - // detect teh request type for that addon |
|
| 350 | - $addon->detect_activation_or_upgrade(); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * detect_if_activation_or_upgrade |
|
| 358 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 359 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 360 | - * |
|
| 361 | - * @access public |
|
| 362 | - * @return void |
|
| 363 | - */ |
|
| 364 | - public function detect_if_activation_or_upgrade() |
|
| 365 | - { |
|
| 366 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 367 | - // check if db has been updated, or if its a brand-new installation |
|
| 368 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 369 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
| 370 | - // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 371 | - switch ($request_type) { |
|
| 372 | - case EE_System::req_type_new_activation: |
|
| 373 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 374 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 375 | - break; |
|
| 376 | - case EE_System::req_type_reactivation: |
|
| 377 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 378 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 379 | - break; |
|
| 380 | - case EE_System::req_type_upgrade: |
|
| 381 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 382 | - // migrations may be required now that we've upgraded |
|
| 383 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 384 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 385 | - break; |
|
| 386 | - case EE_System::req_type_downgrade: |
|
| 387 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 388 | - // its possible migrations are no longer required |
|
| 389 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 390 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 391 | - break; |
|
| 392 | - case EE_System::req_type_normal: |
|
| 393 | - default: |
|
| 394 | - break; |
|
| 395 | - } |
|
| 396 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Updates the list of installed versions and sets hooks for |
|
| 402 | - * initializing the database later during the request |
|
| 403 | - * |
|
| 404 | - * @param array $espresso_db_update |
|
| 405 | - */ |
|
| 406 | - private function _handle_core_version_change(array $espresso_db_update) |
|
| 407 | - { |
|
| 408 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
| 409 | - // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 410 | - add_action( |
|
| 411 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 412 | - [$this, 'initialize_db_if_no_migrations_required'] |
|
| 413 | - ); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 419 | - * information about what versions of EE have been installed and activated, |
|
| 420 | - * NOT necessarily the state of the database |
|
| 421 | - * |
|
| 422 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 423 | - * If not supplied, fetches it from the options table |
|
| 424 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 425 | - */ |
|
| 426 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null): array |
|
| 427 | - { |
|
| 428 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 429 | - if (! $espresso_db_update) { |
|
| 430 | - $espresso_db_update = get_option('espresso_db_update'); |
|
| 431 | - } |
|
| 432 | - // check that option is an array |
|
| 433 | - if (! is_array($espresso_db_update)) { |
|
| 434 | - // if option is FALSE, then it never existed |
|
| 435 | - if ($espresso_db_update === false) { |
|
| 436 | - // make $espresso_db_update an array and save option with autoload OFF |
|
| 437 | - $espresso_db_update = []; |
|
| 438 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 439 | - } else { |
|
| 440 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 441 | - $espresso_db_update = [$espresso_db_update => []]; |
|
| 442 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 443 | - } |
|
| 444 | - } else { |
|
| 445 | - $corrected_db_update = []; |
|
| 446 | - // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 447 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 448 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 449 | - // the key is an int, and the value IS NOT an array |
|
| 450 | - // so it must be numerically-indexed, where values are versions installed... |
|
| 451 | - // fix it! |
|
| 452 | - $version_string = $should_be_array; |
|
| 453 | - $corrected_db_update[ $version_string ] = ['unknown-date']; |
|
| 454 | - } else { |
|
| 455 | - // ok it checks out |
|
| 456 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - $espresso_db_update = $corrected_db_update; |
|
| 460 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 461 | - } |
|
| 462 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 463 | - return ! empty($espresso_db_update) ? $espresso_db_update : []; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 469 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 470 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 471 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 472 | - * so that it will be done when migrations are finished |
|
| 473 | - * |
|
| 474 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 475 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 476 | - * This is a resource-intensive job |
|
| 477 | - * so we prefer to only do it when necessary |
|
| 478 | - * @return void |
|
| 479 | - * @throws EE_Error |
|
| 480 | - * @throws ReflectionException |
|
| 481 | - */ |
|
| 482 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 483 | - { |
|
| 484 | - $request_type = $this->detect_req_type(); |
|
| 485 | - // only initialize system if we're not in maintenance mode. |
|
| 486 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 487 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 488 | - $rewrite_rules = $this->loader->getShared( |
|
| 489 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 490 | - ); |
|
| 491 | - $rewrite_rules->flush(); |
|
| 492 | - if ($verify_schema) { |
|
| 493 | - EEH_Activation::initialize_db_and_folders(); |
|
| 494 | - } |
|
| 495 | - EEH_Activation::initialize_db_content(); |
|
| 496 | - EEH_Activation::system_initialization(); |
|
| 497 | - if ($initialize_addons_too) { |
|
| 498 | - $this->initialize_addons(); |
|
| 499 | - } |
|
| 500 | - } else { |
|
| 501 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 502 | - } |
|
| 503 | - if ( |
|
| 504 | - $request_type === EE_System::req_type_new_activation |
|
| 505 | - || $request_type === EE_System::req_type_reactivation |
|
| 506 | - || ( |
|
| 507 | - $request_type === EE_System::req_type_upgrade |
|
| 508 | - && $this->is_major_version_change() |
|
| 509 | - ) |
|
| 510 | - ) { |
|
| 511 | - add_action('AHEE__EE_System__initialize_last', [$this, 'redirect_to_about_ee'], 9); |
|
| 512 | - } |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Initializes the db for all registered addons |
|
| 518 | - * |
|
| 519 | - * @throws EE_Error |
|
| 520 | - * @throws ReflectionException |
|
| 521 | - */ |
|
| 522 | - public function initialize_addons() |
|
| 523 | - { |
|
| 524 | - // foreach registered addon, make sure its db is up-to-date too |
|
| 525 | - foreach ($this->registry->addons as $addon) { |
|
| 526 | - if ($addon instanceof EE_Addon) { |
|
| 527 | - $addon->initialize_db_if_no_migrations_required(); |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 535 | - * |
|
| 536 | - * @param array $version_history |
|
| 537 | - * @param string $current_version_to_add version to be added to the version history |
|
| 538 | - * @return boolean success as to whether or not this option was changed |
|
| 539 | - */ |
|
| 540 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool |
|
| 541 | - { |
|
| 542 | - if (! $version_history) { |
|
| 543 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 544 | - } |
|
| 545 | - if ($current_version_to_add === null) { |
|
| 546 | - $current_version_to_add = espresso_version(); |
|
| 547 | - } |
|
| 548 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
| 549 | - // re-save |
|
| 550 | - return update_option('espresso_db_update', $version_history); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Detects if the current version indicated in the has existed in the list of |
|
| 556 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 557 | - * |
|
| 558 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 559 | - * If not supplied, fetches it from the options table. |
|
| 560 | - * Also, caches its result so later parts of the code can also know whether |
|
| 561 | - * there's been an update or not. This way we can add the current version to |
|
| 562 | - * espresso_db_update, but still know if this is a new install or not |
|
| 563 | - * @return int one of the constants on EE_System::req_type_ |
|
| 564 | - */ |
|
| 565 | - public function detect_req_type($espresso_db_update = null): int |
|
| 566 | - { |
|
| 567 | - if ($this->_req_type === null) { |
|
| 568 | - $espresso_db_update = ! empty($espresso_db_update) |
|
| 569 | - ? $espresso_db_update |
|
| 570 | - : $this->fix_espresso_db_upgrade_option(); |
|
| 571 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
| 572 | - $espresso_db_update, |
|
| 573 | - 'ee_espresso_activation', |
|
| 574 | - espresso_version() |
|
| 575 | - ); |
|
| 576 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 577 | - $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
| 578 | - } |
|
| 579 | - return $this->_req_type; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 585 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 586 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 587 | - * |
|
| 588 | - * @param $activation_history |
|
| 589 | - * @return bool |
|
| 590 | - */ |
|
| 591 | - private function _detect_major_version_change($activation_history): bool |
|
| 592 | - { |
|
| 593 | - $previous_version = EE_System::getMostRecentlyActiveVersion($activation_history); |
|
| 594 | - $previous_version_parts = explode('.', $previous_version); |
|
| 595 | - $current_version_parts = explode('.', espresso_version()); |
|
| 596 | - return isset( |
|
| 597 | - $previous_version_parts[0], |
|
| 598 | - $previous_version_parts[1], |
|
| 599 | - $current_version_parts[0], |
|
| 600 | - $current_version_parts[1] |
|
| 601 | - ) && ( |
|
| 602 | - $previous_version_parts[0] !== $current_version_parts[0] |
|
| 603 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 604 | - ); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Returns true if either the major or minor version of EE changed during this request. |
|
| 610 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 611 | - * |
|
| 612 | - * @return bool |
|
| 613 | - */ |
|
| 614 | - public function is_major_version_change(): bool |
|
| 615 | - { |
|
| 616 | - return $this->_major_version_change; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 622 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 623 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 624 | - * just activated to (for core that will always be espresso_version()) |
|
| 625 | - * |
|
| 626 | - * @param array|null $activation_history the option's value which stores the activation history for |
|
| 627 | - * this |
|
| 628 | - * ee plugin. for core that's 'espresso_db_update' |
|
| 629 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 630 | - * indicate that this plugin was just activated |
|
| 631 | - * @param string $current_version the version that was just upgraded to (for core that will be |
|
| 632 | - * espresso_version()) |
|
| 633 | - * @return int one of the constants on EE_System::req_type_ |
|
| 634 | - */ |
|
| 635 | - public static function detect_req_type_given_activation_history( |
|
| 636 | - array $activation_history, |
|
| 637 | - string $activation_indicator_option_name, |
|
| 638 | - string $current_version |
|
| 639 | - ): int { |
|
| 640 | - $version_change = self::compareVersionWithPrevious($activation_history, $current_version); |
|
| 641 | - $is_activation = get_option($activation_indicator_option_name, false); |
|
| 642 | - $req_type = self::getRequestType($activation_history, $version_change, $is_activation); |
|
| 643 | - if ($is_activation) { |
|
| 644 | - // cleanup in aisle 6 |
|
| 645 | - delete_option($activation_indicator_option_name); |
|
| 646 | - } |
|
| 647 | - return $req_type; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * @param array $activation_history |
|
| 653 | - * @param int $version_change |
|
| 654 | - * @param bool $is_activation |
|
| 655 | - * @return int |
|
| 656 | - * @since $VID:$ |
|
| 657 | - */ |
|
| 658 | - private static function getRequestType(array $activation_history, int $version_change, bool $is_activation): int |
|
| 659 | - { |
|
| 660 | - // if no previous activation history exists, then this is a brand new install |
|
| 661 | - if (empty($activation_history)) { |
|
| 662 | - return EE_System::req_type_new_activation; |
|
| 663 | - } |
|
| 664 | - // current version is higher than previous version, so it's an upgrade |
|
| 665 | - if ($version_change === 1) { |
|
| 666 | - return EE_System::req_type_upgrade; |
|
| 667 | - } |
|
| 668 | - // current version is lower than previous version, so it's a downgrade |
|
| 669 | - if ($version_change === -1) { |
|
| 670 | - return EE_System::req_type_downgrade; |
|
| 671 | - } |
|
| 672 | - // version hasn't changed since last version so check if the activation indicator is set |
|
| 673 | - // to determine if it's a reactivation, or just a normal request |
|
| 674 | - return $is_activation |
|
| 675 | - ? EE_System::req_type_reactivation |
|
| 676 | - : EE_System::req_type_normal; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 682 | - * the $activation_history_for_addon |
|
| 683 | - * |
|
| 684 | - * @param array $activation_history array where keys are versions, |
|
| 685 | - * values are arrays of times activated (sometimes 'unknown-date') |
|
| 686 | - * @param string $current_version |
|
| 687 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 688 | - * -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 689 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 690 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 691 | - */ |
|
| 692 | - private static function compareVersionWithPrevious(array $activation_history, string $current_version): int |
|
| 693 | - { |
|
| 694 | - // find the most recently-activated version |
|
| 695 | - $most_recently_active_version = EE_System::getMostRecentlyActiveVersion($activation_history); |
|
| 696 | - return version_compare($current_version, $most_recently_active_version); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Gets the most recently active version listed in the activation history, |
|
| 702 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 703 | - * |
|
| 704 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 705 | - * sometimes containing 'unknown-date' |
|
| 706 | - * @return string |
|
| 707 | - */ |
|
| 708 | - private static function getMostRecentlyActiveVersion(array $activation_history): string |
|
| 709 | - { |
|
| 710 | - $most_recent_activation_date = '1970-01-01 00:00:00'; |
|
| 711 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
| 712 | - if (is_array($activation_history)) { |
|
| 713 | - foreach ($activation_history as $version => $activation_dates) { |
|
| 714 | - // check there is a record of when this version was activated. |
|
| 715 | - // Otherwise, mark it as unknown |
|
| 716 | - if (! $activation_dates) { |
|
| 717 | - $activation_dates = ['unknown-date']; |
|
| 718 | - } |
|
| 719 | - $activation_dates = is_string($activation_dates) ? [$activation_dates] : $activation_dates; |
|
| 720 | - foreach ($activation_dates as $activation_date) { |
|
| 721 | - if ($activation_date !== 'unknown-date' && $activation_date > $most_recent_activation_date) { |
|
| 722 | - $most_recently_active_version = $version; |
|
| 723 | - $most_recent_activation_date = $activation_date; |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - return $most_recently_active_version; |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * This redirects to the about EE page after activation |
|
| 734 | - * |
|
| 735 | - * @return void |
|
| 736 | - */ |
|
| 737 | - public function redirect_to_about_ee() |
|
| 738 | - { |
|
| 739 | - $notices = EE_Error::get_notices(false); |
|
| 740 | - // if current user is an admin and it's not an ajax or rest request |
|
| 741 | - if ( |
|
| 742 | - ! isset($notices['errors']) |
|
| 743 | - && $this->request->isAdmin() |
|
| 744 | - && apply_filters( |
|
| 745 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 746 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
| 747 | - ) |
|
| 748 | - ) { |
|
| 749 | - $query_params = ['page' => 'espresso_about']; |
|
| 750 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 751 | - $query_params['new_activation'] = true; |
|
| 752 | - } |
|
| 753 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 754 | - $query_params['reactivation'] = true; |
|
| 755 | - } |
|
| 756 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 757 | - EEH_URL::safeRedirectAndExit($url); |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * load_core_configuration |
|
| 764 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 765 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 766 | - * |
|
| 767 | - * @return void |
|
| 768 | - * @throws ReflectionException |
|
| 769 | - * @throws Exception |
|
| 770 | - */ |
|
| 771 | - public function load_core_configuration() |
|
| 772 | - { |
|
| 773 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 774 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
| 775 | - // load textdomain |
|
| 776 | - EE_Load_Textdomain::load_textdomain(); |
|
| 777 | - // load caf stuff a chance to play during the activation process too. |
|
| 778 | - $this->_maybe_brew_regular(); |
|
| 779 | - // load and setup EE_Config and EE_Network_Config |
|
| 780 | - $config = $this->loader->getShared('EE_Config'); |
|
| 781 | - $this->loader->getShared('EE_Network_Config'); |
|
| 782 | - // setup autoloaders |
|
| 783 | - // enable logging? |
|
| 784 | - if ($config->admin->use_remote_logging) { |
|
| 785 | - $this->loader->getShared('EE_Log'); |
|
| 786 | - } |
|
| 787 | - // check for activation errors |
|
| 788 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 789 | - if ($activation_errors) { |
|
| 790 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 791 | - update_option('ee_plugin_activation_errors', false); |
|
| 792 | - } |
|
| 793 | - // get model names |
|
| 794 | - $this->_parse_model_names(); |
|
| 795 | - // configure custom post type definitions |
|
| 796 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
| 797 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
| 798 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 804 | - * |
|
| 805 | - * @return void |
|
| 806 | - * @throws ReflectionException |
|
| 807 | - */ |
|
| 808 | - private function _parse_model_names() |
|
| 809 | - { |
|
| 810 | - // get all the files in the EE_MODELS folder that end in .model.php |
|
| 811 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 812 | - $model_names = []; |
|
| 813 | - $non_abstract_db_models = []; |
|
| 814 | - foreach ($models as $model) { |
|
| 815 | - // get model classname |
|
| 816 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 817 | - $short_name = str_replace('EEM_', '', $classname); |
|
| 818 | - $reflectionClass = new ReflectionClass($classname); |
|
| 819 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 820 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
| 821 | - } |
|
| 822 | - $model_names[ $short_name ] = $classname; |
|
| 823 | - } |
|
| 824 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 825 | - $this->registry->non_abstract_db_models = apply_filters( |
|
| 826 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
| 827 | - $non_abstract_db_models |
|
| 828 | - ); |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - |
|
| 832 | - /** |
|
| 833 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 834 | - * that need to be setup before our EE_System launches. |
|
| 835 | - * |
|
| 836 | - * @return void |
|
| 837 | - * @throws DomainException |
|
| 838 | - * @throws InvalidArgumentException |
|
| 839 | - * @throws InvalidDataTypeException |
|
| 840 | - * @throws InvalidInterfaceException |
|
| 841 | - * @throws InvalidClassException |
|
| 842 | - * @throws InvalidFilePathException |
|
| 843 | - */ |
|
| 844 | - private function _maybe_brew_regular() |
|
| 845 | - { |
|
| 846 | - /** @var Domain $domain */ |
|
| 847 | - $domain = DomainFactory::getEventEspressoCoreDomain(); |
|
| 848 | - if ($domain->isCaffeinated()) { |
|
| 849 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 850 | - } |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * @throws Exception |
|
| 856 | - * @since 4.9.71.p |
|
| 857 | - */ |
|
| 858 | - public function loadRouteMatchSpecifications() |
|
| 859 | - { |
|
| 860 | - try { |
|
| 861 | - $this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager'); |
|
| 862 | - $this->loader->getShared('EventEspresso\core\services\routing\RouteCollection'); |
|
| 863 | - $this->router->loadPrimaryRoutes(); |
|
| 864 | - } catch (Exception $exception) { |
|
| 865 | - new ExceptionStackTraceDisplay($exception); |
|
| 866 | - } |
|
| 867 | - do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * register_shortcodes_modules_and_widgets |
|
| 873 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
| 874 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 875 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 876 | - * |
|
| 877 | - * @access public |
|
| 878 | - * @return void |
|
| 879 | - * @throws Exception |
|
| 880 | - */ |
|
| 881 | - public function register_shortcodes_modules_and_widgets() |
|
| 882 | - { |
|
| 883 | - $this->router->registerShortcodesModulesAndWidgets(); |
|
| 884 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 885 | - // check for addons using old hook point |
|
| 886 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 887 | - $this->_incompatible_addon_error(); |
|
| 888 | - } |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * _incompatible_addon_error |
|
| 894 | - * |
|
| 895 | - * @access public |
|
| 896 | - * @return void |
|
| 897 | - */ |
|
| 898 | - private function _incompatible_addon_error() |
|
| 899 | - { |
|
| 900 | - // get array of classes hooking into here |
|
| 901 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
| 902 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
| 903 | - ); |
|
| 904 | - if (! empty($class_names)) { |
|
| 905 | - $msg = __( |
|
| 906 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 907 | - 'event_espresso' |
|
| 908 | - ); |
|
| 909 | - $msg .= '<ul>'; |
|
| 910 | - foreach ($class_names as $class_name) { |
|
| 911 | - $msg .= '<li><b>Event Espresso - ' |
|
| 912 | - . str_replace( |
|
| 913 | - ['EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'], |
|
| 914 | - '', |
|
| 915 | - $class_name |
|
| 916 | - ) . '</b></li>'; |
|
| 917 | - } |
|
| 918 | - $msg .= '</ul>'; |
|
| 919 | - $msg .= __( |
|
| 920 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 921 | - 'event_espresso' |
|
| 922 | - ); |
|
| 923 | - // save list of incompatible addons to wp-options for later use |
|
| 924 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 925 | - if (is_admin()) { |
|
| 926 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 927 | - } |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - |
|
| 932 | - /** |
|
| 933 | - * brew_espresso |
|
| 934 | - * begins the process of setting hooks for initializing EE in the correct order |
|
| 935 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 936 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 937 | - * |
|
| 938 | - * @return void |
|
| 939 | - * @throws Exception |
|
| 940 | - */ |
|
| 941 | - public function brew_espresso() |
|
| 942 | - { |
|
| 943 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 944 | - // load some final core systems |
|
| 945 | - add_action('init', [$this, 'set_hooks_for_core'], 1); |
|
| 946 | - add_action('init', [$this, 'perform_activations_upgrades_and_migrations'], 3); |
|
| 947 | - add_action('init', [$this, 'load_CPTs_and_session'], 5); |
|
| 948 | - add_action('init', [$this, 'load_controllers'], 7); |
|
| 949 | - add_action('init', [$this, 'core_loaded_and_ready'], 9); |
|
| 950 | - add_action('init', [$this, 'initialize'], 10); |
|
| 951 | - add_action('init', [$this, 'initialize_last'], 100); |
|
| 952 | - $this->router->brewEspresso(); |
|
| 953 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * set_hooks_for_core |
|
| 959 | - * |
|
| 960 | - * @access public |
|
| 961 | - * @return void |
|
| 962 | - * @throws EE_Error |
|
| 963 | - */ |
|
| 964 | - public function set_hooks_for_core() |
|
| 965 | - { |
|
| 966 | - $this->_deactivate_incompatible_addons(); |
|
| 967 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 968 | - $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
| 969 | - // caps need to be initialized on every request so that capability maps are set. |
|
| 970 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 971 | - $this->registry->CAP->init_caps(); |
|
| 972 | - } |
|
| 973 | - |
|
| 974 | - |
|
| 975 | - /** |
|
| 976 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 977 | - * deactivates any addons considered incompatible with the current version of EE |
|
| 978 | - */ |
|
| 979 | - private function _deactivate_incompatible_addons() |
|
| 980 | - { |
|
| 981 | - $incompatible_addons = get_option('ee_incompatible_addons', []); |
|
| 982 | - if (! empty($incompatible_addons)) { |
|
| 983 | - $active_plugins = get_option('active_plugins', []); |
|
| 984 | - foreach ($active_plugins as $active_plugin) { |
|
| 985 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
| 986 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 987 | - unset($_GET['activate']); |
|
| 988 | - espresso_deactivate_plugin($active_plugin); |
|
| 989 | - } |
|
| 990 | - } |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - |
|
| 996 | - /** |
|
| 997 | - * perform_activations_upgrades_and_migrations |
|
| 998 | - * |
|
| 999 | - * @access public |
|
| 1000 | - * @return void |
|
| 1001 | - */ |
|
| 1002 | - public function perform_activations_upgrades_and_migrations() |
|
| 1003 | - { |
|
| 1004 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - |
|
| 1008 | - /** |
|
| 1009 | - * @return void |
|
| 1010 | - * @throws DomainException |
|
| 1011 | - */ |
|
| 1012 | - public function load_CPTs_and_session() |
|
| 1013 | - { |
|
| 1014 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 1015 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */ |
|
| 1016 | - $register_custom_taxonomies = $this->loader->getShared( |
|
| 1017 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
| 1018 | - ); |
|
| 1019 | - $register_custom_taxonomies->registerCustomTaxonomies(); |
|
| 1020 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ |
|
| 1021 | - $register_custom_post_types = $this->loader->getShared( |
|
| 1022 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
| 1023 | - ); |
|
| 1024 | - $register_custom_post_types->registerCustomPostTypes(); |
|
| 1025 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */ |
|
| 1026 | - $register_custom_taxonomy_terms = $this->loader->getShared( |
|
| 1027 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
| 1028 | - ); |
|
| 1029 | - $register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
| 1030 | - // load legacy Custom Post Types and Taxonomies |
|
| 1031 | - $this->loader->getShared('EE_Register_CPTs'); |
|
| 1032 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - |
|
| 1036 | - /** |
|
| 1037 | - * load_controllers |
|
| 1038 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 1039 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 1040 | - * time |
|
| 1041 | - * |
|
| 1042 | - * @access public |
|
| 1043 | - * @return void |
|
| 1044 | - * @throws Exception |
|
| 1045 | - */ |
|
| 1046 | - public function load_controllers() |
|
| 1047 | - { |
|
| 1048 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
| 1049 | - $this->router->loadControllers(); |
|
| 1050 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * core_loaded_and_ready |
|
| 1056 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1057 | - * |
|
| 1058 | - * @access public |
|
| 1059 | - * @return void |
|
| 1060 | - * @throws Exception |
|
| 1061 | - */ |
|
| 1062 | - public function core_loaded_and_ready() |
|
| 1063 | - { |
|
| 1064 | - $this->router->coreLoadedAndReady(); |
|
| 1065 | - // integrate WP_Query with the EE models |
|
| 1066 | - $this->loader->getShared('EE_CPT_Strategy'); |
|
| 1067 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1068 | - // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
| 1069 | - // builders require these even on the front-end |
|
| 1070 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
| 1071 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * initialize |
|
| 1077 | - * this is the best place to begin initializing client code |
|
| 1078 | - * |
|
| 1079 | - * @access public |
|
| 1080 | - * @return void |
|
| 1081 | - */ |
|
| 1082 | - public function initialize() |
|
| 1083 | - { |
|
| 1084 | - do_action('AHEE__EE_System__initialize'); |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - |
|
| 1088 | - /** |
|
| 1089 | - * initialize_last |
|
| 1090 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1091 | - * initialize has done so |
|
| 1092 | - * |
|
| 1093 | - * @access public |
|
| 1094 | - * @return void |
|
| 1095 | - * @throws Exception |
|
| 1096 | - */ |
|
| 1097 | - public function initialize_last() |
|
| 1098 | - { |
|
| 1099 | - do_action('AHEE__EE_System__initialize_last'); |
|
| 1100 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 1101 | - $rewrite_rules = $this->loader->getShared( |
|
| 1102 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 1103 | - ); |
|
| 1104 | - $rewrite_rules->flushRewriteRules(); |
|
| 1105 | - $this->router->initializeLast(); |
|
| 1106 | - add_action('admin_bar_init', [$this, 'addEspressoToolbar']); |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * @return void |
|
| 1112 | - */ |
|
| 1113 | - public function addEspressoToolbar() |
|
| 1114 | - { |
|
| 1115 | - $this->loader->getShared( |
|
| 1116 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
| 1117 | - [$this->registry->CAP] |
|
| 1118 | - ); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - |
|
| 1122 | - /** |
|
| 1123 | - * do_not_cache |
|
| 1124 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 1125 | - * |
|
| 1126 | - * @access public |
|
| 1127 | - * @return void |
|
| 1128 | - */ |
|
| 1129 | - public static function do_not_cache() |
|
| 1130 | - { |
|
| 1131 | - // set no cache constants |
|
| 1132 | - if (! defined('DONOTCACHEPAGE')) { |
|
| 1133 | - define('DONOTCACHEPAGE', true); |
|
| 1134 | - } |
|
| 1135 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1136 | - define('DONOTCACHCEOBJECT', true); |
|
| 1137 | - } |
|
| 1138 | - if (! defined('DONOTCACHEDB')) { |
|
| 1139 | - define('DONOTCACHEDB', true); |
|
| 1140 | - } |
|
| 1141 | - // add no cache headers |
|
| 1142 | - add_action('send_headers', ['EE_System', 'nocache_headers'], 10); |
|
| 1143 | - // plus a little extra for nginx and Google Chrome |
|
| 1144 | - add_filter('nocache_headers', ['EE_System', 'extra_nocache_headers'], 10, 1); |
|
| 1145 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1146 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * extra_nocache_headers |
|
| 1152 | - * |
|
| 1153 | - * @access public |
|
| 1154 | - * @param $headers |
|
| 1155 | - * @return array |
|
| 1156 | - */ |
|
| 1157 | - public static function extra_nocache_headers($headers): array |
|
| 1158 | - { |
|
| 1159 | - // for NGINX |
|
| 1160 | - $headers['X-Accel-Expires'] = 0; |
|
| 1161 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1162 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1163 | - return $headers; |
|
| 1164 | - } |
|
| 1165 | - |
|
| 1166 | - |
|
| 1167 | - /** |
|
| 1168 | - * nocache_headers |
|
| 1169 | - * |
|
| 1170 | - * @access public |
|
| 1171 | - * @return void |
|
| 1172 | - */ |
|
| 1173 | - public static function nocache_headers() |
|
| 1174 | - { |
|
| 1175 | - nocache_headers(); |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - |
|
| 1179 | - /** |
|
| 1180 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1181 | - * never returned with the function. |
|
| 1182 | - * |
|
| 1183 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1184 | - * @return array |
|
| 1185 | - */ |
|
| 1186 | - public function remove_pages_from_wp_list_pages(array $exclude_array): array |
|
| 1187 | - { |
|
| 1188 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1189 | - } |
|
| 28 | + /** |
|
| 29 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 30 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 31 | + */ |
|
| 32 | + const req_type_normal = 0; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Indicates this is a brand new installation of EE so we should install |
|
| 36 | + * tables and default data etc |
|
| 37 | + */ |
|
| 38 | + const req_type_new_activation = 1; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 42 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 43 | + * and that default data is setup too |
|
| 44 | + */ |
|
| 45 | + const req_type_reactivation = 2; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * indicates that EE has been upgraded since its previous request. |
|
| 49 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 50 | + */ |
|
| 51 | + const req_type_upgrade = 3; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 55 | + */ |
|
| 56 | + const req_type_downgrade = 4; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @deprecated since version 4.6.0.dev.006 |
|
| 60 | + * Now whenever a new_activation is detected the request type is still just |
|
| 61 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we're in maintenance mode |
|
| 62 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 63 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 64 | + * (Specifically, when the migration manager indicates migrations are finished |
|
| 65 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 66 | + */ |
|
| 67 | + const req_type_activation_but_not_installed = 5; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 71 | + */ |
|
| 72 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @var AddonManager $addon_manager |
|
| 76 | + */ |
|
| 77 | + private $addon_manager; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @var EE_System $_instance |
|
| 81 | + */ |
|
| 82 | + private static $_instance; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @var EE_Registry $registry |
|
| 86 | + */ |
|
| 87 | + private $registry; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @var LoaderInterface $loader |
|
| 91 | + */ |
|
| 92 | + private $loader; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @var EE_Capabilities $capabilities |
|
| 96 | + */ |
|
| 97 | + private $capabilities; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
| 101 | + */ |
|
| 102 | + private $maintenance_mode; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @var RequestInterface $request |
|
| 106 | + */ |
|
| 107 | + private $request; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 111 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 112 | + * |
|
| 113 | + * @var int $_req_type |
|
| 114 | + */ |
|
| 115 | + private $_req_type; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
| 119 | + * |
|
| 120 | + * @var boolean $_major_version_change |
|
| 121 | + */ |
|
| 122 | + private $_major_version_change = false; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @var Router $router |
|
| 126 | + */ |
|
| 127 | + private $router; |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @singleton method used to instantiate class object |
|
| 132 | + * @param LoaderInterface|null $loader |
|
| 133 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
| 134 | + * @param EE_Registry|null $registry |
|
| 135 | + * @param RequestInterface|null $request |
|
| 136 | + * @param Router|null $router |
|
| 137 | + * @return EE_System |
|
| 138 | + */ |
|
| 139 | + public static function instance( |
|
| 140 | + LoaderInterface $loader = null, |
|
| 141 | + EE_Maintenance_Mode $maintenance_mode = null, |
|
| 142 | + EE_Registry $registry = null, |
|
| 143 | + RequestInterface $request = null, |
|
| 144 | + Router $router = null |
|
| 145 | + ): EE_System { |
|
| 146 | + // check if class object is instantiated |
|
| 147 | + if (! self::$_instance instanceof EE_System) { |
|
| 148 | + self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router); |
|
| 149 | + } |
|
| 150 | + return self::$_instance; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * resets the instance and returns it |
|
| 156 | + * |
|
| 157 | + * @return EE_System |
|
| 158 | + */ |
|
| 159 | + public static function reset(): EE_System |
|
| 160 | + { |
|
| 161 | + self::$_instance->_req_type = null; |
|
| 162 | + // make sure none of the old hooks are left hanging around |
|
| 163 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 164 | + // we need to reset the migration manager in order for it to detect DMSs properly |
|
| 165 | + EE_Data_Migration_Manager::reset(); |
|
| 166 | + self::instance()->detect_activations_or_upgrades(); |
|
| 167 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 168 | + return self::instance(); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * sets hooks for running rest of system |
|
| 174 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 175 | + * starting EE Addons from any other point may lead to problems |
|
| 176 | + * |
|
| 177 | + * @param LoaderInterface $loader |
|
| 178 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
| 179 | + * @param EE_Registry $registry |
|
| 180 | + * @param RequestInterface $request |
|
| 181 | + * @param Router $router |
|
| 182 | + */ |
|
| 183 | + private function __construct( |
|
| 184 | + LoaderInterface $loader, |
|
| 185 | + EE_Maintenance_Mode $maintenance_mode, |
|
| 186 | + EE_Registry $registry, |
|
| 187 | + RequestInterface $request, |
|
| 188 | + Router $router |
|
| 189 | + ) { |
|
| 190 | + $this->registry = $registry; |
|
| 191 | + $this->loader = $loader; |
|
| 192 | + $this->request = $request; |
|
| 193 | + $this->router = $router; |
|
| 194 | + $this->maintenance_mode = $maintenance_mode; |
|
| 195 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
| 196 | + add_action( |
|
| 197 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 198 | + [$this, 'loadCapabilities'], |
|
| 199 | + 5 |
|
| 200 | + ); |
|
| 201 | + add_action( |
|
| 202 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 203 | + [$this, 'loadCommandBus'], |
|
| 204 | + 7 |
|
| 205 | + ); |
|
| 206 | + add_action( |
|
| 207 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 208 | + [$this, 'loadPluginApi'], |
|
| 209 | + 9 |
|
| 210 | + ); |
|
| 211 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 212 | + add_action( |
|
| 213 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 214 | + [$this, 'load_espresso_addons'] |
|
| 215 | + ); |
|
| 216 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
| 217 | + // because the newly-activated addon didn't get a chance to run at all |
|
| 218 | + add_action('activate_plugin', [$this, 'load_espresso_addons'], 1); |
|
| 219 | + // detect whether install or upgrade |
|
| 220 | + add_action( |
|
| 221 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 222 | + [$this, 'detect_activations_or_upgrades'], |
|
| 223 | + 3 |
|
| 224 | + ); |
|
| 225 | + // load EE_Config, EE_Textdomain, etc |
|
| 226 | + add_action( |
|
| 227 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 228 | + [$this, 'load_core_configuration'], |
|
| 229 | + 5 |
|
| 230 | + ); |
|
| 231 | + // load specifications for matching routes to current request |
|
| 232 | + add_action( |
|
| 233 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 234 | + [$this, 'loadRouteMatchSpecifications'] |
|
| 235 | + ); |
|
| 236 | + // load EE_Config, EE_Textdomain, etc |
|
| 237 | + add_action( |
|
| 238 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 239 | + [$this, 'register_shortcodes_modules_and_widgets'], |
|
| 240 | + 7 |
|
| 241 | + ); |
|
| 242 | + // you wanna get going? I wanna get going... let's get going! |
|
| 243 | + add_action( |
|
| 244 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 245 | + [$this, 'brew_espresso'], |
|
| 246 | + 9 |
|
| 247 | + ); |
|
| 248 | + // other housekeeping |
|
| 249 | + // exclude EE critical pages from wp_list_pages |
|
| 250 | + add_filter( |
|
| 251 | + 'wp_list_pages_excludes', |
|
| 252 | + [$this, 'remove_pages_from_wp_list_pages'], |
|
| 253 | + 10 |
|
| 254 | + ); |
|
| 255 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 256 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 257 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * load and setup EE_Capabilities |
|
| 263 | + * |
|
| 264 | + * @return void |
|
| 265 | + */ |
|
| 266 | + public function loadCapabilities() |
|
| 267 | + { |
|
| 268 | + $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
| 269 | + add_action( |
|
| 270 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 271 | + function () { |
|
| 272 | + LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
| 273 | + } |
|
| 274 | + ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * create and cache the CommandBus, and also add middleware |
|
| 280 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
| 281 | + * which is why we need to load the CommandBus after Caps are set up |
|
| 282 | + * |
|
| 283 | + * @return void |
|
| 284 | + */ |
|
| 285 | + public function loadCommandBus() |
|
| 286 | + { |
|
| 287 | + $this->loader->getShared( |
|
| 288 | + 'CommandBusInterface', |
|
| 289 | + [ |
|
| 290 | + null, |
|
| 291 | + apply_filters( |
|
| 292 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 293 | + [ |
|
| 294 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
| 295 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
| 296 | + ] |
|
| 297 | + ), |
|
| 298 | + ] |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * @return void |
|
| 305 | + * @throws Exception |
|
| 306 | + */ |
|
| 307 | + public function loadPluginApi() |
|
| 308 | + { |
|
| 309 | + $this->addon_manager = $this->loader->getShared(AddonManager::class); |
|
| 310 | + $this->addon_manager->initialize(); |
|
| 311 | + $this->loader->getShared('EE_Request_Handler'); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * load_espresso_addons |
|
| 317 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 318 | + * this is hooked into both: |
|
| 319 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 320 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 321 | + * and the WP 'activate_plugin' hook point |
|
| 322 | + * |
|
| 323 | + * @return void |
|
| 324 | + * @throws Exception |
|
| 325 | + */ |
|
| 326 | + public function load_espresso_addons() |
|
| 327 | + { |
|
| 328 | + // looking for hooks? they've been moved into the AddonManager to maintain compatibility |
|
| 329 | + $this->addon_manager->loadAddons(); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * detect_activations_or_upgrades |
|
| 335 | + * Checks for activation or upgrade of core first; |
|
| 336 | + * then also checks if any registered addons have been activated or upgraded |
|
| 337 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 338 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 339 | + * |
|
| 340 | + * @access public |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + public function detect_activations_or_upgrades() |
|
| 344 | + { |
|
| 345 | + // first off: let's make sure to handle core |
|
| 346 | + $this->detect_if_activation_or_upgrade(); |
|
| 347 | + foreach ($this->registry->addons as $addon) { |
|
| 348 | + if ($addon instanceof EE_Addon) { |
|
| 349 | + // detect teh request type for that addon |
|
| 350 | + $addon->detect_activation_or_upgrade(); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * detect_if_activation_or_upgrade |
|
| 358 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 359 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 360 | + * |
|
| 361 | + * @access public |
|
| 362 | + * @return void |
|
| 363 | + */ |
|
| 364 | + public function detect_if_activation_or_upgrade() |
|
| 365 | + { |
|
| 366 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 367 | + // check if db has been updated, or if its a brand-new installation |
|
| 368 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 369 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
| 370 | + // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 371 | + switch ($request_type) { |
|
| 372 | + case EE_System::req_type_new_activation: |
|
| 373 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 374 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 375 | + break; |
|
| 376 | + case EE_System::req_type_reactivation: |
|
| 377 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 378 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 379 | + break; |
|
| 380 | + case EE_System::req_type_upgrade: |
|
| 381 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 382 | + // migrations may be required now that we've upgraded |
|
| 383 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 384 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 385 | + break; |
|
| 386 | + case EE_System::req_type_downgrade: |
|
| 387 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 388 | + // its possible migrations are no longer required |
|
| 389 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
| 390 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 391 | + break; |
|
| 392 | + case EE_System::req_type_normal: |
|
| 393 | + default: |
|
| 394 | + break; |
|
| 395 | + } |
|
| 396 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Updates the list of installed versions and sets hooks for |
|
| 402 | + * initializing the database later during the request |
|
| 403 | + * |
|
| 404 | + * @param array $espresso_db_update |
|
| 405 | + */ |
|
| 406 | + private function _handle_core_version_change(array $espresso_db_update) |
|
| 407 | + { |
|
| 408 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
| 409 | + // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 410 | + add_action( |
|
| 411 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 412 | + [$this, 'initialize_db_if_no_migrations_required'] |
|
| 413 | + ); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 419 | + * information about what versions of EE have been installed and activated, |
|
| 420 | + * NOT necessarily the state of the database |
|
| 421 | + * |
|
| 422 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 423 | + * If not supplied, fetches it from the options table |
|
| 424 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 425 | + */ |
|
| 426 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null): array |
|
| 427 | + { |
|
| 428 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 429 | + if (! $espresso_db_update) { |
|
| 430 | + $espresso_db_update = get_option('espresso_db_update'); |
|
| 431 | + } |
|
| 432 | + // check that option is an array |
|
| 433 | + if (! is_array($espresso_db_update)) { |
|
| 434 | + // if option is FALSE, then it never existed |
|
| 435 | + if ($espresso_db_update === false) { |
|
| 436 | + // make $espresso_db_update an array and save option with autoload OFF |
|
| 437 | + $espresso_db_update = []; |
|
| 438 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 439 | + } else { |
|
| 440 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 441 | + $espresso_db_update = [$espresso_db_update => []]; |
|
| 442 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 443 | + } |
|
| 444 | + } else { |
|
| 445 | + $corrected_db_update = []; |
|
| 446 | + // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 447 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 448 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 449 | + // the key is an int, and the value IS NOT an array |
|
| 450 | + // so it must be numerically-indexed, where values are versions installed... |
|
| 451 | + // fix it! |
|
| 452 | + $version_string = $should_be_array; |
|
| 453 | + $corrected_db_update[ $version_string ] = ['unknown-date']; |
|
| 454 | + } else { |
|
| 455 | + // ok it checks out |
|
| 456 | + $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + $espresso_db_update = $corrected_db_update; |
|
| 460 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 461 | + } |
|
| 462 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 463 | + return ! empty($espresso_db_update) ? $espresso_db_update : []; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 469 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 470 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 471 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 472 | + * so that it will be done when migrations are finished |
|
| 473 | + * |
|
| 474 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 475 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 476 | + * This is a resource-intensive job |
|
| 477 | + * so we prefer to only do it when necessary |
|
| 478 | + * @return void |
|
| 479 | + * @throws EE_Error |
|
| 480 | + * @throws ReflectionException |
|
| 481 | + */ |
|
| 482 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 483 | + { |
|
| 484 | + $request_type = $this->detect_req_type(); |
|
| 485 | + // only initialize system if we're not in maintenance mode. |
|
| 486 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 487 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 488 | + $rewrite_rules = $this->loader->getShared( |
|
| 489 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 490 | + ); |
|
| 491 | + $rewrite_rules->flush(); |
|
| 492 | + if ($verify_schema) { |
|
| 493 | + EEH_Activation::initialize_db_and_folders(); |
|
| 494 | + } |
|
| 495 | + EEH_Activation::initialize_db_content(); |
|
| 496 | + EEH_Activation::system_initialization(); |
|
| 497 | + if ($initialize_addons_too) { |
|
| 498 | + $this->initialize_addons(); |
|
| 499 | + } |
|
| 500 | + } else { |
|
| 501 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 502 | + } |
|
| 503 | + if ( |
|
| 504 | + $request_type === EE_System::req_type_new_activation |
|
| 505 | + || $request_type === EE_System::req_type_reactivation |
|
| 506 | + || ( |
|
| 507 | + $request_type === EE_System::req_type_upgrade |
|
| 508 | + && $this->is_major_version_change() |
|
| 509 | + ) |
|
| 510 | + ) { |
|
| 511 | + add_action('AHEE__EE_System__initialize_last', [$this, 'redirect_to_about_ee'], 9); |
|
| 512 | + } |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Initializes the db for all registered addons |
|
| 518 | + * |
|
| 519 | + * @throws EE_Error |
|
| 520 | + * @throws ReflectionException |
|
| 521 | + */ |
|
| 522 | + public function initialize_addons() |
|
| 523 | + { |
|
| 524 | + // foreach registered addon, make sure its db is up-to-date too |
|
| 525 | + foreach ($this->registry->addons as $addon) { |
|
| 526 | + if ($addon instanceof EE_Addon) { |
|
| 527 | + $addon->initialize_db_if_no_migrations_required(); |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 535 | + * |
|
| 536 | + * @param array $version_history |
|
| 537 | + * @param string $current_version_to_add version to be added to the version history |
|
| 538 | + * @return boolean success as to whether or not this option was changed |
|
| 539 | + */ |
|
| 540 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool |
|
| 541 | + { |
|
| 542 | + if (! $version_history) { |
|
| 543 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 544 | + } |
|
| 545 | + if ($current_version_to_add === null) { |
|
| 546 | + $current_version_to_add = espresso_version(); |
|
| 547 | + } |
|
| 548 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
| 549 | + // re-save |
|
| 550 | + return update_option('espresso_db_update', $version_history); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Detects if the current version indicated in the has existed in the list of |
|
| 556 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 557 | + * |
|
| 558 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 559 | + * If not supplied, fetches it from the options table. |
|
| 560 | + * Also, caches its result so later parts of the code can also know whether |
|
| 561 | + * there's been an update or not. This way we can add the current version to |
|
| 562 | + * espresso_db_update, but still know if this is a new install or not |
|
| 563 | + * @return int one of the constants on EE_System::req_type_ |
|
| 564 | + */ |
|
| 565 | + public function detect_req_type($espresso_db_update = null): int |
|
| 566 | + { |
|
| 567 | + if ($this->_req_type === null) { |
|
| 568 | + $espresso_db_update = ! empty($espresso_db_update) |
|
| 569 | + ? $espresso_db_update |
|
| 570 | + : $this->fix_espresso_db_upgrade_option(); |
|
| 571 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
| 572 | + $espresso_db_update, |
|
| 573 | + 'ee_espresso_activation', |
|
| 574 | + espresso_version() |
|
| 575 | + ); |
|
| 576 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 577 | + $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
| 578 | + } |
|
| 579 | + return $this->_req_type; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 585 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 586 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 587 | + * |
|
| 588 | + * @param $activation_history |
|
| 589 | + * @return bool |
|
| 590 | + */ |
|
| 591 | + private function _detect_major_version_change($activation_history): bool |
|
| 592 | + { |
|
| 593 | + $previous_version = EE_System::getMostRecentlyActiveVersion($activation_history); |
|
| 594 | + $previous_version_parts = explode('.', $previous_version); |
|
| 595 | + $current_version_parts = explode('.', espresso_version()); |
|
| 596 | + return isset( |
|
| 597 | + $previous_version_parts[0], |
|
| 598 | + $previous_version_parts[1], |
|
| 599 | + $current_version_parts[0], |
|
| 600 | + $current_version_parts[1] |
|
| 601 | + ) && ( |
|
| 602 | + $previous_version_parts[0] !== $current_version_parts[0] |
|
| 603 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 604 | + ); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Returns true if either the major or minor version of EE changed during this request. |
|
| 610 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 611 | + * |
|
| 612 | + * @return bool |
|
| 613 | + */ |
|
| 614 | + public function is_major_version_change(): bool |
|
| 615 | + { |
|
| 616 | + return $this->_major_version_change; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 622 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 623 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 624 | + * just activated to (for core that will always be espresso_version()) |
|
| 625 | + * |
|
| 626 | + * @param array|null $activation_history the option's value which stores the activation history for |
|
| 627 | + * this |
|
| 628 | + * ee plugin. for core that's 'espresso_db_update' |
|
| 629 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 630 | + * indicate that this plugin was just activated |
|
| 631 | + * @param string $current_version the version that was just upgraded to (for core that will be |
|
| 632 | + * espresso_version()) |
|
| 633 | + * @return int one of the constants on EE_System::req_type_ |
|
| 634 | + */ |
|
| 635 | + public static function detect_req_type_given_activation_history( |
|
| 636 | + array $activation_history, |
|
| 637 | + string $activation_indicator_option_name, |
|
| 638 | + string $current_version |
|
| 639 | + ): int { |
|
| 640 | + $version_change = self::compareVersionWithPrevious($activation_history, $current_version); |
|
| 641 | + $is_activation = get_option($activation_indicator_option_name, false); |
|
| 642 | + $req_type = self::getRequestType($activation_history, $version_change, $is_activation); |
|
| 643 | + if ($is_activation) { |
|
| 644 | + // cleanup in aisle 6 |
|
| 645 | + delete_option($activation_indicator_option_name); |
|
| 646 | + } |
|
| 647 | + return $req_type; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * @param array $activation_history |
|
| 653 | + * @param int $version_change |
|
| 654 | + * @param bool $is_activation |
|
| 655 | + * @return int |
|
| 656 | + * @since $VID:$ |
|
| 657 | + */ |
|
| 658 | + private static function getRequestType(array $activation_history, int $version_change, bool $is_activation): int |
|
| 659 | + { |
|
| 660 | + // if no previous activation history exists, then this is a brand new install |
|
| 661 | + if (empty($activation_history)) { |
|
| 662 | + return EE_System::req_type_new_activation; |
|
| 663 | + } |
|
| 664 | + // current version is higher than previous version, so it's an upgrade |
|
| 665 | + if ($version_change === 1) { |
|
| 666 | + return EE_System::req_type_upgrade; |
|
| 667 | + } |
|
| 668 | + // current version is lower than previous version, so it's a downgrade |
|
| 669 | + if ($version_change === -1) { |
|
| 670 | + return EE_System::req_type_downgrade; |
|
| 671 | + } |
|
| 672 | + // version hasn't changed since last version so check if the activation indicator is set |
|
| 673 | + // to determine if it's a reactivation, or just a normal request |
|
| 674 | + return $is_activation |
|
| 675 | + ? EE_System::req_type_reactivation |
|
| 676 | + : EE_System::req_type_normal; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 682 | + * the $activation_history_for_addon |
|
| 683 | + * |
|
| 684 | + * @param array $activation_history array where keys are versions, |
|
| 685 | + * values are arrays of times activated (sometimes 'unknown-date') |
|
| 686 | + * @param string $current_version |
|
| 687 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 688 | + * -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 689 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 690 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 691 | + */ |
|
| 692 | + private static function compareVersionWithPrevious(array $activation_history, string $current_version): int |
|
| 693 | + { |
|
| 694 | + // find the most recently-activated version |
|
| 695 | + $most_recently_active_version = EE_System::getMostRecentlyActiveVersion($activation_history); |
|
| 696 | + return version_compare($current_version, $most_recently_active_version); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Gets the most recently active version listed in the activation history, |
|
| 702 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 703 | + * |
|
| 704 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 705 | + * sometimes containing 'unknown-date' |
|
| 706 | + * @return string |
|
| 707 | + */ |
|
| 708 | + private static function getMostRecentlyActiveVersion(array $activation_history): string |
|
| 709 | + { |
|
| 710 | + $most_recent_activation_date = '1970-01-01 00:00:00'; |
|
| 711 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
| 712 | + if (is_array($activation_history)) { |
|
| 713 | + foreach ($activation_history as $version => $activation_dates) { |
|
| 714 | + // check there is a record of when this version was activated. |
|
| 715 | + // Otherwise, mark it as unknown |
|
| 716 | + if (! $activation_dates) { |
|
| 717 | + $activation_dates = ['unknown-date']; |
|
| 718 | + } |
|
| 719 | + $activation_dates = is_string($activation_dates) ? [$activation_dates] : $activation_dates; |
|
| 720 | + foreach ($activation_dates as $activation_date) { |
|
| 721 | + if ($activation_date !== 'unknown-date' && $activation_date > $most_recent_activation_date) { |
|
| 722 | + $most_recently_active_version = $version; |
|
| 723 | + $most_recent_activation_date = $activation_date; |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + return $most_recently_active_version; |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * This redirects to the about EE page after activation |
|
| 734 | + * |
|
| 735 | + * @return void |
|
| 736 | + */ |
|
| 737 | + public function redirect_to_about_ee() |
|
| 738 | + { |
|
| 739 | + $notices = EE_Error::get_notices(false); |
|
| 740 | + // if current user is an admin and it's not an ajax or rest request |
|
| 741 | + if ( |
|
| 742 | + ! isset($notices['errors']) |
|
| 743 | + && $this->request->isAdmin() |
|
| 744 | + && apply_filters( |
|
| 745 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 746 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
| 747 | + ) |
|
| 748 | + ) { |
|
| 749 | + $query_params = ['page' => 'espresso_about']; |
|
| 750 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 751 | + $query_params['new_activation'] = true; |
|
| 752 | + } |
|
| 753 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 754 | + $query_params['reactivation'] = true; |
|
| 755 | + } |
|
| 756 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 757 | + EEH_URL::safeRedirectAndExit($url); |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * load_core_configuration |
|
| 764 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 765 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 766 | + * |
|
| 767 | + * @return void |
|
| 768 | + * @throws ReflectionException |
|
| 769 | + * @throws Exception |
|
| 770 | + */ |
|
| 771 | + public function load_core_configuration() |
|
| 772 | + { |
|
| 773 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 774 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
| 775 | + // load textdomain |
|
| 776 | + EE_Load_Textdomain::load_textdomain(); |
|
| 777 | + // load caf stuff a chance to play during the activation process too. |
|
| 778 | + $this->_maybe_brew_regular(); |
|
| 779 | + // load and setup EE_Config and EE_Network_Config |
|
| 780 | + $config = $this->loader->getShared('EE_Config'); |
|
| 781 | + $this->loader->getShared('EE_Network_Config'); |
|
| 782 | + // setup autoloaders |
|
| 783 | + // enable logging? |
|
| 784 | + if ($config->admin->use_remote_logging) { |
|
| 785 | + $this->loader->getShared('EE_Log'); |
|
| 786 | + } |
|
| 787 | + // check for activation errors |
|
| 788 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 789 | + if ($activation_errors) { |
|
| 790 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 791 | + update_option('ee_plugin_activation_errors', false); |
|
| 792 | + } |
|
| 793 | + // get model names |
|
| 794 | + $this->_parse_model_names(); |
|
| 795 | + // configure custom post type definitions |
|
| 796 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
| 797 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
| 798 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 804 | + * |
|
| 805 | + * @return void |
|
| 806 | + * @throws ReflectionException |
|
| 807 | + */ |
|
| 808 | + private function _parse_model_names() |
|
| 809 | + { |
|
| 810 | + // get all the files in the EE_MODELS folder that end in .model.php |
|
| 811 | + $models = glob(EE_MODELS . '*.model.php'); |
|
| 812 | + $model_names = []; |
|
| 813 | + $non_abstract_db_models = []; |
|
| 814 | + foreach ($models as $model) { |
|
| 815 | + // get model classname |
|
| 816 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 817 | + $short_name = str_replace('EEM_', '', $classname); |
|
| 818 | + $reflectionClass = new ReflectionClass($classname); |
|
| 819 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 820 | + $non_abstract_db_models[ $short_name ] = $classname; |
|
| 821 | + } |
|
| 822 | + $model_names[ $short_name ] = $classname; |
|
| 823 | + } |
|
| 824 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 825 | + $this->registry->non_abstract_db_models = apply_filters( |
|
| 826 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
| 827 | + $non_abstract_db_models |
|
| 828 | + ); |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + |
|
| 832 | + /** |
|
| 833 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 834 | + * that need to be setup before our EE_System launches. |
|
| 835 | + * |
|
| 836 | + * @return void |
|
| 837 | + * @throws DomainException |
|
| 838 | + * @throws InvalidArgumentException |
|
| 839 | + * @throws InvalidDataTypeException |
|
| 840 | + * @throws InvalidInterfaceException |
|
| 841 | + * @throws InvalidClassException |
|
| 842 | + * @throws InvalidFilePathException |
|
| 843 | + */ |
|
| 844 | + private function _maybe_brew_regular() |
|
| 845 | + { |
|
| 846 | + /** @var Domain $domain */ |
|
| 847 | + $domain = DomainFactory::getEventEspressoCoreDomain(); |
|
| 848 | + if ($domain->isCaffeinated()) { |
|
| 849 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 850 | + } |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * @throws Exception |
|
| 856 | + * @since 4.9.71.p |
|
| 857 | + */ |
|
| 858 | + public function loadRouteMatchSpecifications() |
|
| 859 | + { |
|
| 860 | + try { |
|
| 861 | + $this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager'); |
|
| 862 | + $this->loader->getShared('EventEspresso\core\services\routing\RouteCollection'); |
|
| 863 | + $this->router->loadPrimaryRoutes(); |
|
| 864 | + } catch (Exception $exception) { |
|
| 865 | + new ExceptionStackTraceDisplay($exception); |
|
| 866 | + } |
|
| 867 | + do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * register_shortcodes_modules_and_widgets |
|
| 873 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
| 874 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 875 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 876 | + * |
|
| 877 | + * @access public |
|
| 878 | + * @return void |
|
| 879 | + * @throws Exception |
|
| 880 | + */ |
|
| 881 | + public function register_shortcodes_modules_and_widgets() |
|
| 882 | + { |
|
| 883 | + $this->router->registerShortcodesModulesAndWidgets(); |
|
| 884 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 885 | + // check for addons using old hook point |
|
| 886 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 887 | + $this->_incompatible_addon_error(); |
|
| 888 | + } |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * _incompatible_addon_error |
|
| 894 | + * |
|
| 895 | + * @access public |
|
| 896 | + * @return void |
|
| 897 | + */ |
|
| 898 | + private function _incompatible_addon_error() |
|
| 899 | + { |
|
| 900 | + // get array of classes hooking into here |
|
| 901 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
| 902 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
| 903 | + ); |
|
| 904 | + if (! empty($class_names)) { |
|
| 905 | + $msg = __( |
|
| 906 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 907 | + 'event_espresso' |
|
| 908 | + ); |
|
| 909 | + $msg .= '<ul>'; |
|
| 910 | + foreach ($class_names as $class_name) { |
|
| 911 | + $msg .= '<li><b>Event Espresso - ' |
|
| 912 | + . str_replace( |
|
| 913 | + ['EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'], |
|
| 914 | + '', |
|
| 915 | + $class_name |
|
| 916 | + ) . '</b></li>'; |
|
| 917 | + } |
|
| 918 | + $msg .= '</ul>'; |
|
| 919 | + $msg .= __( |
|
| 920 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 921 | + 'event_espresso' |
|
| 922 | + ); |
|
| 923 | + // save list of incompatible addons to wp-options for later use |
|
| 924 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 925 | + if (is_admin()) { |
|
| 926 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + |
|
| 932 | + /** |
|
| 933 | + * brew_espresso |
|
| 934 | + * begins the process of setting hooks for initializing EE in the correct order |
|
| 935 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 936 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 937 | + * |
|
| 938 | + * @return void |
|
| 939 | + * @throws Exception |
|
| 940 | + */ |
|
| 941 | + public function brew_espresso() |
|
| 942 | + { |
|
| 943 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 944 | + // load some final core systems |
|
| 945 | + add_action('init', [$this, 'set_hooks_for_core'], 1); |
|
| 946 | + add_action('init', [$this, 'perform_activations_upgrades_and_migrations'], 3); |
|
| 947 | + add_action('init', [$this, 'load_CPTs_and_session'], 5); |
|
| 948 | + add_action('init', [$this, 'load_controllers'], 7); |
|
| 949 | + add_action('init', [$this, 'core_loaded_and_ready'], 9); |
|
| 950 | + add_action('init', [$this, 'initialize'], 10); |
|
| 951 | + add_action('init', [$this, 'initialize_last'], 100); |
|
| 952 | + $this->router->brewEspresso(); |
|
| 953 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * set_hooks_for_core |
|
| 959 | + * |
|
| 960 | + * @access public |
|
| 961 | + * @return void |
|
| 962 | + * @throws EE_Error |
|
| 963 | + */ |
|
| 964 | + public function set_hooks_for_core() |
|
| 965 | + { |
|
| 966 | + $this->_deactivate_incompatible_addons(); |
|
| 967 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 968 | + $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
| 969 | + // caps need to be initialized on every request so that capability maps are set. |
|
| 970 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 971 | + $this->registry->CAP->init_caps(); |
|
| 972 | + } |
|
| 973 | + |
|
| 974 | + |
|
| 975 | + /** |
|
| 976 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 977 | + * deactivates any addons considered incompatible with the current version of EE |
|
| 978 | + */ |
|
| 979 | + private function _deactivate_incompatible_addons() |
|
| 980 | + { |
|
| 981 | + $incompatible_addons = get_option('ee_incompatible_addons', []); |
|
| 982 | + if (! empty($incompatible_addons)) { |
|
| 983 | + $active_plugins = get_option('active_plugins', []); |
|
| 984 | + foreach ($active_plugins as $active_plugin) { |
|
| 985 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
| 986 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 987 | + unset($_GET['activate']); |
|
| 988 | + espresso_deactivate_plugin($active_plugin); |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * perform_activations_upgrades_and_migrations |
|
| 998 | + * |
|
| 999 | + * @access public |
|
| 1000 | + * @return void |
|
| 1001 | + */ |
|
| 1002 | + public function perform_activations_upgrades_and_migrations() |
|
| 1003 | + { |
|
| 1004 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + |
|
| 1008 | + /** |
|
| 1009 | + * @return void |
|
| 1010 | + * @throws DomainException |
|
| 1011 | + */ |
|
| 1012 | + public function load_CPTs_and_session() |
|
| 1013 | + { |
|
| 1014 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 1015 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */ |
|
| 1016 | + $register_custom_taxonomies = $this->loader->getShared( |
|
| 1017 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
| 1018 | + ); |
|
| 1019 | + $register_custom_taxonomies->registerCustomTaxonomies(); |
|
| 1020 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ |
|
| 1021 | + $register_custom_post_types = $this->loader->getShared( |
|
| 1022 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
| 1023 | + ); |
|
| 1024 | + $register_custom_post_types->registerCustomPostTypes(); |
|
| 1025 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */ |
|
| 1026 | + $register_custom_taxonomy_terms = $this->loader->getShared( |
|
| 1027 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
| 1028 | + ); |
|
| 1029 | + $register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
| 1030 | + // load legacy Custom Post Types and Taxonomies |
|
| 1031 | + $this->loader->getShared('EE_Register_CPTs'); |
|
| 1032 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + |
|
| 1036 | + /** |
|
| 1037 | + * load_controllers |
|
| 1038 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 1039 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 1040 | + * time |
|
| 1041 | + * |
|
| 1042 | + * @access public |
|
| 1043 | + * @return void |
|
| 1044 | + * @throws Exception |
|
| 1045 | + */ |
|
| 1046 | + public function load_controllers() |
|
| 1047 | + { |
|
| 1048 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
| 1049 | + $this->router->loadControllers(); |
|
| 1050 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * core_loaded_and_ready |
|
| 1056 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1057 | + * |
|
| 1058 | + * @access public |
|
| 1059 | + * @return void |
|
| 1060 | + * @throws Exception |
|
| 1061 | + */ |
|
| 1062 | + public function core_loaded_and_ready() |
|
| 1063 | + { |
|
| 1064 | + $this->router->coreLoadedAndReady(); |
|
| 1065 | + // integrate WP_Query with the EE models |
|
| 1066 | + $this->loader->getShared('EE_CPT_Strategy'); |
|
| 1067 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1068 | + // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
| 1069 | + // builders require these even on the front-end |
|
| 1070 | + require_once EE_PUBLIC . 'template_tags.php'; |
|
| 1071 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * initialize |
|
| 1077 | + * this is the best place to begin initializing client code |
|
| 1078 | + * |
|
| 1079 | + * @access public |
|
| 1080 | + * @return void |
|
| 1081 | + */ |
|
| 1082 | + public function initialize() |
|
| 1083 | + { |
|
| 1084 | + do_action('AHEE__EE_System__initialize'); |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + |
|
| 1088 | + /** |
|
| 1089 | + * initialize_last |
|
| 1090 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1091 | + * initialize has done so |
|
| 1092 | + * |
|
| 1093 | + * @access public |
|
| 1094 | + * @return void |
|
| 1095 | + * @throws Exception |
|
| 1096 | + */ |
|
| 1097 | + public function initialize_last() |
|
| 1098 | + { |
|
| 1099 | + do_action('AHEE__EE_System__initialize_last'); |
|
| 1100 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 1101 | + $rewrite_rules = $this->loader->getShared( |
|
| 1102 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 1103 | + ); |
|
| 1104 | + $rewrite_rules->flushRewriteRules(); |
|
| 1105 | + $this->router->initializeLast(); |
|
| 1106 | + add_action('admin_bar_init', [$this, 'addEspressoToolbar']); |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * @return void |
|
| 1112 | + */ |
|
| 1113 | + public function addEspressoToolbar() |
|
| 1114 | + { |
|
| 1115 | + $this->loader->getShared( |
|
| 1116 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
| 1117 | + [$this->registry->CAP] |
|
| 1118 | + ); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + |
|
| 1122 | + /** |
|
| 1123 | + * do_not_cache |
|
| 1124 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 1125 | + * |
|
| 1126 | + * @access public |
|
| 1127 | + * @return void |
|
| 1128 | + */ |
|
| 1129 | + public static function do_not_cache() |
|
| 1130 | + { |
|
| 1131 | + // set no cache constants |
|
| 1132 | + if (! defined('DONOTCACHEPAGE')) { |
|
| 1133 | + define('DONOTCACHEPAGE', true); |
|
| 1134 | + } |
|
| 1135 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
| 1136 | + define('DONOTCACHCEOBJECT', true); |
|
| 1137 | + } |
|
| 1138 | + if (! defined('DONOTCACHEDB')) { |
|
| 1139 | + define('DONOTCACHEDB', true); |
|
| 1140 | + } |
|
| 1141 | + // add no cache headers |
|
| 1142 | + add_action('send_headers', ['EE_System', 'nocache_headers'], 10); |
|
| 1143 | + // plus a little extra for nginx and Google Chrome |
|
| 1144 | + add_filter('nocache_headers', ['EE_System', 'extra_nocache_headers'], 10, 1); |
|
| 1145 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1146 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * extra_nocache_headers |
|
| 1152 | + * |
|
| 1153 | + * @access public |
|
| 1154 | + * @param $headers |
|
| 1155 | + * @return array |
|
| 1156 | + */ |
|
| 1157 | + public static function extra_nocache_headers($headers): array |
|
| 1158 | + { |
|
| 1159 | + // for NGINX |
|
| 1160 | + $headers['X-Accel-Expires'] = 0; |
|
| 1161 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1162 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1163 | + return $headers; |
|
| 1164 | + } |
|
| 1165 | + |
|
| 1166 | + |
|
| 1167 | + /** |
|
| 1168 | + * nocache_headers |
|
| 1169 | + * |
|
| 1170 | + * @access public |
|
| 1171 | + * @return void |
|
| 1172 | + */ |
|
| 1173 | + public static function nocache_headers() |
|
| 1174 | + { |
|
| 1175 | + nocache_headers(); |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + |
|
| 1179 | + /** |
|
| 1180 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1181 | + * never returned with the function. |
|
| 1182 | + * |
|
| 1183 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1184 | + * @return array |
|
| 1185 | + */ |
|
| 1186 | + public function remove_pages_from_wp_list_pages(array $exclude_array): array |
|
| 1187 | + { |
|
| 1188 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1189 | + } |
|
| 1190 | 1190 | } |