@@ -16,2816 +16,2816 @@ |
||
| 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. |
|
| 19 | + /** |
|
| 20 | + * This will hold the event object for event_details screen. |
|
| 21 | + * |
|
| 22 | + * @var EE_Event $_event |
|
| 23 | + */ |
|
| 24 | + protected $_event; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * This will hold the category object for category_details screen. |
|
| 29 | + * |
|
| 30 | + * @var stdClass $_category |
|
| 31 | + */ |
|
| 32 | + protected $_category; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * This will hold the event model instance |
|
| 37 | + * |
|
| 38 | + * @var EEM_Event $_event_model |
|
| 39 | + */ |
|
| 40 | + protected $_event_model; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Event |
|
| 45 | + */ |
|
| 46 | + protected $_cpt_model_obj = false; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var NodeGroupDao |
|
| 51 | + */ |
|
| 52 | + protected $model_obj_node_group_persister; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Initialize page props for this admin page group. |
|
| 57 | + */ |
|
| 58 | + protected function _init_page_props() |
|
| 59 | + { |
|
| 60 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 61 | + $this->page_label = EVENTS_LABEL; |
|
| 62 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 63 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 64 | + $this->_cpt_model_names = [ |
|
| 65 | + 'create_new' => 'EEM_Event', |
|
| 66 | + 'edit' => 'EEM_Event', |
|
| 67 | + ]; |
|
| 68 | + $this->_cpt_edit_routes = [ |
|
| 69 | + 'espresso_events' => 'edit', |
|
| 70 | + ]; |
|
| 71 | + add_action( |
|
| 72 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 73 | + [$this, 'verify_event_edit'], |
|
| 74 | + 10, |
|
| 75 | + 2 |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Sets the ajax hooks used for this admin page group. |
|
| 82 | + */ |
|
| 83 | + protected function _ajax_hooks() |
|
| 84 | + { |
|
| 85 | + add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Sets the page properties for this admin page group. |
|
| 91 | + */ |
|
| 92 | + protected function _define_page_props() |
|
| 93 | + { |
|
| 94 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 95 | + $this->_labels = [ |
|
| 96 | + 'buttons' => [ |
|
| 97 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 98 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 99 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 100 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 101 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 102 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 103 | + ], |
|
| 104 | + 'editor_title' => [ |
|
| 105 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 106 | + ], |
|
| 107 | + 'publishbox' => [ |
|
| 108 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 109 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 110 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 111 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 112 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 113 | + ], |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Sets the page routes property for this admin page group. |
|
| 120 | + */ |
|
| 121 | + protected function _set_page_routes() |
|
| 122 | + { |
|
| 123 | + // load formatter helper |
|
| 124 | + // load field generator helper |
|
| 125 | + // is there a evt_id in the request? |
|
| 126 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 127 | + $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
| 128 | + |
|
| 129 | + $this->_page_routes = [ |
|
| 130 | + 'default' => [ |
|
| 131 | + 'func' => '_events_overview_list_table', |
|
| 132 | + 'capability' => 'ee_read_events', |
|
| 133 | + ], |
|
| 134 | + 'create_new' => [ |
|
| 135 | + 'func' => '_create_new_cpt_item', |
|
| 136 | + 'capability' => 'ee_edit_events', |
|
| 137 | + ], |
|
| 138 | + 'edit' => [ |
|
| 139 | + 'func' => '_edit_cpt_item', |
|
| 140 | + 'capability' => 'ee_edit_event', |
|
| 141 | + 'obj_id' => $EVT_ID, |
|
| 142 | + ], |
|
| 143 | + 'copy_event' => [ |
|
| 144 | + 'func' => '_copy_events', |
|
| 145 | + 'capability' => 'ee_edit_event', |
|
| 146 | + 'obj_id' => $EVT_ID, |
|
| 147 | + 'noheader' => true, |
|
| 148 | + ], |
|
| 149 | + 'trash_event' => [ |
|
| 150 | + 'func' => '_trash_or_restore_event', |
|
| 151 | + 'args' => ['event_status' => 'trash'], |
|
| 152 | + 'capability' => 'ee_delete_event', |
|
| 153 | + 'obj_id' => $EVT_ID, |
|
| 154 | + 'noheader' => true, |
|
| 155 | + ], |
|
| 156 | + 'trash_events' => [ |
|
| 157 | + 'func' => '_trash_or_restore_events', |
|
| 158 | + 'args' => ['event_status' => 'trash'], |
|
| 159 | + 'capability' => 'ee_delete_events', |
|
| 160 | + 'noheader' => true, |
|
| 161 | + ], |
|
| 162 | + 'restore_event' => [ |
|
| 163 | + 'func' => '_trash_or_restore_event', |
|
| 164 | + 'args' => ['event_status' => 'draft'], |
|
| 165 | + 'capability' => 'ee_delete_event', |
|
| 166 | + 'obj_id' => $EVT_ID, |
|
| 167 | + 'noheader' => true, |
|
| 168 | + ], |
|
| 169 | + 'restore_events' => [ |
|
| 170 | + 'func' => '_trash_or_restore_events', |
|
| 171 | + 'args' => ['event_status' => 'draft'], |
|
| 172 | + 'capability' => 'ee_delete_events', |
|
| 173 | + 'noheader' => true, |
|
| 174 | + ], |
|
| 175 | + 'delete_event' => [ |
|
| 176 | + 'func' => '_delete_event', |
|
| 177 | + 'capability' => 'ee_delete_event', |
|
| 178 | + 'obj_id' => $EVT_ID, |
|
| 179 | + 'noheader' => true, |
|
| 180 | + ], |
|
| 181 | + 'delete_events' => [ |
|
| 182 | + 'func' => '_delete_events', |
|
| 183 | + 'capability' => 'ee_delete_events', |
|
| 184 | + 'noheader' => true, |
|
| 185 | + ], |
|
| 186 | + 'view_report' => [ |
|
| 187 | + 'func' => '_view_report', |
|
| 188 | + 'capability' => 'ee_edit_events', |
|
| 189 | + ], |
|
| 190 | + 'default_event_settings' => [ |
|
| 191 | + 'func' => '_default_event_settings', |
|
| 192 | + 'capability' => 'manage_options', |
|
| 193 | + ], |
|
| 194 | + 'update_default_event_settings' => [ |
|
| 195 | + 'func' => '_update_default_event_settings', |
|
| 196 | + 'capability' => 'manage_options', |
|
| 197 | + 'noheader' => true, |
|
| 198 | + ], |
|
| 199 | + 'template_settings' => [ |
|
| 200 | + 'func' => '_template_settings', |
|
| 201 | + 'capability' => 'manage_options', |
|
| 202 | + ], |
|
| 203 | + // event category tab related |
|
| 204 | + 'add_category' => [ |
|
| 205 | + 'func' => '_category_details', |
|
| 206 | + 'capability' => 'ee_edit_event_category', |
|
| 207 | + 'args' => ['add'], |
|
| 208 | + ], |
|
| 209 | + 'edit_category' => [ |
|
| 210 | + 'func' => '_category_details', |
|
| 211 | + 'capability' => 'ee_edit_event_category', |
|
| 212 | + 'args' => ['edit'], |
|
| 213 | + ], |
|
| 214 | + 'delete_categories' => [ |
|
| 215 | + 'func' => '_delete_categories', |
|
| 216 | + 'capability' => 'ee_delete_event_category', |
|
| 217 | + 'noheader' => true, |
|
| 218 | + ], |
|
| 219 | + 'delete_category' => [ |
|
| 220 | + 'func' => '_delete_categories', |
|
| 221 | + 'capability' => 'ee_delete_event_category', |
|
| 222 | + 'noheader' => true, |
|
| 223 | + ], |
|
| 224 | + 'insert_category' => [ |
|
| 225 | + 'func' => '_insert_or_update_category', |
|
| 226 | + 'args' => ['new_category' => true], |
|
| 227 | + 'capability' => 'ee_edit_event_category', |
|
| 228 | + 'noheader' => true, |
|
| 229 | + ], |
|
| 230 | + 'update_category' => [ |
|
| 231 | + 'func' => '_insert_or_update_category', |
|
| 232 | + 'args' => ['new_category' => false], |
|
| 233 | + 'capability' => 'ee_edit_event_category', |
|
| 234 | + 'noheader' => true, |
|
| 235 | + ], |
|
| 236 | + 'category_list' => [ |
|
| 237 | + 'func' => '_category_list_table', |
|
| 238 | + 'capability' => 'ee_manage_event_categories', |
|
| 239 | + ], |
|
| 240 | + 'preview_deletion' => [ |
|
| 241 | + 'func' => 'previewDeletion', |
|
| 242 | + 'capability' => 'ee_delete_events', |
|
| 243 | + ], |
|
| 244 | + 'confirm_deletion' => [ |
|
| 245 | + 'func' => 'confirmDeletion', |
|
| 246 | + 'capability' => 'ee_delete_events', |
|
| 247 | + 'noheader' => true, |
|
| 248 | + ], |
|
| 249 | + ]; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Set the _page_config property for this admin page group. |
|
| 255 | + */ |
|
| 256 | + protected function _set_page_config() |
|
| 257 | + { |
|
| 258 | + $post_id = $this->request->getRequestParam('post', 0, 'int'); |
|
| 259 | + $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 260 | + $this->_page_config = [ |
|
| 261 | + 'default' => [ |
|
| 262 | + 'nav' => [ |
|
| 263 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 264 | + 'order' => 10, |
|
| 265 | + ], |
|
| 266 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 267 | + 'help_tabs' => [ |
|
| 268 | + 'events_overview_help_tab' => [ |
|
| 269 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 270 | + 'filename' => 'events_overview', |
|
| 271 | + ], |
|
| 272 | + 'events_overview_table_column_headings_help_tab' => [ |
|
| 273 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 274 | + 'filename' => 'events_overview_table_column_headings', |
|
| 275 | + ], |
|
| 276 | + 'events_overview_filters_help_tab' => [ |
|
| 277 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 278 | + 'filename' => 'events_overview_filters', |
|
| 279 | + ], |
|
| 280 | + 'events_overview_view_help_tab' => [ |
|
| 281 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 282 | + 'filename' => 'events_overview_views', |
|
| 283 | + ], |
|
| 284 | + 'events_overview_other_help_tab' => [ |
|
| 285 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 286 | + 'filename' => 'events_overview_other', |
|
| 287 | + ], |
|
| 288 | + ], |
|
| 289 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 290 | + // 'help_tour' => array( |
|
| 291 | + // 'Event_Overview_Help_Tour', |
|
| 292 | + // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 293 | + // ), |
|
| 294 | + 'qtips' => [ |
|
| 295 | + 'EE_Event_List_Table_Tips', |
|
| 296 | + ], |
|
| 297 | + 'require_nonce' => false, |
|
| 298 | + ], |
|
| 299 | + 'create_new' => [ |
|
| 300 | + 'nav' => [ |
|
| 301 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 302 | + 'order' => 5, |
|
| 303 | + 'persistent' => false, |
|
| 304 | + ], |
|
| 305 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 306 | + 'help_tabs' => [ |
|
| 307 | + 'event_editor_help_tab' => [ |
|
| 308 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 309 | + 'filename' => 'event_editor', |
|
| 310 | + ], |
|
| 311 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 312 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 313 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 314 | + ], |
|
| 315 | + 'event_editor_venue_details_help_tab' => [ |
|
| 316 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 317 | + 'filename' => 'event_editor_venue_details', |
|
| 318 | + ], |
|
| 319 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 320 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 321 | + 'filename' => 'event_editor_event_datetimes', |
|
| 322 | + ], |
|
| 323 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 324 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 325 | + 'filename' => 'event_editor_event_tickets', |
|
| 326 | + ], |
|
| 327 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 328 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 329 | + 'filename' => 'event_editor_event_registration_options', |
|
| 330 | + ], |
|
| 331 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 332 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 333 | + 'filename' => 'event_editor_tags_categories', |
|
| 334 | + ], |
|
| 335 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 336 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 337 | + 'filename' => 'event_editor_questions_registrants', |
|
| 338 | + ], |
|
| 339 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 340 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 341 | + 'filename' => 'event_editor_save_new_event', |
|
| 342 | + ], |
|
| 343 | + 'event_editor_other_help_tab' => [ |
|
| 344 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 345 | + 'filename' => 'event_editor_other', |
|
| 346 | + ], |
|
| 347 | + ], |
|
| 348 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 349 | + // 'help_tour' => array( |
|
| 350 | + // 'Event_Editor_Help_Tour', |
|
| 351 | + // ), |
|
| 352 | + 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 353 | + 'require_nonce' => false, |
|
| 354 | + ], |
|
| 355 | + 'edit' => [ |
|
| 356 | + 'nav' => [ |
|
| 357 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 358 | + 'order' => 5, |
|
| 359 | + 'persistent' => false, |
|
| 360 | + 'url' => $post_id |
|
| 361 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 362 | + ['post' => $post_id, 'action' => 'edit'], |
|
| 363 | + $this->_current_page_view_url |
|
| 364 | + ) |
|
| 365 | + : $this->_admin_base_url, |
|
| 366 | + ], |
|
| 367 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 368 | + 'help_tabs' => [ |
|
| 369 | + 'event_editor_help_tab' => [ |
|
| 370 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 371 | + 'filename' => 'event_editor', |
|
| 372 | + ], |
|
| 373 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 374 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 375 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 376 | + ], |
|
| 377 | + 'event_editor_venue_details_help_tab' => [ |
|
| 378 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 379 | + 'filename' => 'event_editor_venue_details', |
|
| 380 | + ], |
|
| 381 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 382 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 383 | + 'filename' => 'event_editor_event_datetimes', |
|
| 384 | + ], |
|
| 385 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 386 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 387 | + 'filename' => 'event_editor_event_tickets', |
|
| 388 | + ], |
|
| 389 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 390 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 391 | + 'filename' => 'event_editor_event_registration_options', |
|
| 392 | + ], |
|
| 393 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 394 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 395 | + 'filename' => 'event_editor_tags_categories', |
|
| 396 | + ], |
|
| 397 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 398 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 399 | + 'filename' => 'event_editor_questions_registrants', |
|
| 400 | + ], |
|
| 401 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 402 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 403 | + 'filename' => 'event_editor_save_new_event', |
|
| 404 | + ], |
|
| 405 | + 'event_editor_other_help_tab' => [ |
|
| 406 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 407 | + 'filename' => 'event_editor_other', |
|
| 408 | + ], |
|
| 409 | + ], |
|
| 410 | + 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 411 | + 'require_nonce' => false, |
|
| 412 | + ], |
|
| 413 | + 'default_event_settings' => [ |
|
| 414 | + 'nav' => [ |
|
| 415 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 416 | + 'order' => 40, |
|
| 417 | + ], |
|
| 418 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 419 | + 'labels' => [ |
|
| 420 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 421 | + ], |
|
| 422 | + 'help_tabs' => [ |
|
| 423 | + 'default_settings_help_tab' => [ |
|
| 424 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 425 | + 'filename' => 'events_default_settings', |
|
| 426 | + ], |
|
| 427 | + 'default_settings_status_help_tab' => [ |
|
| 428 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 429 | + 'filename' => 'events_default_settings_status', |
|
| 430 | + ], |
|
| 431 | + 'default_maximum_tickets_help_tab' => [ |
|
| 432 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 433 | + 'filename' => 'events_default_settings_max_tickets', |
|
| 434 | + ], |
|
| 435 | + ], |
|
| 436 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 437 | + // 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 438 | + 'require_nonce' => false, |
|
| 439 | + ], |
|
| 440 | + // template settings |
|
| 441 | + 'template_settings' => [ |
|
| 442 | + 'nav' => [ |
|
| 443 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 444 | + 'order' => 30, |
|
| 445 | + ], |
|
| 446 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 447 | + 'help_tabs' => [ |
|
| 448 | + 'general_settings_templates_help_tab' => [ |
|
| 449 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 450 | + 'filename' => 'general_settings_templates', |
|
| 451 | + ], |
|
| 452 | + ], |
|
| 453 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 454 | + // 'help_tour' => array('Templates_Help_Tour'), |
|
| 455 | + 'require_nonce' => false, |
|
| 456 | + ], |
|
| 457 | + // event category stuff |
|
| 458 | + 'add_category' => [ |
|
| 459 | + 'nav' => [ |
|
| 460 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 461 | + 'order' => 15, |
|
| 462 | + 'persistent' => false, |
|
| 463 | + ], |
|
| 464 | + 'help_tabs' => [ |
|
| 465 | + 'add_category_help_tab' => [ |
|
| 466 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 467 | + 'filename' => 'events_add_category', |
|
| 468 | + ], |
|
| 469 | + ], |
|
| 470 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 471 | + // 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 472 | + 'metaboxes' => ['_publish_post_box'], |
|
| 473 | + 'require_nonce' => false, |
|
| 474 | + ], |
|
| 475 | + 'edit_category' => [ |
|
| 476 | + 'nav' => [ |
|
| 477 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 478 | + 'order' => 15, |
|
| 479 | + 'persistent' => false, |
|
| 480 | + 'url' => $EVT_CAT_ID |
|
| 481 | + ? add_query_arg( |
|
| 482 | + ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
| 483 | + $this->_current_page_view_url |
|
| 484 | + ) |
|
| 485 | + : $this->_admin_base_url, |
|
| 486 | + ], |
|
| 487 | + 'help_tabs' => [ |
|
| 488 | + 'edit_category_help_tab' => [ |
|
| 489 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 490 | + 'filename' => 'events_edit_category', |
|
| 491 | + ], |
|
| 492 | + ], |
|
| 493 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 494 | + 'metaboxes' => ['_publish_post_box'], |
|
| 495 | + 'require_nonce' => false, |
|
| 496 | + ], |
|
| 497 | + 'category_list' => [ |
|
| 498 | + 'nav' => [ |
|
| 499 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 500 | + 'order' => 20, |
|
| 501 | + ], |
|
| 502 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 503 | + 'help_tabs' => [ |
|
| 504 | + 'events_categories_help_tab' => [ |
|
| 505 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 506 | + 'filename' => 'events_categories', |
|
| 507 | + ], |
|
| 508 | + 'events_categories_table_column_headings_help_tab' => [ |
|
| 509 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 510 | + 'filename' => 'events_categories_table_column_headings', |
|
| 511 | + ], |
|
| 512 | + 'events_categories_view_help_tab' => [ |
|
| 513 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 514 | + 'filename' => 'events_categories_views', |
|
| 515 | + ], |
|
| 516 | + 'events_categories_other_help_tab' => [ |
|
| 517 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 518 | + 'filename' => 'events_categories_other', |
|
| 519 | + ], |
|
| 520 | + ], |
|
| 521 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 522 | + // 'help_tour' => array( |
|
| 523 | + // 'Event_Categories_Help_Tour', |
|
| 524 | + // ), |
|
| 525 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 526 | + 'require_nonce' => false, |
|
| 527 | + ], |
|
| 528 | + 'preview_deletion' => [ |
|
| 529 | + 'nav' => [ |
|
| 530 | + 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 531 | + 'order' => 15, |
|
| 532 | + 'persistent' => false, |
|
| 533 | + 'url' => '', |
|
| 534 | + ], |
|
| 535 | + 'require_nonce' => false, |
|
| 536 | + ], |
|
| 537 | + ]; |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 543 | + */ |
|
| 544 | + protected function _add_screen_options() |
|
| 545 | + { |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Implementing the screen options for the 'default' route. |
|
| 551 | + */ |
|
| 552 | + protected function _add_screen_options_default() |
|
| 553 | + { |
|
| 554 | + $this->_per_page_screen_option(); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Implementing screen options for the category list route. |
|
| 560 | + */ |
|
| 561 | + protected function _add_screen_options_category_list() |
|
| 562 | + { |
|
| 563 | + $page_title = $this->_admin_page_title; |
|
| 564 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 565 | + $this->_per_page_screen_option(); |
|
| 566 | + $this->_admin_page_title = $page_title; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Used to register any global feature pointers for the admin page group. |
|
| 572 | + */ |
|
| 573 | + protected function _add_feature_pointers() |
|
| 574 | + { |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 580 | + */ |
|
| 581 | + public function load_scripts_styles() |
|
| 582 | + { |
|
| 583 | + wp_register_style( |
|
| 584 | + 'events-admin-css', |
|
| 585 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 586 | + [], |
|
| 587 | + EVENT_ESPRESSO_VERSION |
|
| 588 | + ); |
|
| 589 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION); |
|
| 590 | + wp_enqueue_style('events-admin-css'); |
|
| 591 | + wp_enqueue_style('ee-cat-admin'); |
|
| 592 | + // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 593 | + // registers for all views |
|
| 594 | + // scripts |
|
| 595 | + wp_register_script( |
|
| 596 | + 'event_editor_js', |
|
| 597 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 598 | + ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 599 | + EVENT_ESPRESSO_VERSION, |
|
| 600 | + true |
|
| 601 | + ); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * Enqueuing scripts and styles specific to this view |
|
| 607 | + */ |
|
| 608 | + public function load_scripts_styles_create_new() |
|
| 609 | + { |
|
| 610 | + $this->load_scripts_styles_edit(); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Enqueuing scripts and styles specific to this view |
|
| 616 | + */ |
|
| 617 | + public function load_scripts_styles_edit() |
|
| 618 | + { |
|
| 619 | + // styles |
|
| 620 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 621 | + wp_register_style( |
|
| 622 | + 'event-editor-css', |
|
| 623 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 624 | + ['ee-admin-css'], |
|
| 625 | + EVENT_ESPRESSO_VERSION |
|
| 626 | + ); |
|
| 627 | + wp_enqueue_style('event-editor-css'); |
|
| 628 | + // scripts |
|
| 629 | + wp_register_script( |
|
| 630 | + 'event-datetime-metabox', |
|
| 631 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 632 | + ['event_editor_js', 'ee-datepicker'], |
|
| 633 | + EVENT_ESPRESSO_VERSION |
|
| 634 | + ); |
|
| 635 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * Populating the _views property for the category list table view. |
|
| 641 | + */ |
|
| 642 | + protected function _set_list_table_views_category_list() |
|
| 643 | + { |
|
| 644 | + $this->_views = [ |
|
| 645 | + 'all' => [ |
|
| 646 | + 'slug' => 'all', |
|
| 647 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 648 | + 'count' => 0, |
|
| 649 | + 'bulk_action' => [ |
|
| 650 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 651 | + ], |
|
| 652 | + ], |
|
| 653 | + ]; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 659 | + */ |
|
| 660 | + public function admin_init() |
|
| 661 | + { |
|
| 662 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 663 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 664 | + 'event_espresso' |
|
| 665 | + ); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 671 | + * group. |
|
| 672 | + */ |
|
| 673 | + public function admin_notices() |
|
| 674 | + { |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 680 | + * this admin page group. |
|
| 681 | + */ |
|
| 682 | + public function admin_footer_scripts() |
|
| 683 | + { |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + |
|
| 687 | + /** |
|
| 688 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 689 | + * warning (via EE_Error::add_error()); |
|
| 690 | + * |
|
| 691 | + * @param EE_Event $event Event object |
|
| 692 | + * @param string $req_type |
|
| 693 | + * @return void |
|
| 694 | + * @throws EE_Error |
|
| 695 | + * @throws ReflectionException |
|
| 696 | + */ |
|
| 697 | + public function verify_event_edit($event = null, $req_type = '') |
|
| 698 | + { |
|
| 699 | + // don't need to do this when processing |
|
| 700 | + if (! empty($req_type)) { |
|
| 701 | + return; |
|
| 702 | + } |
|
| 703 | + // no event? |
|
| 704 | + if (empty($event)) { |
|
| 705 | + // set event |
|
| 706 | + $event = $this->_cpt_model_obj; |
|
| 707 | + } |
|
| 708 | + // STILL no event? |
|
| 709 | + if (! $event instanceof EE_Event) { |
|
| 710 | + return; |
|
| 711 | + } |
|
| 712 | + $orig_status = $event->status(); |
|
| 713 | + // first check if event is active. |
|
| 714 | + if ( |
|
| 715 | + $orig_status === EEM_Event::cancelled |
|
| 716 | + || $orig_status === EEM_Event::postponed |
|
| 717 | + || $event->is_expired() |
|
| 718 | + || $event->is_inactive() |
|
| 719 | + ) { |
|
| 720 | + return; |
|
| 721 | + } |
|
| 722 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
| 723 | + if ($event->is_sold_out(true)) { |
|
| 724 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 725 | + EE_Error::add_attention( |
|
| 726 | + sprintf( |
|
| 727 | + esc_html__( |
|
| 728 | + '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.', |
|
| 729 | + 'event_espresso' |
|
| 730 | + ), |
|
| 731 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 732 | + ) |
|
| 733 | + ); |
|
| 734 | + } |
|
| 735 | + return; |
|
| 736 | + } elseif ($orig_status === EEM_Event::sold_out) { |
|
| 737 | + EE_Error::add_attention( |
|
| 738 | + sprintf( |
|
| 739 | + esc_html__( |
|
| 740 | + '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.', |
|
| 741 | + 'event_espresso' |
|
| 742 | + ), |
|
| 743 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 744 | + ) |
|
| 745 | + ); |
|
| 746 | + } |
|
| 747 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 748 | + if (! $event->tickets_on_sale()) { |
|
| 749 | + return; |
|
| 750 | + } |
|
| 751 | + // made it here so show warning |
|
| 752 | + $this->_edit_event_warning(); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 758 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 759 | + * |
|
| 760 | + * @access protected |
|
| 761 | + * @return void |
|
| 762 | + */ |
|
| 763 | + protected function _edit_event_warning() |
|
| 764 | + { |
|
| 765 | + // we don't want to add warnings during these requests |
|
| 766 | + if ($this->request->getRequestParam('action') === 'editpost') { |
|
| 767 | + return; |
|
| 768 | + } |
|
| 769 | + EE_Error::add_attention( |
|
| 770 | + sprintf( |
|
| 771 | + esc_html__( |
|
| 772 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 773 | + 'event_espresso' |
|
| 774 | + ), |
|
| 775 | + '<a class="espresso-help-tab-lnk">', |
|
| 776 | + '</a>' |
|
| 777 | + ) |
|
| 778 | + ); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 784 | + * Otherwise, do the normal logic |
|
| 785 | + * |
|
| 786 | + * @return void |
|
| 787 | + * @throws EE_Error |
|
| 788 | + */ |
|
| 789 | + protected function _create_new_cpt_item() |
|
| 790 | + { |
|
| 791 | + $has_timezone_string = get_option('timezone_string'); |
|
| 792 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 793 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 794 | + EE_Error::add_attention( |
|
| 795 | + sprintf( |
|
| 796 | + esc_html__( |
|
| 797 | + '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', |
|
| 798 | + 'event_espresso' |
|
| 799 | + ), |
|
| 800 | + '<br>', |
|
| 801 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 802 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 803 | + . '</select>', |
|
| 804 | + '<button class="button button-secondary timezone-submit">', |
|
| 805 | + '</button><span class="spinner"></span>' |
|
| 806 | + ), |
|
| 807 | + __FILE__, |
|
| 808 | + __FUNCTION__, |
|
| 809 | + __LINE__ |
|
| 810 | + ); |
|
| 811 | + } |
|
| 812 | + parent::_create_new_cpt_item(); |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * Sets the _views property for the default route in this admin page group. |
|
| 818 | + */ |
|
| 819 | + protected function _set_list_table_views_default() |
|
| 820 | + { |
|
| 821 | + $this->_views = [ |
|
| 822 | + 'all' => [ |
|
| 823 | + 'slug' => 'all', |
|
| 824 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 825 | + 'count' => 0, |
|
| 826 | + 'bulk_action' => [ |
|
| 827 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 828 | + ], |
|
| 829 | + ], |
|
| 830 | + 'draft' => [ |
|
| 831 | + 'slug' => 'draft', |
|
| 832 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 833 | + 'count' => 0, |
|
| 834 | + 'bulk_action' => [ |
|
| 835 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 836 | + ], |
|
| 837 | + ], |
|
| 838 | + ]; |
|
| 839 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 840 | + $this->_views['trash'] = [ |
|
| 841 | + 'slug' => 'trash', |
|
| 842 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 843 | + 'count' => 0, |
|
| 844 | + 'bulk_action' => [ |
|
| 845 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 846 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 847 | + ], |
|
| 848 | + ]; |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Provides the legend item array for the default list table view. |
|
| 855 | + * |
|
| 856 | + * @return array |
|
| 857 | + * @throws EE_Error |
|
| 858 | + * @throws EE_Error |
|
| 859 | + */ |
|
| 860 | + protected function _event_legend_items() |
|
| 861 | + { |
|
| 862 | + $items = [ |
|
| 863 | + 'view_details' => [ |
|
| 864 | + 'class' => 'dashicons dashicons-search', |
|
| 865 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 866 | + ], |
|
| 867 | + 'edit_event' => [ |
|
| 868 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 869 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 870 | + ], |
|
| 871 | + 'view_attendees' => [ |
|
| 872 | + 'class' => 'dashicons dashicons-groups', |
|
| 873 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 874 | + ], |
|
| 875 | + ]; |
|
| 876 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 877 | + $statuses = [ |
|
| 878 | + 'sold_out_status' => [ |
|
| 879 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 880 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 881 | + ], |
|
| 882 | + 'active_status' => [ |
|
| 883 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 884 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 885 | + ], |
|
| 886 | + 'upcoming_status' => [ |
|
| 887 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 888 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 889 | + ], |
|
| 890 | + 'postponed_status' => [ |
|
| 891 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 892 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 893 | + ], |
|
| 894 | + 'cancelled_status' => [ |
|
| 895 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 896 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 897 | + ], |
|
| 898 | + 'expired_status' => [ |
|
| 899 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 900 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 901 | + ], |
|
| 902 | + 'inactive_status' => [ |
|
| 903 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 904 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 905 | + ], |
|
| 906 | + ]; |
|
| 907 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 908 | + return array_merge($items, $statuses); |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * @return EEM_Event |
|
| 914 | + * @throws EE_Error |
|
| 915 | + * @throws ReflectionException |
|
| 916 | + */ |
|
| 917 | + private function _event_model() |
|
| 918 | + { |
|
| 919 | + if (! $this->_event_model instanceof EEM_Event) { |
|
| 920 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 921 | + } |
|
| 922 | + return $this->_event_model; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 928 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 929 | + * |
|
| 930 | + * @param string $return the current html |
|
| 931 | + * @param int $id the post id for the page |
|
| 932 | + * @param string $new_title What the title is |
|
| 933 | + * @param string $new_slug what the slug is |
|
| 934 | + * @return string The new html string for the permalink area |
|
| 935 | + */ |
|
| 936 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 937 | + { |
|
| 938 | + // make sure this is only when editing |
|
| 939 | + if (! empty($id)) { |
|
| 940 | + $post = get_post($id); |
|
| 941 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 942 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 943 | + . '</a> '; |
|
| 944 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 945 | + . $post->ID |
|
| 946 | + . ']">'; |
|
| 947 | + } |
|
| 948 | + return $return; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * _events_overview_list_table |
|
| 954 | + * This contains the logic for showing the events_overview list |
|
| 955 | + * |
|
| 956 | + * @access protected |
|
| 957 | + * @return void |
|
| 958 | + * @throws EE_Error |
|
| 959 | + */ |
|
| 960 | + protected function _events_overview_list_table() |
|
| 961 | + { |
|
| 962 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 963 | + $this->_template_args['after_list_table'] = |
|
| 964 | + ! empty($this->_template_args['after_list_table']) |
|
| 965 | + ? (array) $this->_template_args['after_list_table'] |
|
| 966 | + : []; |
|
| 967 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 968 | + . EEH_Template::get_button_or_link( |
|
| 969 | + get_post_type_archive_link('espresso_events'), |
|
| 970 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
| 971 | + 'button' |
|
| 972 | + ); |
|
| 973 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend( |
|
| 974 | + $this->_event_legend_items() |
|
| 975 | + ); |
|
| 976 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 977 | + 'create_new', |
|
| 978 | + 'add', |
|
| 979 | + [], |
|
| 980 | + 'add-new-h2' |
|
| 981 | + ); |
|
| 982 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + |
|
| 986 | + /** |
|
| 987 | + * this allows for extra misc actions in the default WP publish box |
|
| 988 | + * |
|
| 989 | + * @return void |
|
| 990 | + * @throws EE_Error |
|
| 991 | + * @throws ReflectionException |
|
| 992 | + */ |
|
| 993 | + public function extra_misc_actions_publish_box() |
|
| 994 | + { |
|
| 995 | + $this->_generate_publish_box_extra_content(); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1001 | + * saved. |
|
| 1002 | + * Typically you would use this to save any additional data. |
|
| 1003 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1004 | + * ALSO very important. When a post transitions from scheduled to published, |
|
| 1005 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1006 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1007 | + * |
|
| 1008 | + * @access protected |
|
| 1009 | + * @abstract |
|
| 1010 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1011 | + * @param object $post The post object of the cpt that was saved. |
|
| 1012 | + * @return void |
|
| 1013 | + * @throws EE_Error |
|
| 1014 | + * @throws ReflectionException |
|
| 1015 | + */ |
|
| 1016 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 1017 | + { |
|
| 1018 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1019 | + // get out we're not processing an event save. |
|
| 1020 | + return; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + $event_values = [ |
|
| 1024 | + 'EVT_display_desc' => $this->request->getRequestParam('display_desc', false, 'bool'), |
|
| 1025 | + 'EVT_display_ticket_selector' => $this->request->getRequestParam( |
|
| 1026 | + 'display_ticket_selector', |
|
| 1027 | + false, |
|
| 1028 | + 'bool' |
|
| 1029 | + ), |
|
| 1030 | + 'EVT_additional_limit' => min( |
|
| 1031 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1032 | + $this->request->getRequestParam('additional_limit', null, 'int') |
|
| 1033 | + ), |
|
| 1034 | + 'EVT_default_registration_status' => $this->request->getRequestParam( |
|
| 1035 | + 'EVT_default_registration_status', |
|
| 1036 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 1037 | + ), |
|
| 1038 | + |
|
| 1039 | + 'EVT_member_only' => $this->request->getRequestParam('member_only', false, 'bool'), |
|
| 1040 | + 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'), |
|
| 1041 | + 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
| 1042 | + 'EVT_external_URL' => $this->request->getRequestParam('externalURL'), |
|
| 1043 | + 'EVT_phone' => $this->request->getRequestParam('event_phone'), |
|
| 1044 | + ]; |
|
| 1045 | + // update event |
|
| 1046 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1047 | + // get event_object for other metaboxes... |
|
| 1048 | + // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
| 1049 | + // i have to setup where conditions to override the filters in the model |
|
| 1050 | + // that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 1051 | + $event = $this->_event_model()->get_one( |
|
| 1052 | + [ |
|
| 1053 | + [ |
|
| 1054 | + $this->_event_model()->primary_key_name() => $post_id, |
|
| 1055 | + 'OR' => [ |
|
| 1056 | + 'status' => $post->post_status, |
|
| 1057 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1058 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1059 | + 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
| 1060 | + ], |
|
| 1061 | + ], |
|
| 1062 | + ] |
|
| 1063 | + ); |
|
| 1064 | + // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 1065 | + $event_update_callbacks = apply_filters( |
|
| 1066 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1067 | + [ |
|
| 1068 | + [$this, '_default_venue_update'], |
|
| 1069 | + [$this, '_default_tickets_update'], |
|
| 1070 | + ] |
|
| 1071 | + ); |
|
| 1072 | + $att_success = true; |
|
| 1073 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 1074 | + $_success = is_callable($e_callback) |
|
| 1075 | + ? call_user_func($e_callback, $event, $this->request->requestParams()) |
|
| 1076 | + : false; |
|
| 1077 | + // if ANY of these updates fail then we want the appropriate global error message |
|
| 1078 | + $att_success = ! $att_success ? $att_success : $_success; |
|
| 1079 | + } |
|
| 1080 | + // any errors? |
|
| 1081 | + if ($success && false === $att_success) { |
|
| 1082 | + EE_Error::add_error( |
|
| 1083 | + esc_html__( |
|
| 1084 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1085 | + 'event_espresso' |
|
| 1086 | + ), |
|
| 1087 | + __FILE__, |
|
| 1088 | + __FUNCTION__, |
|
| 1089 | + __LINE__ |
|
| 1090 | + ); |
|
| 1091 | + } elseif ($success === false) { |
|
| 1092 | + EE_Error::add_error( |
|
| 1093 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1094 | + __FILE__, |
|
| 1095 | + __FUNCTION__, |
|
| 1096 | + __LINE__ |
|
| 1097 | + ); |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + |
|
| 1102 | + /** |
|
| 1103 | + * @param int $post_id |
|
| 1104 | + * @param int $revision_id |
|
| 1105 | + * @throws EE_Error |
|
| 1106 | + * @throws EE_Error |
|
| 1107 | + * @throws ReflectionException |
|
| 1108 | + * @see parent::restore_item() |
|
| 1109 | + */ |
|
| 1110 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1111 | + { |
|
| 1112 | + // copy existing event meta to new post |
|
| 1113 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1114 | + if ($post_evt instanceof EE_Event) { |
|
| 1115 | + // meta revision restore |
|
| 1116 | + $post_evt->restore_revision($revision_id); |
|
| 1117 | + // related objs restore |
|
| 1118 | + $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1119 | + } |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + |
|
| 1123 | + /** |
|
| 1124 | + * Attach the venue to the Event |
|
| 1125 | + * |
|
| 1126 | + * @param EE_Event $event Event Object to add the venue to |
|
| 1127 | + * @param array $data The request data from the form |
|
| 1128 | + * @return bool Success or fail. |
|
| 1129 | + * @throws EE_Error |
|
| 1130 | + * @throws ReflectionException |
|
| 1131 | + */ |
|
| 1132 | + protected function _default_venue_update(EE_Event $event, $data) |
|
| 1133 | + { |
|
| 1134 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1135 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1136 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1137 | + // very important. If we don't have a venue name... |
|
| 1138 | + // then we'll get out because not necessary to create empty venue |
|
| 1139 | + if (empty($data['venue_title'])) { |
|
| 1140 | + return false; |
|
| 1141 | + } |
|
| 1142 | + $venue_array = [ |
|
| 1143 | + 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
| 1144 | + 'VNU_name' => $data['venue_title'], |
|
| 1145 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1146 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1147 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
| 1148 | + ? $data['venue_short_description'] |
|
| 1149 | + : null, |
|
| 1150 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1151 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1152 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1153 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1154 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1155 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1156 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1157 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1158 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1159 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1160 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1161 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1162 | + 'status' => 'publish', |
|
| 1163 | + ]; |
|
| 1164 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1165 | + if (! empty($venue_id)) { |
|
| 1166 | + $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1167 | + $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1168 | + // 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. |
|
| 1169 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1170 | + return $rows_affected > 0; |
|
| 1171 | + } |
|
| 1172 | + // we insert the venue |
|
| 1173 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1174 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1175 | + return ! empty($venue_id); |
|
| 1176 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + /** |
|
| 1181 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1182 | + * |
|
| 1183 | + * @param EE_Event $event The Event object we're attaching data to |
|
| 1184 | + * @param array $data The request data from the form |
|
| 1185 | + * @return array |
|
| 1186 | + * @throws EE_Error |
|
| 1187 | + * @throws ReflectionException |
|
| 1188 | + * @throws Exception |
|
| 1189 | + */ |
|
| 1190 | + protected function _default_tickets_update(EE_Event $event, $data) |
|
| 1191 | + { |
|
| 1192 | + $datetime = null; |
|
| 1193 | + $saved_tickets = []; |
|
| 1194 | + $event_timezone = $event->get_timezone(); |
|
| 1195 | + $date_formats = ['Y-m-d', 'h:i a']; |
|
| 1196 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 1197 | + // trim all values to ensure any excess whitespace is removed. |
|
| 1198 | + $datetime_data = array_map('trim', $datetime_data); |
|
| 1199 | + $datetime_data['DTT_EVT_end'] = |
|
| 1200 | + isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
|
| 1201 | + ? $datetime_data['DTT_EVT_end'] |
|
| 1202 | + : $datetime_data['DTT_EVT_start']; |
|
| 1203 | + $datetime_values = [ |
|
| 1204 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
| 1205 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 1206 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 1207 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
| 1208 | + 'DTT_order' => $row, |
|
| 1209 | + ]; |
|
| 1210 | + // if we have an id then let's get existing object first and then set the new values. |
|
| 1211 | + // Otherwise we instantiate a new object for save. |
|
| 1212 | + if (! empty($datetime_data['DTT_ID'])) { |
|
| 1213 | + $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 1214 | + if (! $datetime instanceof EE_Ticket) { |
|
| 1215 | + throw new RuntimeException( |
|
| 1216 | + sprintf( |
|
| 1217 | + esc_html__( |
|
| 1218 | + 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1219 | + 'event_espresso' |
|
| 1220 | + ), |
|
| 1221 | + $datetime_data['DTT_ID'] |
|
| 1222 | + ) |
|
| 1223 | + ); |
|
| 1224 | + } |
|
| 1225 | + $datetime->set_date_format($date_formats[0]); |
|
| 1226 | + $datetime->set_time_format($date_formats[1]); |
|
| 1227 | + foreach ($datetime_values as $field => $value) { |
|
| 1228 | + $datetime->set($field, $value); |
|
| 1229 | + } |
|
| 1230 | + } else { |
|
| 1231 | + $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
| 1232 | + } |
|
| 1233 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1234 | + throw new RuntimeException( |
|
| 1235 | + sprintf( |
|
| 1236 | + esc_html__( |
|
| 1237 | + 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
| 1238 | + 'event_espresso' |
|
| 1239 | + ), |
|
| 1240 | + print_r($datetime_values, true) |
|
| 1241 | + ) |
|
| 1242 | + ); |
|
| 1243 | + } |
|
| 1244 | + // before going any further make sure our dates are setup correctly |
|
| 1245 | + // so that the end date is always equal or greater than the start date. |
|
| 1246 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 1247 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 1248 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 1249 | + } |
|
| 1250 | + $datetime->save(); |
|
| 1251 | + $event->_add_relation_to($datetime, 'Datetime'); |
|
| 1252 | + } |
|
| 1253 | + // no datetimes get deleted so we don't do any of that logic here. |
|
| 1254 | + // update tickets next |
|
| 1255 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1256 | + |
|
| 1257 | + // set up some default start and end dates in case those are not present in the incoming data |
|
| 1258 | + $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 1259 | + $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
| 1260 | + // use the start date of the first datetime for the end date |
|
| 1261 | + $first_datetime = $event->first_datetime(); |
|
| 1262 | + $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
| 1263 | + |
|
| 1264 | + // now process the incoming data |
|
| 1265 | + foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
| 1266 | + $update_prices = false; |
|
| 1267 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1268 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1269 | + : 0; |
|
| 1270 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1271 | + $ticket_data = array_map('trim', $ticket_data); |
|
| 1272 | + $ticket_values = [ |
|
| 1273 | + 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
| 1274 | + 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
| 1275 | + 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
| 1276 | + 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
| 1277 | + 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
| 1278 | + ? $ticket_data['TKT_start_date'] |
|
| 1279 | + : $default_start_date, |
|
| 1280 | + 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
| 1281 | + ? $ticket_data['TKT_end_date'] |
|
| 1282 | + : $default_end_date, |
|
| 1283 | + 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
| 1284 | + || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
| 1285 | + ? $ticket_data['TKT_qty'] |
|
| 1286 | + : EE_INF, |
|
| 1287 | + 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
| 1288 | + || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
| 1289 | + ? $ticket_data['TKT_uses'] |
|
| 1290 | + : EE_INF, |
|
| 1291 | + 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
| 1292 | + 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
| 1293 | + 'TKT_order' => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row, |
|
| 1294 | + 'TKT_price' => $ticket_price, |
|
| 1295 | + 'TKT_row' => $row, |
|
| 1296 | + ]; |
|
| 1297 | + // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 1298 | + // which means in turn that the prices will become new prices as well. |
|
| 1299 | + if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
| 1300 | + $ticket_values['TKT_ID'] = 0; |
|
| 1301 | + $ticket_values['TKT_is_default'] = 0; |
|
| 1302 | + $update_prices = true; |
|
| 1303 | + } |
|
| 1304 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1305 | + // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
| 1306 | + // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
| 1307 | + // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
| 1308 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1309 | + if (! empty($ticket_data['TKT_ID'])) { |
|
| 1310 | + $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
| 1311 | + if (! $existing_ticket instanceof EE_Ticket) { |
|
| 1312 | + throw new RuntimeException( |
|
| 1313 | + sprintf( |
|
| 1314 | + esc_html__( |
|
| 1315 | + 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1316 | + 'event_espresso' |
|
| 1317 | + ), |
|
| 1318 | + $ticket_data['TKT_ID'] |
|
| 1319 | + ) |
|
| 1320 | + ); |
|
| 1321 | + } |
|
| 1322 | + $ticket_sold = $existing_ticket->count_related( |
|
| 1323 | + 'Registration', |
|
| 1324 | + [ |
|
| 1325 | + [ |
|
| 1326 | + 'STS_ID' => [ |
|
| 1327 | + 'NOT IN', |
|
| 1328 | + [EEM_Registration::status_id_incomplete], |
|
| 1329 | + ], |
|
| 1330 | + ], |
|
| 1331 | + ] |
|
| 1332 | + ) > 0; |
|
| 1333 | + // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
| 1334 | + // if they are different then we create a new ticket (if $ticket_sold) |
|
| 1335 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 1336 | + $create_new_ticket = $ticket_sold |
|
| 1337 | + && $ticket_price !== $existing_ticket->price() |
|
| 1338 | + && ! $existing_ticket->deleted(); |
|
| 1339 | + $existing_ticket->set_date_format($date_formats[0]); |
|
| 1340 | + $existing_ticket->set_time_format($date_formats[1]); |
|
| 1341 | + // set new values |
|
| 1342 | + foreach ($ticket_values as $field => $value) { |
|
| 1343 | + if ($field == 'TKT_qty') { |
|
| 1344 | + $existing_ticket->set_qty($value); |
|
| 1345 | + } elseif ($field == 'TKT_price') { |
|
| 1346 | + $existing_ticket->set('TKT_price', $ticket_price); |
|
| 1347 | + } else { |
|
| 1348 | + $existing_ticket->set($field, $value); |
|
| 1349 | + } |
|
| 1350 | + } |
|
| 1351 | + $ticket = $existing_ticket; |
|
| 1352 | + // if $create_new_ticket is false then we can safely update the existing ticket. |
|
| 1353 | + // Otherwise we have to create a new ticket. |
|
| 1354 | + if ($create_new_ticket) { |
|
| 1355 | + // archive the old ticket first |
|
| 1356 | + $existing_ticket->set('TKT_deleted', 1); |
|
| 1357 | + $existing_ticket->save(); |
|
| 1358 | + // make sure this ticket is still recorded in our $saved_tickets |
|
| 1359 | + // so we don't run it through the regular trash routine. |
|
| 1360 | + $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
| 1361 | + // create new ticket that's a copy of the existing except, |
|
| 1362 | + // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
| 1363 | + $new_ticket = clone $existing_ticket; |
|
| 1364 | + $new_ticket->set('TKT_ID', 0); |
|
| 1365 | + $new_ticket->set('TKT_deleted', 0); |
|
| 1366 | + $new_ticket->set('TKT_sold', 0); |
|
| 1367 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1368 | + $update_prices = true; |
|
| 1369 | + $ticket = $new_ticket; |
|
| 1370 | + } |
|
| 1371 | + } else { |
|
| 1372 | + // no TKT_id so a new ticket |
|
| 1373 | + $ticket_values['TKT_price'] = $ticket_price; |
|
| 1374 | + $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
| 1375 | + $update_prices = true; |
|
| 1376 | + } |
|
| 1377 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1378 | + throw new RuntimeException( |
|
| 1379 | + sprintf( |
|
| 1380 | + esc_html__( |
|
| 1381 | + 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
| 1382 | + 'event_espresso' |
|
| 1383 | + ), |
|
| 1384 | + print_r($ticket_values, true) |
|
| 1385 | + ) |
|
| 1386 | + ); |
|
| 1387 | + } |
|
| 1388 | + // cap ticket qty by datetime reg limits |
|
| 1389 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 1390 | + // update ticket. |
|
| 1391 | + $ticket->save(); |
|
| 1392 | + // before going any further make sure our dates are setup correctly |
|
| 1393 | + // so that the end date is always equal or greater than the start date. |
|
| 1394 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 1395 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 1396 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 1397 | + $ticket->save(); |
|
| 1398 | + } |
|
| 1399 | + // initially let's add the ticket to the datetime |
|
| 1400 | + $datetime->_add_relation_to($ticket, 'Ticket'); |
|
| 1401 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 1402 | + // add prices to ticket |
|
| 1403 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices); |
|
| 1404 | + } |
|
| 1405 | + // however now we need to handle permanently deleting tickets via the ui. |
|
| 1406 | + // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
| 1407 | + // However, it does allow for deleting tickets that have no tickets sold, |
|
| 1408 | + // in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1409 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets; |
|
| 1410 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1411 | + foreach ($tickets_removed as $id) { |
|
| 1412 | + $id = absint($id); |
|
| 1413 | + // get the ticket for this id |
|
| 1414 | + $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
| 1415 | + if (! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1416 | + continue; |
|
| 1417 | + } |
|
| 1418 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 1419 | + // (remember this process can ONLY kick off if there are NO tickets sold) |
|
| 1420 | + $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
| 1421 | + foreach ($related_datetimes as $related_datetime) { |
|
| 1422 | + $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
| 1423 | + } |
|
| 1424 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 1425 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1426 | + $ticket_to_remove->delete_related_permanently('Price'); |
|
| 1427 | + // finally let's delete this ticket |
|
| 1428 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1429 | + $ticket_to_remove->delete_permanently(); |
|
| 1430 | + } |
|
| 1431 | + return [$datetime, $saved_tickets]; |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + |
|
| 1435 | + /** |
|
| 1436 | + * This attaches a list of given prices to a ticket. |
|
| 1437 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1438 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1439 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1440 | + * |
|
| 1441 | + * @access private |
|
| 1442 | + * @param array $prices_data Array of prices from the form. |
|
| 1443 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1444 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1445 | + * @return void |
|
| 1446 | + * @throws EE_Error |
|
| 1447 | + * @throws ReflectionException |
|
| 1448 | + */ |
|
| 1449 | + private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false) |
|
| 1450 | + { |
|
| 1451 | + $timezone = $ticket->get_timezone(); |
|
| 1452 | + foreach ($prices_data as $row => $price_data) { |
|
| 1453 | + $price_values = [ |
|
| 1454 | + 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
| 1455 | + 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
| 1456 | + 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
| 1457 | + 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
| 1458 | + 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
| 1459 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1460 | + 'PRC_order' => $row, |
|
| 1461 | + ]; |
|
| 1462 | + if ($new_prices || empty($price_values['PRC_ID'])) { |
|
| 1463 | + $price_values['PRC_ID'] = 0; |
|
| 1464 | + $price = EE_Price::new_instance($price_values, $timezone); |
|
| 1465 | + } else { |
|
| 1466 | + $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
| 1467 | + // update this price with new values |
|
| 1468 | + foreach ($price_values as $field => $new_price) { |
|
| 1469 | + $price->set($field, $new_price); |
|
| 1470 | + } |
|
| 1471 | + } |
|
| 1472 | + if (! $price instanceof EE_Price) { |
|
| 1473 | + throw new RuntimeException( |
|
| 1474 | + sprintf( |
|
| 1475 | + esc_html__( |
|
| 1476 | + 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
| 1477 | + 'event_espresso' |
|
| 1478 | + ), |
|
| 1479 | + print_r($price_values, true) |
|
| 1480 | + ) |
|
| 1481 | + ); |
|
| 1482 | + } |
|
| 1483 | + $price->save(); |
|
| 1484 | + $ticket->_add_relation_to($price, 'Price'); |
|
| 1485 | + } |
|
| 1486 | + } |
|
| 1487 | + |
|
| 1488 | + |
|
| 1489 | + /** |
|
| 1490 | + * Add in our autosave ajax handlers |
|
| 1491 | + * |
|
| 1492 | + */ |
|
| 1493 | + protected function _ee_autosave_create_new() |
|
| 1494 | + { |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * More autosave handlers. |
|
| 1500 | + */ |
|
| 1501 | + protected function _ee_autosave_edit() |
|
| 1502 | + { |
|
| 1503 | + // TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1504 | + } |
|
| 1505 | + |
|
| 1506 | + |
|
| 1507 | + /** |
|
| 1508 | + * @throws EE_Error |
|
| 1509 | + * @throws ReflectionException |
|
| 1510 | + */ |
|
| 1511 | + private function _generate_publish_box_extra_content() |
|
| 1512 | + { |
|
| 1513 | + // load formatter helper |
|
| 1514 | + // args for getting related registrations |
|
| 1515 | + $approved_query_args = [ |
|
| 1516 | + [ |
|
| 1517 | + 'REG_deleted' => 0, |
|
| 1518 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1519 | + ], |
|
| 1520 | + ]; |
|
| 1521 | + $not_approved_query_args = [ |
|
| 1522 | + [ |
|
| 1523 | + 'REG_deleted' => 0, |
|
| 1524 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1525 | + ], |
|
| 1526 | + ]; |
|
| 1527 | + $pending_payment_query_args = [ |
|
| 1528 | + [ |
|
| 1529 | + 'REG_deleted' => 0, |
|
| 1530 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1531 | + ], |
|
| 1532 | + ]; |
|
| 1533 | + // publish box |
|
| 1534 | + $publish_box_extra_args = [ |
|
| 1535 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1536 | + [ |
|
| 1537 | + 'action' => 'default', |
|
| 1538 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1539 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1540 | + ], |
|
| 1541 | + REG_ADMIN_URL |
|
| 1542 | + ), |
|
| 1543 | + 'view_not_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_not_approved, |
|
| 1548 | + ], |
|
| 1549 | + REG_ADMIN_URL |
|
| 1550 | + ), |
|
| 1551 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1552 | + [ |
|
| 1553 | + 'action' => 'default', |
|
| 1554 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1555 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1556 | + ], |
|
| 1557 | + REG_ADMIN_URL |
|
| 1558 | + ), |
|
| 1559 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1560 | + 'Registration', |
|
| 1561 | + $approved_query_args |
|
| 1562 | + ), |
|
| 1563 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1564 | + 'Registration', |
|
| 1565 | + $not_approved_query_args |
|
| 1566 | + ), |
|
| 1567 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1568 | + 'Registration', |
|
| 1569 | + $pending_payment_query_args |
|
| 1570 | + ), |
|
| 1571 | + 'misc_pub_section_class' => apply_filters( |
|
| 1572 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1573 | + 'misc-pub-section' |
|
| 1574 | + ), |
|
| 1575 | + ]; |
|
| 1576 | + ob_start(); |
|
| 1577 | + do_action( |
|
| 1578 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1579 | + $this->_cpt_model_obj |
|
| 1580 | + ); |
|
| 1581 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1582 | + // load template |
|
| 1583 | + EEH_Template::display_template( |
|
| 1584 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1585 | + $publish_box_extra_args |
|
| 1586 | + ); |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + /** |
|
| 1591 | + * @return EE_Event |
|
| 1592 | + */ |
|
| 1593 | + public function get_event_object() |
|
| 1594 | + { |
|
| 1595 | + return $this->_cpt_model_obj; |
|
| 1596 | + } |
|
| 1597 | + |
|
| 1598 | + |
|
| 1599 | + |
|
| 1600 | + |
|
| 1601 | + /** METABOXES * */ |
|
| 1602 | + /** |
|
| 1603 | + * _register_event_editor_meta_boxes |
|
| 1604 | + * add all metaboxes related to the event_editor |
|
| 1605 | + * |
|
| 1606 | + * @return void |
|
| 1607 | + * @throws EE_Error |
|
| 1608 | + * @throws ReflectionException |
|
| 1609 | + */ |
|
| 1610 | + protected function _register_event_editor_meta_boxes() |
|
| 1611 | + { |
|
| 1612 | + $this->verify_cpt_object(); |
|
| 1613 | + add_meta_box( |
|
| 1614 | + 'espresso_event_editor_tickets', |
|
| 1615 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1616 | + [$this, 'ticket_metabox'], |
|
| 1617 | + $this->page_slug, |
|
| 1618 | + 'normal', |
|
| 1619 | + 'high' |
|
| 1620 | + ); |
|
| 1621 | + add_meta_box( |
|
| 1622 | + 'espresso_event_editor_event_options', |
|
| 1623 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1624 | + [$this, 'registration_options_meta_box'], |
|
| 1625 | + $this->page_slug, |
|
| 1626 | + 'side' |
|
| 1627 | + ); |
|
| 1628 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1629 | + // where a metabox has a related management page in the admin |
|
| 1630 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1631 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * @throws DomainException |
|
| 1637 | + * @throws EE_Error |
|
| 1638 | + * @throws ReflectionException |
|
| 1639 | + */ |
|
| 1640 | + public function ticket_metabox() |
|
| 1641 | + { |
|
| 1642 | + $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1643 | + // defaults for template args |
|
| 1644 | + $template_args = [ |
|
| 1645 | + 'existing_datetime_ids' => '', |
|
| 1646 | + 'event_datetime_help_link' => '', |
|
| 1647 | + 'ticket_options_help_link' => '', |
|
| 1648 | + 'time' => null, |
|
| 1649 | + 'ticket_rows' => '', |
|
| 1650 | + 'existing_ticket_ids' => '', |
|
| 1651 | + 'total_ticket_rows' => 1, |
|
| 1652 | + 'ticket_js_structure' => '', |
|
| 1653 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1654 | + 'disabled' => '', |
|
| 1655 | + ]; |
|
| 1656 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1657 | + /** |
|
| 1658 | + * 1. Start with retrieving Datetimes |
|
| 1659 | + * 2. Fore each datetime get related tickets |
|
| 1660 | + * 3. For each ticket get related prices |
|
| 1661 | + */ |
|
| 1662 | + $times = EEM_Datetime::instance()->get_all_event_dates($event_id); |
|
| 1663 | + $first_datetime = reset($times); |
|
| 1664 | + // do we get related tickets? |
|
| 1665 | + if ( |
|
| 1666 | + $first_datetime instanceof EE_Datetime |
|
| 1667 | + && $first_datetime->ID() !== 0 |
|
| 1668 | + ) { |
|
| 1669 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1670 | + $template_args['time'] = $first_datetime; |
|
| 1671 | + $related_tickets = $first_datetime->tickets( |
|
| 1672 | + [ |
|
| 1673 | + ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1674 | + 'default_where_conditions' => 'none', |
|
| 1675 | + ] |
|
| 1676 | + ); |
|
| 1677 | + if (! empty($related_tickets)) { |
|
| 1678 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1679 | + $row = 0; |
|
| 1680 | + foreach ($related_tickets as $ticket) { |
|
| 1681 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1682 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1683 | + $row++; |
|
| 1684 | + } |
|
| 1685 | + } else { |
|
| 1686 | + $template_args['total_ticket_rows'] = 1; |
|
| 1687 | + /** @type EE_Ticket $ticket */ |
|
| 1688 | + $ticket = EEM_Ticket::instance()->create_default_object(); |
|
| 1689 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1690 | + } |
|
| 1691 | + } else { |
|
| 1692 | + $template_args['time'] = $times[0]; |
|
| 1693 | + $tickets = EEM_Ticket::instance()->get_all_default_tickets(); |
|
| 1694 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
| 1695 | + // NOTE: we're just sending the first default row |
|
| 1696 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1697 | + } |
|
| 1698 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1699 | + 'event_editor_event_datetimes_help_tab' |
|
| 1700 | + ); |
|
| 1701 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1702 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1703 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1704 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1705 | + EEM_Ticket::instance()->create_default_object(), |
|
| 1706 | + true |
|
| 1707 | + ); |
|
| 1708 | + $template = apply_filters( |
|
| 1709 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1710 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1711 | + ); |
|
| 1712 | + EEH_Template::display_template($template, $template_args); |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + |
|
| 1716 | + /** |
|
| 1717 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1718 | + * |
|
| 1719 | + * @access private |
|
| 1720 | + * @param EE_Ticket $ticket the ticket object |
|
| 1721 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1722 | + * @param int $row |
|
| 1723 | + * @return string generated html for the ticket row. |
|
| 1724 | + * @throws EE_Error |
|
| 1725 | + * @throws ReflectionException |
|
| 1726 | + */ |
|
| 1727 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1728 | + { |
|
| 1729 | + $template_args = [ |
|
| 1730 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1731 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1732 | + : '', |
|
| 1733 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1734 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1735 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1736 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1737 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1738 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1739 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1740 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1741 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1742 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1743 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1744 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1745 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1746 | + : ' disabled=disabled', |
|
| 1747 | + ]; |
|
| 1748 | + $price = $ticket->ID() !== 0 |
|
| 1749 | + ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1750 | + : null; |
|
| 1751 | + $price = $price instanceof EE_Price |
|
| 1752 | + ? $price |
|
| 1753 | + : EEM_Price::instance()->create_default_object(); |
|
| 1754 | + $price_args = [ |
|
| 1755 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1756 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1757 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1758 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1759 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1760 | + ]; |
|
| 1761 | + // make sure we have default start and end dates if skeleton |
|
| 1762 | + // handle rows that should NOT be empty |
|
| 1763 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1764 | + // if empty then the start date will be now. |
|
| 1765 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1766 | + } |
|
| 1767 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1768 | + // get the earliest datetime (if present); |
|
| 1769 | + $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1770 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1771 | + 'Datetime', |
|
| 1772 | + ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1773 | + ) |
|
| 1774 | + : null; |
|
| 1775 | + $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
| 1776 | + ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
| 1777 | + : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
| 1778 | + } |
|
| 1779 | + $template_args = array_merge($template_args, $price_args); |
|
| 1780 | + $template = apply_filters( |
|
| 1781 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1782 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1783 | + $ticket |
|
| 1784 | + ); |
|
| 1785 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1786 | + } |
|
| 1787 | + |
|
| 1788 | + |
|
| 1789 | + /** |
|
| 1790 | + * @throws EE_Error |
|
| 1791 | + * @throws ReflectionException |
|
| 1792 | + */ |
|
| 1793 | + public function registration_options_meta_box() |
|
| 1794 | + { |
|
| 1795 | + $yes_no_values = [ |
|
| 1796 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1797 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1798 | + ]; |
|
| 1799 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1800 | + [ |
|
| 1801 | + EEM_Registration::status_id_cancelled, |
|
| 1802 | + EEM_Registration::status_id_declined, |
|
| 1803 | + EEM_Registration::status_id_incomplete, |
|
| 1804 | + ], |
|
| 1805 | + true |
|
| 1806 | + ); |
|
| 1807 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1808 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1809 | + $template_args['event'] = $this->_cpt_model_obj; |
|
| 1810 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1811 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1812 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1813 | + 'default_reg_status', |
|
| 1814 | + $default_reg_status_values, |
|
| 1815 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1816 | + ); |
|
| 1817 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1818 | + 'display_desc', |
|
| 1819 | + $yes_no_values, |
|
| 1820 | + $this->_cpt_model_obj->display_description() |
|
| 1821 | + ); |
|
| 1822 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1823 | + 'display_ticket_selector', |
|
| 1824 | + $yes_no_values, |
|
| 1825 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1826 | + '', |
|
| 1827 | + '', |
|
| 1828 | + false |
|
| 1829 | + ); |
|
| 1830 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1831 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1832 | + '', |
|
| 1833 | + $template_args, |
|
| 1834 | + $yes_no_values, |
|
| 1835 | + $default_reg_status_values |
|
| 1836 | + ); |
|
| 1837 | + EEH_Template::display_template( |
|
| 1838 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1839 | + $template_args |
|
| 1840 | + ); |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + |
|
| 1844 | + /** |
|
| 1845 | + * _get_events() |
|
| 1846 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1847 | + * |
|
| 1848 | + * @access public |
|
| 1849 | + * @param int $per_page count of items per page (20 default); |
|
| 1850 | + * @param int $current_page what is the current page being viewed. |
|
| 1851 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1852 | + * If FALSE then we return an array of event objects |
|
| 1853 | + * that match the given _view and paging parameters. |
|
| 1854 | + * @return array|int an array of event objects or a count of them. |
|
| 1855 | + * @throws Exception |
|
| 1856 | + */ |
|
| 1857 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1858 | + { |
|
| 1859 | + $EEM_Event = $this->_event_model(); |
|
| 1860 | + $offset = ($current_page - 1) * $per_page; |
|
| 1861 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1862 | + $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
| 1863 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 1864 | + $month_range = $this->request->getRequestParam('month_range'); |
|
| 1865 | + if ($month_range) { |
|
| 1866 | + $pieces = explode(' ', $month_range, 3); |
|
| 1867 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1868 | + // where PHP doesn't know what to assume for date. |
|
| 1869 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1870 | + $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1871 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1872 | + } |
|
| 1873 | + $where = []; |
|
| 1874 | + $status = $this->request->getRequestParam('status'); |
|
| 1875 | + // determine what post_status our condition will have for the query. |
|
| 1876 | + switch ($status) { |
|
| 1877 | + case 'month': |
|
| 1878 | + case 'today': |
|
| 1879 | + case null: |
|
| 1880 | + case 'all': |
|
| 1881 | + break; |
|
| 1882 | + case 'draft': |
|
| 1883 | + $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1884 | + break; |
|
| 1885 | + default: |
|
| 1886 | + $where['status'] = $status; |
|
| 1887 | + } |
|
| 1888 | + // categories? |
|
| 1889 | + $category = $this->request->getRequestParam('EVT_CAT', 0, 'int'); |
|
| 1890 | + if ($category) { |
|
| 1891 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1892 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1893 | + } |
|
| 1894 | + // date where conditions |
|
| 1895 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1896 | + if ($month_range) { |
|
| 1897 | + $DateTime = new DateTime( |
|
| 1898 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1899 | + new DateTimeZone('UTC') |
|
| 1900 | + ); |
|
| 1901 | + $start = $DateTime->getTimestamp(); |
|
| 1902 | + // set the datetime to be the end of the month |
|
| 1903 | + $DateTime->setDate( |
|
| 1904 | + $year_r, |
|
| 1905 | + $month_r, |
|
| 1906 | + $DateTime->format('t') |
|
| 1907 | + )->setTime(23, 59, 59); |
|
| 1908 | + $end = $DateTime->getTimestamp(); |
|
| 1909 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1910 | + } elseif ($status === 'today') { |
|
| 1911 | + $DateTime = |
|
| 1912 | + new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1913 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1914 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1915 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1916 | + } elseif ($status === 'month') { |
|
| 1917 | + $now = date('Y-m-01'); |
|
| 1918 | + $DateTime = |
|
| 1919 | + new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1920 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1921 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1922 | + ->setTime(23, 59, 59) |
|
| 1923 | + ->format(implode(' ', $start_formats)); |
|
| 1924 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1925 | + } |
|
| 1926 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1927 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1928 | + } else { |
|
| 1929 | + if (! isset($where['status'])) { |
|
| 1930 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1931 | + $where['OR'] = [ |
|
| 1932 | + 'status*restrict_private' => ['!=', 'private'], |
|
| 1933 | + 'AND' => [ |
|
| 1934 | + 'status*inclusive' => ['=', 'private'], |
|
| 1935 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1936 | + ], |
|
| 1937 | + ]; |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + } |
|
| 1941 | + $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int'); |
|
| 1942 | + if ( |
|
| 1943 | + $wp_user |
|
| 1944 | + && $wp_user !== get_current_user_id() |
|
| 1945 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1946 | + ) { |
|
| 1947 | + $where['EVT_wp_user'] = $wp_user; |
|
| 1948 | + } |
|
| 1949 | + // search query handling |
|
| 1950 | + $search_term = $this->request->getRequestParam('s'); |
|
| 1951 | + if ($search_term) { |
|
| 1952 | + $search_term = '%' . $search_term . '%'; |
|
| 1953 | + $where['OR'] = [ |
|
| 1954 | + 'EVT_name' => ['LIKE', $search_term], |
|
| 1955 | + 'EVT_desc' => ['LIKE', $search_term], |
|
| 1956 | + 'EVT_short_desc' => ['LIKE', $search_term], |
|
| 1957 | + ]; |
|
| 1958 | + } |
|
| 1959 | + // filter events by venue. |
|
| 1960 | + $venue = $this->request->getRequestParam('venue', 0, 'int'); |
|
| 1961 | + if ($venue) { |
|
| 1962 | + $where['Venue.VNU_ID'] = $venue; |
|
| 1963 | + } |
|
| 1964 | + $request_params = $this->request->requestParams(); |
|
| 1965 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
| 1966 | + $query_params = apply_filters( |
|
| 1967 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1968 | + [ |
|
| 1969 | + $where, |
|
| 1970 | + 'limit' => $limit, |
|
| 1971 | + 'order_by' => $orderby, |
|
| 1972 | + 'order' => $order, |
|
| 1973 | + 'group_by' => 'EVT_ID', |
|
| 1974 | + ], |
|
| 1975 | + $request_params |
|
| 1976 | + ); |
|
| 1977 | + |
|
| 1978 | + // let's first check if we have special requests coming in. |
|
| 1979 | + $active_status = $this->request->getRequestParam('active_status'); |
|
| 1980 | + if ($active_status) { |
|
| 1981 | + switch ($active_status) { |
|
| 1982 | + case 'upcoming': |
|
| 1983 | + return $EEM_Event->get_upcoming_events($query_params, $count); |
|
| 1984 | + case 'expired': |
|
| 1985 | + return $EEM_Event->get_expired_events($query_params, $count); |
|
| 1986 | + case 'active': |
|
| 1987 | + return $EEM_Event->get_active_events($query_params, $count); |
|
| 1988 | + case 'inactive': |
|
| 1989 | + return $EEM_Event->get_inactive_events($query_params, $count); |
|
| 1990 | + } |
|
| 1991 | + } |
|
| 1992 | + |
|
| 1993 | + return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
| 1994 | + } |
|
| 1995 | + |
|
| 1996 | + |
|
| 1997 | + /** |
|
| 1998 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1999 | + * |
|
| 2000 | + * @param string $post_id |
|
| 2001 | + * @throws EE_Error |
|
| 2002 | + * @throws ReflectionException |
|
| 2003 | + */ |
|
| 2004 | + public function trash_cpt_item($post_id) |
|
| 2005 | + { |
|
| 2006 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2007 | + $this->_trash_or_restore_event('trash', false); |
|
| 2008 | + } |
|
| 2009 | + |
|
| 2010 | + |
|
| 2011 | + /** |
|
| 2012 | + * @param string $post_id |
|
| 2013 | + * @throws EE_Error |
|
| 2014 | + * @throws ReflectionException |
|
| 2015 | + */ |
|
| 2016 | + public function restore_cpt_item($post_id) |
|
| 2017 | + { |
|
| 2018 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2019 | + $this->_trash_or_restore_event('draft', false); |
|
| 2020 | + } |
|
| 2021 | + |
|
| 2022 | + |
|
| 2023 | + /** |
|
| 2024 | + * @param string $post_id |
|
| 2025 | + * @throws EE_Error |
|
| 2026 | + * @throws EE_Error |
|
| 2027 | + */ |
|
| 2028 | + public function delete_cpt_item($post_id) |
|
| 2029 | + { |
|
| 2030 | + throw new EE_Error( |
|
| 2031 | + esc_html__( |
|
| 2032 | + 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
| 2033 | + 'event_espresso' |
|
| 2034 | + ) |
|
| 2035 | + ); |
|
| 2036 | + // $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2037 | + // $this->_delete_event(); |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + |
|
| 2041 | + /** |
|
| 2042 | + * _trash_or_restore_event |
|
| 2043 | + * |
|
| 2044 | + * @access protected |
|
| 2045 | + * @param string $event_status |
|
| 2046 | + * @param bool $redirect_after |
|
| 2047 | + * @throws EE_Error |
|
| 2048 | + * @throws EE_Error |
|
| 2049 | + * @throws ReflectionException |
|
| 2050 | + */ |
|
| 2051 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 2052 | + { |
|
| 2053 | + // determine the event id and set to array. |
|
| 2054 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 2055 | + // loop thru events |
|
| 2056 | + if ($EVT_ID) { |
|
| 2057 | + // clean status |
|
| 2058 | + $event_status = sanitize_key($event_status); |
|
| 2059 | + // grab status |
|
| 2060 | + if (! empty($event_status)) { |
|
| 2061 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2062 | + } else { |
|
| 2063 | + $success = false; |
|
| 2064 | + $msg = esc_html__( |
|
| 2065 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2066 | + 'event_espresso' |
|
| 2067 | + ); |
|
| 2068 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2069 | + } |
|
| 2070 | + } else { |
|
| 2071 | + $success = false; |
|
| 2072 | + $msg = esc_html__( |
|
| 2073 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2074 | + 'event_espresso' |
|
| 2075 | + ); |
|
| 2076 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2077 | + } |
|
| 2078 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2079 | + if ($redirect_after) { |
|
| 2080 | + $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2081 | + } |
|
| 2082 | + } |
|
| 2083 | + |
|
| 2084 | + |
|
| 2085 | + /** |
|
| 2086 | + * _trash_or_restore_events |
|
| 2087 | + * |
|
| 2088 | + * @access protected |
|
| 2089 | + * @param string $event_status |
|
| 2090 | + * @return void |
|
| 2091 | + * @throws EE_Error |
|
| 2092 | + * @throws EE_Error |
|
| 2093 | + * @throws ReflectionException |
|
| 2094 | + */ |
|
| 2095 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2096 | + { |
|
| 2097 | + // clean status |
|
| 2098 | + $event_status = sanitize_key($event_status); |
|
| 2099 | + // grab status |
|
| 2100 | + if (! empty($event_status)) { |
|
| 2101 | + $success = true; |
|
| 2102 | + // determine the event id and set to array. |
|
| 2103 | + $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2104 | + // loop thru events |
|
| 2105 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2106 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 2107 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2108 | + $success = $results !== false ? $success : false; |
|
| 2109 | + } else { |
|
| 2110 | + $msg = sprintf( |
|
| 2111 | + esc_html__( |
|
| 2112 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2113 | + 'event_espresso' |
|
| 2114 | + ), |
|
| 2115 | + $EVT_ID |
|
| 2116 | + ); |
|
| 2117 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2118 | + $success = false; |
|
| 2119 | + } |
|
| 2120 | + } |
|
| 2121 | + } else { |
|
| 2122 | + $success = false; |
|
| 2123 | + $msg = esc_html__( |
|
| 2124 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2125 | + 'event_espresso' |
|
| 2126 | + ); |
|
| 2127 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2128 | + } |
|
| 2129 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2130 | + $success = $success ? 2 : false; |
|
| 2131 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2132 | + $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2133 | + } |
|
| 2134 | + |
|
| 2135 | + |
|
| 2136 | + /** |
|
| 2137 | + * @param int $EVT_ID |
|
| 2138 | + * @param string $event_status |
|
| 2139 | + * @return bool |
|
| 2140 | + * @throws EE_Error |
|
| 2141 | + * @throws ReflectionException |
|
| 2142 | + */ |
|
| 2143 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2144 | + { |
|
| 2145 | + // grab event id |
|
| 2146 | + if (! $EVT_ID) { |
|
| 2147 | + $msg = esc_html__( |
|
| 2148 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2149 | + 'event_espresso' |
|
| 2150 | + ); |
|
| 2151 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2152 | + return false; |
|
| 2153 | + } |
|
| 2154 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2155 | + // clean status |
|
| 2156 | + $event_status = sanitize_key($event_status); |
|
| 2157 | + // grab status |
|
| 2158 | + if (empty($event_status)) { |
|
| 2159 | + $msg = esc_html__( |
|
| 2160 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2161 | + 'event_espresso' |
|
| 2162 | + ); |
|
| 2163 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2164 | + return false; |
|
| 2165 | + } |
|
| 2166 | + // was event trashed or restored ? |
|
| 2167 | + switch ($event_status) { |
|
| 2168 | + case 'draft': |
|
| 2169 | + $action = 'restored from the trash'; |
|
| 2170 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2171 | + break; |
|
| 2172 | + case 'trash': |
|
| 2173 | + $action = 'moved to the trash'; |
|
| 2174 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2175 | + break; |
|
| 2176 | + default: |
|
| 2177 | + $action = 'updated'; |
|
| 2178 | + $hook = false; |
|
| 2179 | + } |
|
| 2180 | + // use class to change status |
|
| 2181 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2182 | + $success = $this->_cpt_model_obj->save(); |
|
| 2183 | + if (! $success) { |
|
| 2184 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2185 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2186 | + return false; |
|
| 2187 | + } |
|
| 2188 | + if ($hook) { |
|
| 2189 | + do_action($hook); |
|
| 2190 | + } |
|
| 2191 | + return true; |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + |
|
| 2195 | + /** |
|
| 2196 | + * @param array $event_ids |
|
| 2197 | + * @return array |
|
| 2198 | + * @since 4.10.23.p |
|
| 2199 | + */ |
|
| 2200 | + private function cleanEventIds(array $event_ids) |
|
| 2201 | + { |
|
| 2202 | + return array_map('absint', $event_ids); |
|
| 2203 | + } |
|
| 2204 | + |
|
| 2205 | + |
|
| 2206 | + /** |
|
| 2207 | + * @return array |
|
| 2208 | + * @since 4.10.23.p |
|
| 2209 | + */ |
|
| 2210 | + private function getEventIdsFromRequest() |
|
| 2211 | + { |
|
| 2212 | + return $this->request->getRequestParam('EVT_IDs', [], 'int', true, ','); |
|
| 2213 | + } |
|
| 2214 | + |
|
| 2215 | + |
|
| 2216 | + /** |
|
| 2217 | + * @param bool $preview_delete |
|
| 2218 | + * @throws EE_Error |
|
| 2219 | + */ |
|
| 2220 | + protected function _delete_event($preview_delete = true) |
|
| 2221 | + { |
|
| 2222 | + $this->_delete_events($preview_delete); |
|
| 2223 | + } |
|
| 2224 | + |
|
| 2225 | + |
|
| 2226 | + /** |
|
| 2227 | + * Gets the tree traversal batch persister. |
|
| 2228 | + * |
|
| 2229 | + * @return NodeGroupDao |
|
| 2230 | + * @throws InvalidArgumentException |
|
| 2231 | + * @throws InvalidDataTypeException |
|
| 2232 | + * @throws InvalidInterfaceException |
|
| 2233 | + * @since 4.10.12.p |
|
| 2234 | + */ |
|
| 2235 | + protected function getModelObjNodeGroupPersister() |
|
| 2236 | + { |
|
| 2237 | + if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2238 | + $this->model_obj_node_group_persister = |
|
| 2239 | + $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2240 | + } |
|
| 2241 | + return $this->model_obj_node_group_persister; |
|
| 2242 | + } |
|
| 2243 | + |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * @param bool $preview_delete |
|
| 2247 | + * @return void |
|
| 2248 | + * @throws EE_Error |
|
| 2249 | + */ |
|
| 2250 | + protected function _delete_events($preview_delete = true) |
|
| 2251 | + { |
|
| 2252 | + $event_ids = $this->getEventIdsFromRequest(); |
|
| 2253 | + if ($preview_delete) { |
|
| 2254 | + $this->generateDeletionPreview($event_ids); |
|
| 2255 | + } else { |
|
| 2256 | + EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]); |
|
| 2257 | + } |
|
| 2258 | + } |
|
| 2259 | + |
|
| 2260 | + |
|
| 2261 | + /** |
|
| 2262 | + * @param array $event_ids |
|
| 2263 | + */ |
|
| 2264 | + protected function generateDeletionPreview(array $event_ids) |
|
| 2265 | + { |
|
| 2266 | + $event_ids = $this->cleanEventIds($event_ids); |
|
| 2267 | + // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2268 | + $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2269 | + $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2270 | + [ |
|
| 2271 | + 'action' => 'preview_deletion', |
|
| 2272 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2273 | + ], |
|
| 2274 | + $this->_admin_base_url |
|
| 2275 | + ); |
|
| 2276 | + EEH_URL::safeRedirectAndExit( |
|
| 2277 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2278 | + [ |
|
| 2279 | + 'page' => 'espresso_batch', |
|
| 2280 | + 'batch' => EED_Batch::batch_job, |
|
| 2281 | + 'EVT_IDs' => $event_ids, |
|
| 2282 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2283 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
| 2284 | + 'return_url' => urlencode($return_url), |
|
| 2285 | + ], |
|
| 2286 | + admin_url() |
|
| 2287 | + ) |
|
| 2288 | + ); |
|
| 2289 | + } |
|
| 2290 | + |
|
| 2291 | + |
|
| 2292 | + /** |
|
| 2293 | + * Checks for a POST submission |
|
| 2294 | + * |
|
| 2295 | + * @since 4.10.12.p |
|
| 2296 | + */ |
|
| 2297 | + protected function confirmDeletion() |
|
| 2298 | + { |
|
| 2299 | + $deletion_redirect_logic = |
|
| 2300 | + $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
| 2301 | + $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2302 | + } |
|
| 2303 | + |
|
| 2304 | + |
|
| 2305 | + /** |
|
| 2306 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2307 | + * |
|
| 2308 | + * @throws EE_Error |
|
| 2309 | + * @since 4.10.12.p |
|
| 2310 | + */ |
|
| 2311 | + protected function previewDeletion() |
|
| 2312 | + { |
|
| 2313 | + $preview_deletion_logic = |
|
| 2314 | + $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
| 2315 | + $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2316 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2317 | + } |
|
| 2318 | + |
|
| 2319 | + |
|
| 2320 | + /** |
|
| 2321 | + * get total number of events |
|
| 2322 | + * |
|
| 2323 | + * @access public |
|
| 2324 | + * @return int |
|
| 2325 | + * @throws EE_Error |
|
| 2326 | + * @throws EE_Error |
|
| 2327 | + */ |
|
| 2328 | + public function total_events() |
|
| 2329 | + { |
|
| 2330 | + return EEM_Event::instance()->count( |
|
| 2331 | + ['caps' => 'read_admin'], |
|
| 2332 | + 'EVT_ID', |
|
| 2333 | + true |
|
| 2334 | + ); |
|
| 2335 | + } |
|
| 2336 | + |
|
| 2337 | + |
|
| 2338 | + /** |
|
| 2339 | + * get total number of draft events |
|
| 2340 | + * |
|
| 2341 | + * @access public |
|
| 2342 | + * @return int |
|
| 2343 | + * @throws EE_Error |
|
| 2344 | + * @throws EE_Error |
|
| 2345 | + */ |
|
| 2346 | + public function total_events_draft() |
|
| 2347 | + { |
|
| 2348 | + return EEM_Event::instance()->count( |
|
| 2349 | + [ |
|
| 2350 | + ['status' => ['IN', ['draft', 'auto-draft']]], |
|
| 2351 | + 'caps' => 'read_admin', |
|
| 2352 | + ], |
|
| 2353 | + 'EVT_ID', |
|
| 2354 | + true |
|
| 2355 | + ); |
|
| 2356 | + } |
|
| 2357 | + |
|
| 2358 | + |
|
| 2359 | + /** |
|
| 2360 | + * get total number of trashed events |
|
| 2361 | + * |
|
| 2362 | + * @access public |
|
| 2363 | + * @return int |
|
| 2364 | + * @throws EE_Error |
|
| 2365 | + * @throws EE_Error |
|
| 2366 | + */ |
|
| 2367 | + public function total_trashed_events() |
|
| 2368 | + { |
|
| 2369 | + return EEM_Event::instance()->count( |
|
| 2370 | + [ |
|
| 2371 | + ['status' => 'trash'], |
|
| 2372 | + 'caps' => 'read_admin', |
|
| 2373 | + ], |
|
| 2374 | + 'EVT_ID', |
|
| 2375 | + true |
|
| 2376 | + ); |
|
| 2377 | + } |
|
| 2378 | + |
|
| 2379 | + |
|
| 2380 | + /** |
|
| 2381 | + * _default_event_settings |
|
| 2382 | + * This generates the Default Settings Tab |
|
| 2383 | + * |
|
| 2384 | + * @return void |
|
| 2385 | + * @throws EE_Error |
|
| 2386 | + */ |
|
| 2387 | + protected function _default_event_settings() |
|
| 2388 | + { |
|
| 2389 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2390 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2391 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2392 | + $this->display_admin_page_with_sidebar(); |
|
| 2393 | + } |
|
| 2394 | + |
|
| 2395 | + |
|
| 2396 | + /** |
|
| 2397 | + * Return the form for event settings. |
|
| 2398 | + * |
|
| 2399 | + * @return EE_Form_Section_Proper |
|
| 2400 | + * @throws EE_Error |
|
| 2401 | + */ |
|
| 2402 | + protected function _default_event_settings_form() |
|
| 2403 | + { |
|
| 2404 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2405 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2406 | + // exclude |
|
| 2407 | + [ |
|
| 2408 | + EEM_Registration::status_id_cancelled, |
|
| 2409 | + EEM_Registration::status_id_declined, |
|
| 2410 | + EEM_Registration::status_id_incomplete, |
|
| 2411 | + EEM_Registration::status_id_wait_list, |
|
| 2412 | + ], |
|
| 2413 | + true |
|
| 2414 | + ); |
|
| 2415 | + return new EE_Form_Section_Proper( |
|
| 2416 | + [ |
|
| 2417 | + 'name' => 'update_default_event_settings', |
|
| 2418 | + 'html_id' => 'update_default_event_settings', |
|
| 2419 | + 'html_class' => 'form-table', |
|
| 2420 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2421 | + 'subsections' => apply_filters( |
|
| 2422 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2423 | + [ |
|
| 2424 | + 'default_reg_status' => new EE_Select_Input( |
|
| 2425 | + $registration_stati_for_selection, |
|
| 2426 | + [ |
|
| 2427 | + 'default' => isset($registration_config->default_STS_ID) |
|
| 2428 | + && array_key_exists( |
|
| 2429 | + $registration_config->default_STS_ID, |
|
| 2430 | + $registration_stati_for_selection |
|
| 2431 | + ) |
|
| 2432 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2433 | + : EEM_Registration::status_id_pending_payment, |
|
| 2434 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2435 | + . EEH_Template::get_help_tab_link( |
|
| 2436 | + 'default_settings_status_help_tab' |
|
| 2437 | + ), |
|
| 2438 | + 'html_help_text' => esc_html__( |
|
| 2439 | + '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.', |
|
| 2440 | + 'event_espresso' |
|
| 2441 | + ), |
|
| 2442 | + ] |
|
| 2443 | + ), |
|
| 2444 | + 'default_max_tickets' => new EE_Integer_Input( |
|
| 2445 | + [ |
|
| 2446 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2447 | + ? $registration_config->default_maximum_number_of_tickets |
|
| 2448 | + : EEM_Event::get_default_additional_limit(), |
|
| 2449 | + 'html_label_text' => esc_html__( |
|
| 2450 | + 'Default Maximum Tickets Allowed Per Order:', |
|
| 2451 | + 'event_espresso' |
|
| 2452 | + ) |
|
| 2453 | + . EEH_Template::get_help_tab_link( |
|
| 2454 | + 'default_maximum_tickets_help_tab"' |
|
| 2455 | + ), |
|
| 2456 | + 'html_help_text' => esc_html__( |
|
| 2457 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2458 | + 'event_espresso' |
|
| 2459 | + ), |
|
| 2460 | + ] |
|
| 2461 | + ), |
|
| 2462 | + ] |
|
| 2463 | + ), |
|
| 2464 | + ] |
|
| 2465 | + ); |
|
| 2466 | + } |
|
| 2467 | + |
|
| 2468 | + |
|
| 2469 | + /** |
|
| 2470 | + * _update_default_event_settings |
|
| 2471 | + * |
|
| 2472 | + * @access protected |
|
| 2473 | + * @return void |
|
| 2474 | + * @throws EE_Error |
|
| 2475 | + */ |
|
| 2476 | + protected function _update_default_event_settings() |
|
| 2477 | + { |
|
| 2478 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2479 | + $form = $this->_default_event_settings_form(); |
|
| 2480 | + if ($form->was_submitted()) { |
|
| 2481 | + $form->receive_form_submission(); |
|
| 2482 | + if ($form->is_valid()) { |
|
| 2483 | + $valid_data = $form->valid_data(); |
|
| 2484 | + if (isset($valid_data['default_reg_status'])) { |
|
| 2485 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2486 | + } |
|
| 2487 | + if (isset($valid_data['default_max_tickets'])) { |
|
| 2488 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2489 | + } |
|
| 2490 | + // update because data was valid! |
|
| 2491 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2492 | + EE_Error::overwrite_success(); |
|
| 2493 | + EE_Error::add_success( |
|
| 2494 | + esc_html__('Default Event Settings were updated', 'event_espresso') |
|
| 2495 | + ); |
|
| 2496 | + } |
|
| 2497 | + } |
|
| 2498 | + $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2499 | + } |
|
| 2500 | + |
|
| 2501 | + |
|
| 2502 | + /************* Templates ************* |
|
| 21 | 2503 | * |
| 22 | - * @var EE_Event $_event |
|
| 23 | - */ |
|
| 24 | - protected $_event; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * This will hold the category object for category_details screen. |
|
| 29 | - * |
|
| 30 | - * @var stdClass $_category |
|
| 31 | - */ |
|
| 32 | - protected $_category; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * This will hold the event model instance |
|
| 37 | - * |
|
| 38 | - * @var EEM_Event $_event_model |
|
| 39 | - */ |
|
| 40 | - protected $_event_model; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Event |
|
| 45 | - */ |
|
| 46 | - protected $_cpt_model_obj = false; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var NodeGroupDao |
|
| 51 | - */ |
|
| 52 | - protected $model_obj_node_group_persister; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Initialize page props for this admin page group. |
|
| 57 | - */ |
|
| 58 | - protected function _init_page_props() |
|
| 59 | - { |
|
| 60 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 61 | - $this->page_label = EVENTS_LABEL; |
|
| 62 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 63 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 64 | - $this->_cpt_model_names = [ |
|
| 65 | - 'create_new' => 'EEM_Event', |
|
| 66 | - 'edit' => 'EEM_Event', |
|
| 67 | - ]; |
|
| 68 | - $this->_cpt_edit_routes = [ |
|
| 69 | - 'espresso_events' => 'edit', |
|
| 70 | - ]; |
|
| 71 | - add_action( |
|
| 72 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 73 | - [$this, 'verify_event_edit'], |
|
| 74 | - 10, |
|
| 75 | - 2 |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Sets the ajax hooks used for this admin page group. |
|
| 82 | - */ |
|
| 83 | - protected function _ajax_hooks() |
|
| 84 | - { |
|
| 85 | - add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Sets the page properties for this admin page group. |
|
| 91 | - */ |
|
| 92 | - protected function _define_page_props() |
|
| 93 | - { |
|
| 94 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 95 | - $this->_labels = [ |
|
| 96 | - 'buttons' => [ |
|
| 97 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 98 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 99 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 100 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 101 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 102 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 103 | - ], |
|
| 104 | - 'editor_title' => [ |
|
| 105 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 106 | - ], |
|
| 107 | - 'publishbox' => [ |
|
| 108 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 109 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 110 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 111 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 112 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 113 | - ], |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Sets the page routes property for this admin page group. |
|
| 120 | - */ |
|
| 121 | - protected function _set_page_routes() |
|
| 122 | - { |
|
| 123 | - // load formatter helper |
|
| 124 | - // load field generator helper |
|
| 125 | - // is there a evt_id in the request? |
|
| 126 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 127 | - $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int'); |
|
| 128 | - |
|
| 129 | - $this->_page_routes = [ |
|
| 130 | - 'default' => [ |
|
| 131 | - 'func' => '_events_overview_list_table', |
|
| 132 | - 'capability' => 'ee_read_events', |
|
| 133 | - ], |
|
| 134 | - 'create_new' => [ |
|
| 135 | - 'func' => '_create_new_cpt_item', |
|
| 136 | - 'capability' => 'ee_edit_events', |
|
| 137 | - ], |
|
| 138 | - 'edit' => [ |
|
| 139 | - 'func' => '_edit_cpt_item', |
|
| 140 | - 'capability' => 'ee_edit_event', |
|
| 141 | - 'obj_id' => $EVT_ID, |
|
| 142 | - ], |
|
| 143 | - 'copy_event' => [ |
|
| 144 | - 'func' => '_copy_events', |
|
| 145 | - 'capability' => 'ee_edit_event', |
|
| 146 | - 'obj_id' => $EVT_ID, |
|
| 147 | - 'noheader' => true, |
|
| 148 | - ], |
|
| 149 | - 'trash_event' => [ |
|
| 150 | - 'func' => '_trash_or_restore_event', |
|
| 151 | - 'args' => ['event_status' => 'trash'], |
|
| 152 | - 'capability' => 'ee_delete_event', |
|
| 153 | - 'obj_id' => $EVT_ID, |
|
| 154 | - 'noheader' => true, |
|
| 155 | - ], |
|
| 156 | - 'trash_events' => [ |
|
| 157 | - 'func' => '_trash_or_restore_events', |
|
| 158 | - 'args' => ['event_status' => 'trash'], |
|
| 159 | - 'capability' => 'ee_delete_events', |
|
| 160 | - 'noheader' => true, |
|
| 161 | - ], |
|
| 162 | - 'restore_event' => [ |
|
| 163 | - 'func' => '_trash_or_restore_event', |
|
| 164 | - 'args' => ['event_status' => 'draft'], |
|
| 165 | - 'capability' => 'ee_delete_event', |
|
| 166 | - 'obj_id' => $EVT_ID, |
|
| 167 | - 'noheader' => true, |
|
| 168 | - ], |
|
| 169 | - 'restore_events' => [ |
|
| 170 | - 'func' => '_trash_or_restore_events', |
|
| 171 | - 'args' => ['event_status' => 'draft'], |
|
| 172 | - 'capability' => 'ee_delete_events', |
|
| 173 | - 'noheader' => true, |
|
| 174 | - ], |
|
| 175 | - 'delete_event' => [ |
|
| 176 | - 'func' => '_delete_event', |
|
| 177 | - 'capability' => 'ee_delete_event', |
|
| 178 | - 'obj_id' => $EVT_ID, |
|
| 179 | - 'noheader' => true, |
|
| 180 | - ], |
|
| 181 | - 'delete_events' => [ |
|
| 182 | - 'func' => '_delete_events', |
|
| 183 | - 'capability' => 'ee_delete_events', |
|
| 184 | - 'noheader' => true, |
|
| 185 | - ], |
|
| 186 | - 'view_report' => [ |
|
| 187 | - 'func' => '_view_report', |
|
| 188 | - 'capability' => 'ee_edit_events', |
|
| 189 | - ], |
|
| 190 | - 'default_event_settings' => [ |
|
| 191 | - 'func' => '_default_event_settings', |
|
| 192 | - 'capability' => 'manage_options', |
|
| 193 | - ], |
|
| 194 | - 'update_default_event_settings' => [ |
|
| 195 | - 'func' => '_update_default_event_settings', |
|
| 196 | - 'capability' => 'manage_options', |
|
| 197 | - 'noheader' => true, |
|
| 198 | - ], |
|
| 199 | - 'template_settings' => [ |
|
| 200 | - 'func' => '_template_settings', |
|
| 201 | - 'capability' => 'manage_options', |
|
| 202 | - ], |
|
| 203 | - // event category tab related |
|
| 204 | - 'add_category' => [ |
|
| 205 | - 'func' => '_category_details', |
|
| 206 | - 'capability' => 'ee_edit_event_category', |
|
| 207 | - 'args' => ['add'], |
|
| 208 | - ], |
|
| 209 | - 'edit_category' => [ |
|
| 210 | - 'func' => '_category_details', |
|
| 211 | - 'capability' => 'ee_edit_event_category', |
|
| 212 | - 'args' => ['edit'], |
|
| 213 | - ], |
|
| 214 | - 'delete_categories' => [ |
|
| 215 | - 'func' => '_delete_categories', |
|
| 216 | - 'capability' => 'ee_delete_event_category', |
|
| 217 | - 'noheader' => true, |
|
| 218 | - ], |
|
| 219 | - 'delete_category' => [ |
|
| 220 | - 'func' => '_delete_categories', |
|
| 221 | - 'capability' => 'ee_delete_event_category', |
|
| 222 | - 'noheader' => true, |
|
| 223 | - ], |
|
| 224 | - 'insert_category' => [ |
|
| 225 | - 'func' => '_insert_or_update_category', |
|
| 226 | - 'args' => ['new_category' => true], |
|
| 227 | - 'capability' => 'ee_edit_event_category', |
|
| 228 | - 'noheader' => true, |
|
| 229 | - ], |
|
| 230 | - 'update_category' => [ |
|
| 231 | - 'func' => '_insert_or_update_category', |
|
| 232 | - 'args' => ['new_category' => false], |
|
| 233 | - 'capability' => 'ee_edit_event_category', |
|
| 234 | - 'noheader' => true, |
|
| 235 | - ], |
|
| 236 | - 'category_list' => [ |
|
| 237 | - 'func' => '_category_list_table', |
|
| 238 | - 'capability' => 'ee_manage_event_categories', |
|
| 239 | - ], |
|
| 240 | - 'preview_deletion' => [ |
|
| 241 | - 'func' => 'previewDeletion', |
|
| 242 | - 'capability' => 'ee_delete_events', |
|
| 243 | - ], |
|
| 244 | - 'confirm_deletion' => [ |
|
| 245 | - 'func' => 'confirmDeletion', |
|
| 246 | - 'capability' => 'ee_delete_events', |
|
| 247 | - 'noheader' => true, |
|
| 248 | - ], |
|
| 249 | - ]; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Set the _page_config property for this admin page group. |
|
| 255 | - */ |
|
| 256 | - protected function _set_page_config() |
|
| 257 | - { |
|
| 258 | - $post_id = $this->request->getRequestParam('post', 0, 'int'); |
|
| 259 | - $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 260 | - $this->_page_config = [ |
|
| 261 | - 'default' => [ |
|
| 262 | - 'nav' => [ |
|
| 263 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 264 | - 'order' => 10, |
|
| 265 | - ], |
|
| 266 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 267 | - 'help_tabs' => [ |
|
| 268 | - 'events_overview_help_tab' => [ |
|
| 269 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 270 | - 'filename' => 'events_overview', |
|
| 271 | - ], |
|
| 272 | - 'events_overview_table_column_headings_help_tab' => [ |
|
| 273 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 274 | - 'filename' => 'events_overview_table_column_headings', |
|
| 275 | - ], |
|
| 276 | - 'events_overview_filters_help_tab' => [ |
|
| 277 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 278 | - 'filename' => 'events_overview_filters', |
|
| 279 | - ], |
|
| 280 | - 'events_overview_view_help_tab' => [ |
|
| 281 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 282 | - 'filename' => 'events_overview_views', |
|
| 283 | - ], |
|
| 284 | - 'events_overview_other_help_tab' => [ |
|
| 285 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 286 | - 'filename' => 'events_overview_other', |
|
| 287 | - ], |
|
| 288 | - ], |
|
| 289 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 290 | - // 'help_tour' => array( |
|
| 291 | - // 'Event_Overview_Help_Tour', |
|
| 292 | - // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 293 | - // ), |
|
| 294 | - 'qtips' => [ |
|
| 295 | - 'EE_Event_List_Table_Tips', |
|
| 296 | - ], |
|
| 297 | - 'require_nonce' => false, |
|
| 298 | - ], |
|
| 299 | - 'create_new' => [ |
|
| 300 | - 'nav' => [ |
|
| 301 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 302 | - 'order' => 5, |
|
| 303 | - 'persistent' => false, |
|
| 304 | - ], |
|
| 305 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 306 | - 'help_tabs' => [ |
|
| 307 | - 'event_editor_help_tab' => [ |
|
| 308 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 309 | - 'filename' => 'event_editor', |
|
| 310 | - ], |
|
| 311 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 312 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 313 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 314 | - ], |
|
| 315 | - 'event_editor_venue_details_help_tab' => [ |
|
| 316 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 317 | - 'filename' => 'event_editor_venue_details', |
|
| 318 | - ], |
|
| 319 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 320 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 321 | - 'filename' => 'event_editor_event_datetimes', |
|
| 322 | - ], |
|
| 323 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 324 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 325 | - 'filename' => 'event_editor_event_tickets', |
|
| 326 | - ], |
|
| 327 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 328 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 329 | - 'filename' => 'event_editor_event_registration_options', |
|
| 330 | - ], |
|
| 331 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 332 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 333 | - 'filename' => 'event_editor_tags_categories', |
|
| 334 | - ], |
|
| 335 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 336 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 337 | - 'filename' => 'event_editor_questions_registrants', |
|
| 338 | - ], |
|
| 339 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 340 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 341 | - 'filename' => 'event_editor_save_new_event', |
|
| 342 | - ], |
|
| 343 | - 'event_editor_other_help_tab' => [ |
|
| 344 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 345 | - 'filename' => 'event_editor_other', |
|
| 346 | - ], |
|
| 347 | - ], |
|
| 348 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 349 | - // 'help_tour' => array( |
|
| 350 | - // 'Event_Editor_Help_Tour', |
|
| 351 | - // ), |
|
| 352 | - 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 353 | - 'require_nonce' => false, |
|
| 354 | - ], |
|
| 355 | - 'edit' => [ |
|
| 356 | - 'nav' => [ |
|
| 357 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 358 | - 'order' => 5, |
|
| 359 | - 'persistent' => false, |
|
| 360 | - 'url' => $post_id |
|
| 361 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 362 | - ['post' => $post_id, 'action' => 'edit'], |
|
| 363 | - $this->_current_page_view_url |
|
| 364 | - ) |
|
| 365 | - : $this->_admin_base_url, |
|
| 366 | - ], |
|
| 367 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 368 | - 'help_tabs' => [ |
|
| 369 | - 'event_editor_help_tab' => [ |
|
| 370 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 371 | - 'filename' => 'event_editor', |
|
| 372 | - ], |
|
| 373 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 374 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 375 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 376 | - ], |
|
| 377 | - 'event_editor_venue_details_help_tab' => [ |
|
| 378 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 379 | - 'filename' => 'event_editor_venue_details', |
|
| 380 | - ], |
|
| 381 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 382 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 383 | - 'filename' => 'event_editor_event_datetimes', |
|
| 384 | - ], |
|
| 385 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 386 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 387 | - 'filename' => 'event_editor_event_tickets', |
|
| 388 | - ], |
|
| 389 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 390 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 391 | - 'filename' => 'event_editor_event_registration_options', |
|
| 392 | - ], |
|
| 393 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 394 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 395 | - 'filename' => 'event_editor_tags_categories', |
|
| 396 | - ], |
|
| 397 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 398 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 399 | - 'filename' => 'event_editor_questions_registrants', |
|
| 400 | - ], |
|
| 401 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 402 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 403 | - 'filename' => 'event_editor_save_new_event', |
|
| 404 | - ], |
|
| 405 | - 'event_editor_other_help_tab' => [ |
|
| 406 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 407 | - 'filename' => 'event_editor_other', |
|
| 408 | - ], |
|
| 409 | - ], |
|
| 410 | - 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 411 | - 'require_nonce' => false, |
|
| 412 | - ], |
|
| 413 | - 'default_event_settings' => [ |
|
| 414 | - 'nav' => [ |
|
| 415 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 416 | - 'order' => 40, |
|
| 417 | - ], |
|
| 418 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 419 | - 'labels' => [ |
|
| 420 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 421 | - ], |
|
| 422 | - 'help_tabs' => [ |
|
| 423 | - 'default_settings_help_tab' => [ |
|
| 424 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 425 | - 'filename' => 'events_default_settings', |
|
| 426 | - ], |
|
| 427 | - 'default_settings_status_help_tab' => [ |
|
| 428 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 429 | - 'filename' => 'events_default_settings_status', |
|
| 430 | - ], |
|
| 431 | - 'default_maximum_tickets_help_tab' => [ |
|
| 432 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 433 | - 'filename' => 'events_default_settings_max_tickets', |
|
| 434 | - ], |
|
| 435 | - ], |
|
| 436 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 437 | - // 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 438 | - 'require_nonce' => false, |
|
| 439 | - ], |
|
| 440 | - // template settings |
|
| 441 | - 'template_settings' => [ |
|
| 442 | - 'nav' => [ |
|
| 443 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 444 | - 'order' => 30, |
|
| 445 | - ], |
|
| 446 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 447 | - 'help_tabs' => [ |
|
| 448 | - 'general_settings_templates_help_tab' => [ |
|
| 449 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 450 | - 'filename' => 'general_settings_templates', |
|
| 451 | - ], |
|
| 452 | - ], |
|
| 453 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 454 | - // 'help_tour' => array('Templates_Help_Tour'), |
|
| 455 | - 'require_nonce' => false, |
|
| 456 | - ], |
|
| 457 | - // event category stuff |
|
| 458 | - 'add_category' => [ |
|
| 459 | - 'nav' => [ |
|
| 460 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 461 | - 'order' => 15, |
|
| 462 | - 'persistent' => false, |
|
| 463 | - ], |
|
| 464 | - 'help_tabs' => [ |
|
| 465 | - 'add_category_help_tab' => [ |
|
| 466 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 467 | - 'filename' => 'events_add_category', |
|
| 468 | - ], |
|
| 469 | - ], |
|
| 470 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 471 | - // 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 472 | - 'metaboxes' => ['_publish_post_box'], |
|
| 473 | - 'require_nonce' => false, |
|
| 474 | - ], |
|
| 475 | - 'edit_category' => [ |
|
| 476 | - 'nav' => [ |
|
| 477 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 478 | - 'order' => 15, |
|
| 479 | - 'persistent' => false, |
|
| 480 | - 'url' => $EVT_CAT_ID |
|
| 481 | - ? add_query_arg( |
|
| 482 | - ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
| 483 | - $this->_current_page_view_url |
|
| 484 | - ) |
|
| 485 | - : $this->_admin_base_url, |
|
| 486 | - ], |
|
| 487 | - 'help_tabs' => [ |
|
| 488 | - 'edit_category_help_tab' => [ |
|
| 489 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 490 | - 'filename' => 'events_edit_category', |
|
| 491 | - ], |
|
| 492 | - ], |
|
| 493 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 494 | - 'metaboxes' => ['_publish_post_box'], |
|
| 495 | - 'require_nonce' => false, |
|
| 496 | - ], |
|
| 497 | - 'category_list' => [ |
|
| 498 | - 'nav' => [ |
|
| 499 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 500 | - 'order' => 20, |
|
| 501 | - ], |
|
| 502 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 503 | - 'help_tabs' => [ |
|
| 504 | - 'events_categories_help_tab' => [ |
|
| 505 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 506 | - 'filename' => 'events_categories', |
|
| 507 | - ], |
|
| 508 | - 'events_categories_table_column_headings_help_tab' => [ |
|
| 509 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 510 | - 'filename' => 'events_categories_table_column_headings', |
|
| 511 | - ], |
|
| 512 | - 'events_categories_view_help_tab' => [ |
|
| 513 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 514 | - 'filename' => 'events_categories_views', |
|
| 515 | - ], |
|
| 516 | - 'events_categories_other_help_tab' => [ |
|
| 517 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 518 | - 'filename' => 'events_categories_other', |
|
| 519 | - ], |
|
| 520 | - ], |
|
| 521 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 522 | - // 'help_tour' => array( |
|
| 523 | - // 'Event_Categories_Help_Tour', |
|
| 524 | - // ), |
|
| 525 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 526 | - 'require_nonce' => false, |
|
| 527 | - ], |
|
| 528 | - 'preview_deletion' => [ |
|
| 529 | - 'nav' => [ |
|
| 530 | - 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 531 | - 'order' => 15, |
|
| 532 | - 'persistent' => false, |
|
| 533 | - 'url' => '', |
|
| 534 | - ], |
|
| 535 | - 'require_nonce' => false, |
|
| 536 | - ], |
|
| 537 | - ]; |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 543 | - */ |
|
| 544 | - protected function _add_screen_options() |
|
| 545 | - { |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Implementing the screen options for the 'default' route. |
|
| 551 | - */ |
|
| 552 | - protected function _add_screen_options_default() |
|
| 553 | - { |
|
| 554 | - $this->_per_page_screen_option(); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Implementing screen options for the category list route. |
|
| 560 | - */ |
|
| 561 | - protected function _add_screen_options_category_list() |
|
| 562 | - { |
|
| 563 | - $page_title = $this->_admin_page_title; |
|
| 564 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 565 | - $this->_per_page_screen_option(); |
|
| 566 | - $this->_admin_page_title = $page_title; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Used to register any global feature pointers for the admin page group. |
|
| 572 | - */ |
|
| 573 | - protected function _add_feature_pointers() |
|
| 574 | - { |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 580 | - */ |
|
| 581 | - public function load_scripts_styles() |
|
| 582 | - { |
|
| 583 | - wp_register_style( |
|
| 584 | - 'events-admin-css', |
|
| 585 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 586 | - [], |
|
| 587 | - EVENT_ESPRESSO_VERSION |
|
| 588 | - ); |
|
| 589 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION); |
|
| 590 | - wp_enqueue_style('events-admin-css'); |
|
| 591 | - wp_enqueue_style('ee-cat-admin'); |
|
| 592 | - // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 593 | - // registers for all views |
|
| 594 | - // scripts |
|
| 595 | - wp_register_script( |
|
| 596 | - 'event_editor_js', |
|
| 597 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 598 | - ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 599 | - EVENT_ESPRESSO_VERSION, |
|
| 600 | - true |
|
| 601 | - ); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * Enqueuing scripts and styles specific to this view |
|
| 607 | - */ |
|
| 608 | - public function load_scripts_styles_create_new() |
|
| 609 | - { |
|
| 610 | - $this->load_scripts_styles_edit(); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Enqueuing scripts and styles specific to this view |
|
| 616 | - */ |
|
| 617 | - public function load_scripts_styles_edit() |
|
| 618 | - { |
|
| 619 | - // styles |
|
| 620 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 621 | - wp_register_style( |
|
| 622 | - 'event-editor-css', |
|
| 623 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 624 | - ['ee-admin-css'], |
|
| 625 | - EVENT_ESPRESSO_VERSION |
|
| 626 | - ); |
|
| 627 | - wp_enqueue_style('event-editor-css'); |
|
| 628 | - // scripts |
|
| 629 | - wp_register_script( |
|
| 630 | - 'event-datetime-metabox', |
|
| 631 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 632 | - ['event_editor_js', 'ee-datepicker'], |
|
| 633 | - EVENT_ESPRESSO_VERSION |
|
| 634 | - ); |
|
| 635 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * Populating the _views property for the category list table view. |
|
| 641 | - */ |
|
| 642 | - protected function _set_list_table_views_category_list() |
|
| 643 | - { |
|
| 644 | - $this->_views = [ |
|
| 645 | - 'all' => [ |
|
| 646 | - 'slug' => 'all', |
|
| 647 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 648 | - 'count' => 0, |
|
| 649 | - 'bulk_action' => [ |
|
| 650 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 651 | - ], |
|
| 652 | - ], |
|
| 653 | - ]; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 659 | - */ |
|
| 660 | - public function admin_init() |
|
| 661 | - { |
|
| 662 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 663 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 664 | - 'event_espresso' |
|
| 665 | - ); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 671 | - * group. |
|
| 672 | - */ |
|
| 673 | - public function admin_notices() |
|
| 674 | - { |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 680 | - * this admin page group. |
|
| 681 | - */ |
|
| 682 | - public function admin_footer_scripts() |
|
| 683 | - { |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - |
|
| 687 | - /** |
|
| 688 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 689 | - * warning (via EE_Error::add_error()); |
|
| 690 | - * |
|
| 691 | - * @param EE_Event $event Event object |
|
| 692 | - * @param string $req_type |
|
| 693 | - * @return void |
|
| 694 | - * @throws EE_Error |
|
| 695 | - * @throws ReflectionException |
|
| 696 | - */ |
|
| 697 | - public function verify_event_edit($event = null, $req_type = '') |
|
| 698 | - { |
|
| 699 | - // don't need to do this when processing |
|
| 700 | - if (! empty($req_type)) { |
|
| 701 | - return; |
|
| 702 | - } |
|
| 703 | - // no event? |
|
| 704 | - if (empty($event)) { |
|
| 705 | - // set event |
|
| 706 | - $event = $this->_cpt_model_obj; |
|
| 707 | - } |
|
| 708 | - // STILL no event? |
|
| 709 | - if (! $event instanceof EE_Event) { |
|
| 710 | - return; |
|
| 711 | - } |
|
| 712 | - $orig_status = $event->status(); |
|
| 713 | - // first check if event is active. |
|
| 714 | - if ( |
|
| 715 | - $orig_status === EEM_Event::cancelled |
|
| 716 | - || $orig_status === EEM_Event::postponed |
|
| 717 | - || $event->is_expired() |
|
| 718 | - || $event->is_inactive() |
|
| 719 | - ) { |
|
| 720 | - return; |
|
| 721 | - } |
|
| 722 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
| 723 | - if ($event->is_sold_out(true)) { |
|
| 724 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 725 | - EE_Error::add_attention( |
|
| 726 | - sprintf( |
|
| 727 | - esc_html__( |
|
| 728 | - '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.', |
|
| 729 | - 'event_espresso' |
|
| 730 | - ), |
|
| 731 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 732 | - ) |
|
| 733 | - ); |
|
| 734 | - } |
|
| 735 | - return; |
|
| 736 | - } elseif ($orig_status === EEM_Event::sold_out) { |
|
| 737 | - EE_Error::add_attention( |
|
| 738 | - sprintf( |
|
| 739 | - esc_html__( |
|
| 740 | - '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.', |
|
| 741 | - 'event_espresso' |
|
| 742 | - ), |
|
| 743 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 744 | - ) |
|
| 745 | - ); |
|
| 746 | - } |
|
| 747 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 748 | - if (! $event->tickets_on_sale()) { |
|
| 749 | - return; |
|
| 750 | - } |
|
| 751 | - // made it here so show warning |
|
| 752 | - $this->_edit_event_warning(); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 758 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 759 | - * |
|
| 760 | - * @access protected |
|
| 761 | - * @return void |
|
| 762 | - */ |
|
| 763 | - protected function _edit_event_warning() |
|
| 764 | - { |
|
| 765 | - // we don't want to add warnings during these requests |
|
| 766 | - if ($this->request->getRequestParam('action') === 'editpost') { |
|
| 767 | - return; |
|
| 768 | - } |
|
| 769 | - EE_Error::add_attention( |
|
| 770 | - sprintf( |
|
| 771 | - esc_html__( |
|
| 772 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 773 | - 'event_espresso' |
|
| 774 | - ), |
|
| 775 | - '<a class="espresso-help-tab-lnk">', |
|
| 776 | - '</a>' |
|
| 777 | - ) |
|
| 778 | - ); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 784 | - * Otherwise, do the normal logic |
|
| 785 | - * |
|
| 786 | - * @return void |
|
| 787 | - * @throws EE_Error |
|
| 788 | - */ |
|
| 789 | - protected function _create_new_cpt_item() |
|
| 790 | - { |
|
| 791 | - $has_timezone_string = get_option('timezone_string'); |
|
| 792 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 793 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 794 | - EE_Error::add_attention( |
|
| 795 | - sprintf( |
|
| 796 | - esc_html__( |
|
| 797 | - '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', |
|
| 798 | - 'event_espresso' |
|
| 799 | - ), |
|
| 800 | - '<br>', |
|
| 801 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 802 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 803 | - . '</select>', |
|
| 804 | - '<button class="button button-secondary timezone-submit">', |
|
| 805 | - '</button><span class="spinner"></span>' |
|
| 806 | - ), |
|
| 807 | - __FILE__, |
|
| 808 | - __FUNCTION__, |
|
| 809 | - __LINE__ |
|
| 810 | - ); |
|
| 811 | - } |
|
| 812 | - parent::_create_new_cpt_item(); |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * Sets the _views property for the default route in this admin page group. |
|
| 818 | - */ |
|
| 819 | - protected function _set_list_table_views_default() |
|
| 820 | - { |
|
| 821 | - $this->_views = [ |
|
| 822 | - 'all' => [ |
|
| 823 | - 'slug' => 'all', |
|
| 824 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 825 | - 'count' => 0, |
|
| 826 | - 'bulk_action' => [ |
|
| 827 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 828 | - ], |
|
| 829 | - ], |
|
| 830 | - 'draft' => [ |
|
| 831 | - 'slug' => 'draft', |
|
| 832 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 833 | - 'count' => 0, |
|
| 834 | - 'bulk_action' => [ |
|
| 835 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 836 | - ], |
|
| 837 | - ], |
|
| 838 | - ]; |
|
| 839 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 840 | - $this->_views['trash'] = [ |
|
| 841 | - 'slug' => 'trash', |
|
| 842 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 843 | - 'count' => 0, |
|
| 844 | - 'bulk_action' => [ |
|
| 845 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 846 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 847 | - ], |
|
| 848 | - ]; |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Provides the legend item array for the default list table view. |
|
| 855 | - * |
|
| 856 | - * @return array |
|
| 857 | - * @throws EE_Error |
|
| 858 | - * @throws EE_Error |
|
| 859 | - */ |
|
| 860 | - protected function _event_legend_items() |
|
| 861 | - { |
|
| 862 | - $items = [ |
|
| 863 | - 'view_details' => [ |
|
| 864 | - 'class' => 'dashicons dashicons-search', |
|
| 865 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 866 | - ], |
|
| 867 | - 'edit_event' => [ |
|
| 868 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 869 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 870 | - ], |
|
| 871 | - 'view_attendees' => [ |
|
| 872 | - 'class' => 'dashicons dashicons-groups', |
|
| 873 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 874 | - ], |
|
| 875 | - ]; |
|
| 876 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 877 | - $statuses = [ |
|
| 878 | - 'sold_out_status' => [ |
|
| 879 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 880 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 881 | - ], |
|
| 882 | - 'active_status' => [ |
|
| 883 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 884 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 885 | - ], |
|
| 886 | - 'upcoming_status' => [ |
|
| 887 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 888 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 889 | - ], |
|
| 890 | - 'postponed_status' => [ |
|
| 891 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 892 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 893 | - ], |
|
| 894 | - 'cancelled_status' => [ |
|
| 895 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 896 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 897 | - ], |
|
| 898 | - 'expired_status' => [ |
|
| 899 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 900 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 901 | - ], |
|
| 902 | - 'inactive_status' => [ |
|
| 903 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 904 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 905 | - ], |
|
| 906 | - ]; |
|
| 907 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 908 | - return array_merge($items, $statuses); |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * @return EEM_Event |
|
| 914 | - * @throws EE_Error |
|
| 915 | - * @throws ReflectionException |
|
| 916 | - */ |
|
| 917 | - private function _event_model() |
|
| 918 | - { |
|
| 919 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 920 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 921 | - } |
|
| 922 | - return $this->_event_model; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 928 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 929 | - * |
|
| 930 | - * @param string $return the current html |
|
| 931 | - * @param int $id the post id for the page |
|
| 932 | - * @param string $new_title What the title is |
|
| 933 | - * @param string $new_slug what the slug is |
|
| 934 | - * @return string The new html string for the permalink area |
|
| 935 | - */ |
|
| 936 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 937 | - { |
|
| 938 | - // make sure this is only when editing |
|
| 939 | - if (! empty($id)) { |
|
| 940 | - $post = get_post($id); |
|
| 941 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 942 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 943 | - . '</a> '; |
|
| 944 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 945 | - . $post->ID |
|
| 946 | - . ']">'; |
|
| 947 | - } |
|
| 948 | - return $return; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * _events_overview_list_table |
|
| 954 | - * This contains the logic for showing the events_overview list |
|
| 955 | - * |
|
| 956 | - * @access protected |
|
| 957 | - * @return void |
|
| 958 | - * @throws EE_Error |
|
| 959 | - */ |
|
| 960 | - protected function _events_overview_list_table() |
|
| 961 | - { |
|
| 962 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 963 | - $this->_template_args['after_list_table'] = |
|
| 964 | - ! empty($this->_template_args['after_list_table']) |
|
| 965 | - ? (array) $this->_template_args['after_list_table'] |
|
| 966 | - : []; |
|
| 967 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 968 | - . EEH_Template::get_button_or_link( |
|
| 969 | - get_post_type_archive_link('espresso_events'), |
|
| 970 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
| 971 | - 'button' |
|
| 972 | - ); |
|
| 973 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend( |
|
| 974 | - $this->_event_legend_items() |
|
| 975 | - ); |
|
| 976 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 977 | - 'create_new', |
|
| 978 | - 'add', |
|
| 979 | - [], |
|
| 980 | - 'add-new-h2' |
|
| 981 | - ); |
|
| 982 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - |
|
| 986 | - /** |
|
| 987 | - * this allows for extra misc actions in the default WP publish box |
|
| 988 | - * |
|
| 989 | - * @return void |
|
| 990 | - * @throws EE_Error |
|
| 991 | - * @throws ReflectionException |
|
| 992 | - */ |
|
| 993 | - public function extra_misc_actions_publish_box() |
|
| 994 | - { |
|
| 995 | - $this->_generate_publish_box_extra_content(); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1001 | - * saved. |
|
| 1002 | - * Typically you would use this to save any additional data. |
|
| 1003 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1004 | - * ALSO very important. When a post transitions from scheduled to published, |
|
| 1005 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1006 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1007 | - * |
|
| 1008 | - * @access protected |
|
| 1009 | - * @abstract |
|
| 1010 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1011 | - * @param object $post The post object of the cpt that was saved. |
|
| 1012 | - * @return void |
|
| 1013 | - * @throws EE_Error |
|
| 1014 | - * @throws ReflectionException |
|
| 1015 | - */ |
|
| 1016 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 1017 | - { |
|
| 1018 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1019 | - // get out we're not processing an event save. |
|
| 1020 | - return; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - $event_values = [ |
|
| 1024 | - 'EVT_display_desc' => $this->request->getRequestParam('display_desc', false, 'bool'), |
|
| 1025 | - 'EVT_display_ticket_selector' => $this->request->getRequestParam( |
|
| 1026 | - 'display_ticket_selector', |
|
| 1027 | - false, |
|
| 1028 | - 'bool' |
|
| 1029 | - ), |
|
| 1030 | - 'EVT_additional_limit' => min( |
|
| 1031 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1032 | - $this->request->getRequestParam('additional_limit', null, 'int') |
|
| 1033 | - ), |
|
| 1034 | - 'EVT_default_registration_status' => $this->request->getRequestParam( |
|
| 1035 | - 'EVT_default_registration_status', |
|
| 1036 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 1037 | - ), |
|
| 1038 | - |
|
| 1039 | - 'EVT_member_only' => $this->request->getRequestParam('member_only', false, 'bool'), |
|
| 1040 | - 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'), |
|
| 1041 | - 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
| 1042 | - 'EVT_external_URL' => $this->request->getRequestParam('externalURL'), |
|
| 1043 | - 'EVT_phone' => $this->request->getRequestParam('event_phone'), |
|
| 1044 | - ]; |
|
| 1045 | - // update event |
|
| 1046 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1047 | - // get event_object for other metaboxes... |
|
| 1048 | - // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
| 1049 | - // i have to setup where conditions to override the filters in the model |
|
| 1050 | - // that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 1051 | - $event = $this->_event_model()->get_one( |
|
| 1052 | - [ |
|
| 1053 | - [ |
|
| 1054 | - $this->_event_model()->primary_key_name() => $post_id, |
|
| 1055 | - 'OR' => [ |
|
| 1056 | - 'status' => $post->post_status, |
|
| 1057 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1058 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1059 | - 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
| 1060 | - ], |
|
| 1061 | - ], |
|
| 1062 | - ] |
|
| 1063 | - ); |
|
| 1064 | - // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 1065 | - $event_update_callbacks = apply_filters( |
|
| 1066 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1067 | - [ |
|
| 1068 | - [$this, '_default_venue_update'], |
|
| 1069 | - [$this, '_default_tickets_update'], |
|
| 1070 | - ] |
|
| 1071 | - ); |
|
| 1072 | - $att_success = true; |
|
| 1073 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 1074 | - $_success = is_callable($e_callback) |
|
| 1075 | - ? call_user_func($e_callback, $event, $this->request->requestParams()) |
|
| 1076 | - : false; |
|
| 1077 | - // if ANY of these updates fail then we want the appropriate global error message |
|
| 1078 | - $att_success = ! $att_success ? $att_success : $_success; |
|
| 1079 | - } |
|
| 1080 | - // any errors? |
|
| 1081 | - if ($success && false === $att_success) { |
|
| 1082 | - EE_Error::add_error( |
|
| 1083 | - esc_html__( |
|
| 1084 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1085 | - 'event_espresso' |
|
| 1086 | - ), |
|
| 1087 | - __FILE__, |
|
| 1088 | - __FUNCTION__, |
|
| 1089 | - __LINE__ |
|
| 1090 | - ); |
|
| 1091 | - } elseif ($success === false) { |
|
| 1092 | - EE_Error::add_error( |
|
| 1093 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1094 | - __FILE__, |
|
| 1095 | - __FUNCTION__, |
|
| 1096 | - __LINE__ |
|
| 1097 | - ); |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - |
|
| 1102 | - /** |
|
| 1103 | - * @param int $post_id |
|
| 1104 | - * @param int $revision_id |
|
| 1105 | - * @throws EE_Error |
|
| 1106 | - * @throws EE_Error |
|
| 1107 | - * @throws ReflectionException |
|
| 1108 | - * @see parent::restore_item() |
|
| 1109 | - */ |
|
| 1110 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1111 | - { |
|
| 1112 | - // copy existing event meta to new post |
|
| 1113 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1114 | - if ($post_evt instanceof EE_Event) { |
|
| 1115 | - // meta revision restore |
|
| 1116 | - $post_evt->restore_revision($revision_id); |
|
| 1117 | - // related objs restore |
|
| 1118 | - $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1119 | - } |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - |
|
| 1123 | - /** |
|
| 1124 | - * Attach the venue to the Event |
|
| 1125 | - * |
|
| 1126 | - * @param EE_Event $event Event Object to add the venue to |
|
| 1127 | - * @param array $data The request data from the form |
|
| 1128 | - * @return bool Success or fail. |
|
| 1129 | - * @throws EE_Error |
|
| 1130 | - * @throws ReflectionException |
|
| 1131 | - */ |
|
| 1132 | - protected function _default_venue_update(EE_Event $event, $data) |
|
| 1133 | - { |
|
| 1134 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1135 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1136 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1137 | - // very important. If we don't have a venue name... |
|
| 1138 | - // then we'll get out because not necessary to create empty venue |
|
| 1139 | - if (empty($data['venue_title'])) { |
|
| 1140 | - return false; |
|
| 1141 | - } |
|
| 1142 | - $venue_array = [ |
|
| 1143 | - 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
| 1144 | - 'VNU_name' => $data['venue_title'], |
|
| 1145 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1146 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1147 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
| 1148 | - ? $data['venue_short_description'] |
|
| 1149 | - : null, |
|
| 1150 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1151 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1152 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1153 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1154 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1155 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1156 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1157 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1158 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1159 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1160 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1161 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1162 | - 'status' => 'publish', |
|
| 1163 | - ]; |
|
| 1164 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1165 | - if (! empty($venue_id)) { |
|
| 1166 | - $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1167 | - $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1168 | - // 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. |
|
| 1169 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1170 | - return $rows_affected > 0; |
|
| 1171 | - } |
|
| 1172 | - // we insert the venue |
|
| 1173 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1174 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
| 1175 | - return ! empty($venue_id); |
|
| 1176 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - /** |
|
| 1181 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1182 | - * |
|
| 1183 | - * @param EE_Event $event The Event object we're attaching data to |
|
| 1184 | - * @param array $data The request data from the form |
|
| 1185 | - * @return array |
|
| 1186 | - * @throws EE_Error |
|
| 1187 | - * @throws ReflectionException |
|
| 1188 | - * @throws Exception |
|
| 1189 | - */ |
|
| 1190 | - protected function _default_tickets_update(EE_Event $event, $data) |
|
| 1191 | - { |
|
| 1192 | - $datetime = null; |
|
| 1193 | - $saved_tickets = []; |
|
| 1194 | - $event_timezone = $event->get_timezone(); |
|
| 1195 | - $date_formats = ['Y-m-d', 'h:i a']; |
|
| 1196 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 1197 | - // trim all values to ensure any excess whitespace is removed. |
|
| 1198 | - $datetime_data = array_map('trim', $datetime_data); |
|
| 1199 | - $datetime_data['DTT_EVT_end'] = |
|
| 1200 | - isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
|
| 1201 | - ? $datetime_data['DTT_EVT_end'] |
|
| 1202 | - : $datetime_data['DTT_EVT_start']; |
|
| 1203 | - $datetime_values = [ |
|
| 1204 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
| 1205 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 1206 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 1207 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
| 1208 | - 'DTT_order' => $row, |
|
| 1209 | - ]; |
|
| 1210 | - // if we have an id then let's get existing object first and then set the new values. |
|
| 1211 | - // Otherwise we instantiate a new object for save. |
|
| 1212 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 1213 | - $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 1214 | - if (! $datetime instanceof EE_Ticket) { |
|
| 1215 | - throw new RuntimeException( |
|
| 1216 | - sprintf( |
|
| 1217 | - esc_html__( |
|
| 1218 | - 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1219 | - 'event_espresso' |
|
| 1220 | - ), |
|
| 1221 | - $datetime_data['DTT_ID'] |
|
| 1222 | - ) |
|
| 1223 | - ); |
|
| 1224 | - } |
|
| 1225 | - $datetime->set_date_format($date_formats[0]); |
|
| 1226 | - $datetime->set_time_format($date_formats[1]); |
|
| 1227 | - foreach ($datetime_values as $field => $value) { |
|
| 1228 | - $datetime->set($field, $value); |
|
| 1229 | - } |
|
| 1230 | - } else { |
|
| 1231 | - $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
| 1232 | - } |
|
| 1233 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1234 | - throw new RuntimeException( |
|
| 1235 | - sprintf( |
|
| 1236 | - esc_html__( |
|
| 1237 | - 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
| 1238 | - 'event_espresso' |
|
| 1239 | - ), |
|
| 1240 | - print_r($datetime_values, true) |
|
| 1241 | - ) |
|
| 1242 | - ); |
|
| 1243 | - } |
|
| 1244 | - // before going any further make sure our dates are setup correctly |
|
| 1245 | - // so that the end date is always equal or greater than the start date. |
|
| 1246 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 1247 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 1248 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 1249 | - } |
|
| 1250 | - $datetime->save(); |
|
| 1251 | - $event->_add_relation_to($datetime, 'Datetime'); |
|
| 1252 | - } |
|
| 1253 | - // no datetimes get deleted so we don't do any of that logic here. |
|
| 1254 | - // update tickets next |
|
| 1255 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1256 | - |
|
| 1257 | - // set up some default start and end dates in case those are not present in the incoming data |
|
| 1258 | - $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 1259 | - $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
| 1260 | - // use the start date of the first datetime for the end date |
|
| 1261 | - $first_datetime = $event->first_datetime(); |
|
| 1262 | - $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
| 1263 | - |
|
| 1264 | - // now process the incoming data |
|
| 1265 | - foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
| 1266 | - $update_prices = false; |
|
| 1267 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1268 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1269 | - : 0; |
|
| 1270 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1271 | - $ticket_data = array_map('trim', $ticket_data); |
|
| 1272 | - $ticket_values = [ |
|
| 1273 | - 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
| 1274 | - 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
| 1275 | - 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
| 1276 | - 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
| 1277 | - 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
| 1278 | - ? $ticket_data['TKT_start_date'] |
|
| 1279 | - : $default_start_date, |
|
| 1280 | - 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
| 1281 | - ? $ticket_data['TKT_end_date'] |
|
| 1282 | - : $default_end_date, |
|
| 1283 | - 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
| 1284 | - || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
| 1285 | - ? $ticket_data['TKT_qty'] |
|
| 1286 | - : EE_INF, |
|
| 1287 | - 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
| 1288 | - || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
| 1289 | - ? $ticket_data['TKT_uses'] |
|
| 1290 | - : EE_INF, |
|
| 1291 | - 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
| 1292 | - 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
| 1293 | - 'TKT_order' => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row, |
|
| 1294 | - 'TKT_price' => $ticket_price, |
|
| 1295 | - 'TKT_row' => $row, |
|
| 1296 | - ]; |
|
| 1297 | - // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 1298 | - // which means in turn that the prices will become new prices as well. |
|
| 1299 | - if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
| 1300 | - $ticket_values['TKT_ID'] = 0; |
|
| 1301 | - $ticket_values['TKT_is_default'] = 0; |
|
| 1302 | - $update_prices = true; |
|
| 1303 | - } |
|
| 1304 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1305 | - // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
| 1306 | - // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
| 1307 | - // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
| 1308 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1309 | - if (! empty($ticket_data['TKT_ID'])) { |
|
| 1310 | - $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
| 1311 | - if (! $existing_ticket instanceof EE_Ticket) { |
|
| 1312 | - throw new RuntimeException( |
|
| 1313 | - sprintf( |
|
| 1314 | - esc_html__( |
|
| 1315 | - 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
| 1316 | - 'event_espresso' |
|
| 1317 | - ), |
|
| 1318 | - $ticket_data['TKT_ID'] |
|
| 1319 | - ) |
|
| 1320 | - ); |
|
| 1321 | - } |
|
| 1322 | - $ticket_sold = $existing_ticket->count_related( |
|
| 1323 | - 'Registration', |
|
| 1324 | - [ |
|
| 1325 | - [ |
|
| 1326 | - 'STS_ID' => [ |
|
| 1327 | - 'NOT IN', |
|
| 1328 | - [EEM_Registration::status_id_incomplete], |
|
| 1329 | - ], |
|
| 1330 | - ], |
|
| 1331 | - ] |
|
| 1332 | - ) > 0; |
|
| 1333 | - // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
| 1334 | - // if they are different then we create a new ticket (if $ticket_sold) |
|
| 1335 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 1336 | - $create_new_ticket = $ticket_sold |
|
| 1337 | - && $ticket_price !== $existing_ticket->price() |
|
| 1338 | - && ! $existing_ticket->deleted(); |
|
| 1339 | - $existing_ticket->set_date_format($date_formats[0]); |
|
| 1340 | - $existing_ticket->set_time_format($date_formats[1]); |
|
| 1341 | - // set new values |
|
| 1342 | - foreach ($ticket_values as $field => $value) { |
|
| 1343 | - if ($field == 'TKT_qty') { |
|
| 1344 | - $existing_ticket->set_qty($value); |
|
| 1345 | - } elseif ($field == 'TKT_price') { |
|
| 1346 | - $existing_ticket->set('TKT_price', $ticket_price); |
|
| 1347 | - } else { |
|
| 1348 | - $existing_ticket->set($field, $value); |
|
| 1349 | - } |
|
| 1350 | - } |
|
| 1351 | - $ticket = $existing_ticket; |
|
| 1352 | - // if $create_new_ticket is false then we can safely update the existing ticket. |
|
| 1353 | - // Otherwise we have to create a new ticket. |
|
| 1354 | - if ($create_new_ticket) { |
|
| 1355 | - // archive the old ticket first |
|
| 1356 | - $existing_ticket->set('TKT_deleted', 1); |
|
| 1357 | - $existing_ticket->save(); |
|
| 1358 | - // make sure this ticket is still recorded in our $saved_tickets |
|
| 1359 | - // so we don't run it through the regular trash routine. |
|
| 1360 | - $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
| 1361 | - // create new ticket that's a copy of the existing except, |
|
| 1362 | - // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
| 1363 | - $new_ticket = clone $existing_ticket; |
|
| 1364 | - $new_ticket->set('TKT_ID', 0); |
|
| 1365 | - $new_ticket->set('TKT_deleted', 0); |
|
| 1366 | - $new_ticket->set('TKT_sold', 0); |
|
| 1367 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1368 | - $update_prices = true; |
|
| 1369 | - $ticket = $new_ticket; |
|
| 1370 | - } |
|
| 1371 | - } else { |
|
| 1372 | - // no TKT_id so a new ticket |
|
| 1373 | - $ticket_values['TKT_price'] = $ticket_price; |
|
| 1374 | - $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
| 1375 | - $update_prices = true; |
|
| 1376 | - } |
|
| 1377 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1378 | - throw new RuntimeException( |
|
| 1379 | - sprintf( |
|
| 1380 | - esc_html__( |
|
| 1381 | - 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
| 1382 | - 'event_espresso' |
|
| 1383 | - ), |
|
| 1384 | - print_r($ticket_values, true) |
|
| 1385 | - ) |
|
| 1386 | - ); |
|
| 1387 | - } |
|
| 1388 | - // cap ticket qty by datetime reg limits |
|
| 1389 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 1390 | - // update ticket. |
|
| 1391 | - $ticket->save(); |
|
| 1392 | - // before going any further make sure our dates are setup correctly |
|
| 1393 | - // so that the end date is always equal or greater than the start date. |
|
| 1394 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 1395 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 1396 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 1397 | - $ticket->save(); |
|
| 1398 | - } |
|
| 1399 | - // initially let's add the ticket to the datetime |
|
| 1400 | - $datetime->_add_relation_to($ticket, 'Ticket'); |
|
| 1401 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 1402 | - // add prices to ticket |
|
| 1403 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices); |
|
| 1404 | - } |
|
| 1405 | - // however now we need to handle permanently deleting tickets via the ui. |
|
| 1406 | - // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
| 1407 | - // However, it does allow for deleting tickets that have no tickets sold, |
|
| 1408 | - // in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1409 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets; |
|
| 1410 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1411 | - foreach ($tickets_removed as $id) { |
|
| 1412 | - $id = absint($id); |
|
| 1413 | - // get the ticket for this id |
|
| 1414 | - $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
| 1415 | - if (! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1416 | - continue; |
|
| 1417 | - } |
|
| 1418 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 1419 | - // (remember this process can ONLY kick off if there are NO tickets sold) |
|
| 1420 | - $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
| 1421 | - foreach ($related_datetimes as $related_datetime) { |
|
| 1422 | - $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
| 1423 | - } |
|
| 1424 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 1425 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1426 | - $ticket_to_remove->delete_related_permanently('Price'); |
|
| 1427 | - // finally let's delete this ticket |
|
| 1428 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1429 | - $ticket_to_remove->delete_permanently(); |
|
| 1430 | - } |
|
| 1431 | - return [$datetime, $saved_tickets]; |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - |
|
| 1435 | - /** |
|
| 1436 | - * This attaches a list of given prices to a ticket. |
|
| 1437 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1438 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1439 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1440 | - * |
|
| 1441 | - * @access private |
|
| 1442 | - * @param array $prices_data Array of prices from the form. |
|
| 1443 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1444 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1445 | - * @return void |
|
| 1446 | - * @throws EE_Error |
|
| 1447 | - * @throws ReflectionException |
|
| 1448 | - */ |
|
| 1449 | - private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false) |
|
| 1450 | - { |
|
| 1451 | - $timezone = $ticket->get_timezone(); |
|
| 1452 | - foreach ($prices_data as $row => $price_data) { |
|
| 1453 | - $price_values = [ |
|
| 1454 | - 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
| 1455 | - 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
| 1456 | - 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
| 1457 | - 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
| 1458 | - 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
| 1459 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1460 | - 'PRC_order' => $row, |
|
| 1461 | - ]; |
|
| 1462 | - if ($new_prices || empty($price_values['PRC_ID'])) { |
|
| 1463 | - $price_values['PRC_ID'] = 0; |
|
| 1464 | - $price = EE_Price::new_instance($price_values, $timezone); |
|
| 1465 | - } else { |
|
| 1466 | - $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
| 1467 | - // update this price with new values |
|
| 1468 | - foreach ($price_values as $field => $new_price) { |
|
| 1469 | - $price->set($field, $new_price); |
|
| 1470 | - } |
|
| 1471 | - } |
|
| 1472 | - if (! $price instanceof EE_Price) { |
|
| 1473 | - throw new RuntimeException( |
|
| 1474 | - sprintf( |
|
| 1475 | - esc_html__( |
|
| 1476 | - 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
| 1477 | - 'event_espresso' |
|
| 1478 | - ), |
|
| 1479 | - print_r($price_values, true) |
|
| 1480 | - ) |
|
| 1481 | - ); |
|
| 1482 | - } |
|
| 1483 | - $price->save(); |
|
| 1484 | - $ticket->_add_relation_to($price, 'Price'); |
|
| 1485 | - } |
|
| 1486 | - } |
|
| 1487 | - |
|
| 1488 | - |
|
| 1489 | - /** |
|
| 1490 | - * Add in our autosave ajax handlers |
|
| 1491 | - * |
|
| 1492 | - */ |
|
| 1493 | - protected function _ee_autosave_create_new() |
|
| 1494 | - { |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * More autosave handlers. |
|
| 1500 | - */ |
|
| 1501 | - protected function _ee_autosave_edit() |
|
| 1502 | - { |
|
| 1503 | - // TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1504 | - } |
|
| 1505 | - |
|
| 1506 | - |
|
| 1507 | - /** |
|
| 1508 | - * @throws EE_Error |
|
| 1509 | - * @throws ReflectionException |
|
| 1510 | - */ |
|
| 1511 | - private function _generate_publish_box_extra_content() |
|
| 1512 | - { |
|
| 1513 | - // load formatter helper |
|
| 1514 | - // args for getting related registrations |
|
| 1515 | - $approved_query_args = [ |
|
| 1516 | - [ |
|
| 1517 | - 'REG_deleted' => 0, |
|
| 1518 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1519 | - ], |
|
| 1520 | - ]; |
|
| 1521 | - $not_approved_query_args = [ |
|
| 1522 | - [ |
|
| 1523 | - 'REG_deleted' => 0, |
|
| 1524 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1525 | - ], |
|
| 1526 | - ]; |
|
| 1527 | - $pending_payment_query_args = [ |
|
| 1528 | - [ |
|
| 1529 | - 'REG_deleted' => 0, |
|
| 1530 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1531 | - ], |
|
| 1532 | - ]; |
|
| 1533 | - // publish box |
|
| 1534 | - $publish_box_extra_args = [ |
|
| 1535 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1536 | - [ |
|
| 1537 | - 'action' => 'default', |
|
| 1538 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1539 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1540 | - ], |
|
| 1541 | - REG_ADMIN_URL |
|
| 1542 | - ), |
|
| 1543 | - 'view_not_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_not_approved, |
|
| 1548 | - ], |
|
| 1549 | - REG_ADMIN_URL |
|
| 1550 | - ), |
|
| 1551 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1552 | - [ |
|
| 1553 | - 'action' => 'default', |
|
| 1554 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1555 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1556 | - ], |
|
| 1557 | - REG_ADMIN_URL |
|
| 1558 | - ), |
|
| 1559 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1560 | - 'Registration', |
|
| 1561 | - $approved_query_args |
|
| 1562 | - ), |
|
| 1563 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1564 | - 'Registration', |
|
| 1565 | - $not_approved_query_args |
|
| 1566 | - ), |
|
| 1567 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1568 | - 'Registration', |
|
| 1569 | - $pending_payment_query_args |
|
| 1570 | - ), |
|
| 1571 | - 'misc_pub_section_class' => apply_filters( |
|
| 1572 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1573 | - 'misc-pub-section' |
|
| 1574 | - ), |
|
| 1575 | - ]; |
|
| 1576 | - ob_start(); |
|
| 1577 | - do_action( |
|
| 1578 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1579 | - $this->_cpt_model_obj |
|
| 1580 | - ); |
|
| 1581 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1582 | - // load template |
|
| 1583 | - EEH_Template::display_template( |
|
| 1584 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1585 | - $publish_box_extra_args |
|
| 1586 | - ); |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - /** |
|
| 1591 | - * @return EE_Event |
|
| 1592 | - */ |
|
| 1593 | - public function get_event_object() |
|
| 1594 | - { |
|
| 1595 | - return $this->_cpt_model_obj; |
|
| 1596 | - } |
|
| 1597 | - |
|
| 1598 | - |
|
| 1599 | - |
|
| 1600 | - |
|
| 1601 | - /** METABOXES * */ |
|
| 1602 | - /** |
|
| 1603 | - * _register_event_editor_meta_boxes |
|
| 1604 | - * add all metaboxes related to the event_editor |
|
| 1605 | - * |
|
| 1606 | - * @return void |
|
| 1607 | - * @throws EE_Error |
|
| 1608 | - * @throws ReflectionException |
|
| 1609 | - */ |
|
| 1610 | - protected function _register_event_editor_meta_boxes() |
|
| 1611 | - { |
|
| 1612 | - $this->verify_cpt_object(); |
|
| 1613 | - add_meta_box( |
|
| 1614 | - 'espresso_event_editor_tickets', |
|
| 1615 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1616 | - [$this, 'ticket_metabox'], |
|
| 1617 | - $this->page_slug, |
|
| 1618 | - 'normal', |
|
| 1619 | - 'high' |
|
| 1620 | - ); |
|
| 1621 | - add_meta_box( |
|
| 1622 | - 'espresso_event_editor_event_options', |
|
| 1623 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1624 | - [$this, 'registration_options_meta_box'], |
|
| 1625 | - $this->page_slug, |
|
| 1626 | - 'side' |
|
| 1627 | - ); |
|
| 1628 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1629 | - // where a metabox has a related management page in the admin |
|
| 1630 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1631 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * @throws DomainException |
|
| 1637 | - * @throws EE_Error |
|
| 1638 | - * @throws ReflectionException |
|
| 1639 | - */ |
|
| 1640 | - public function ticket_metabox() |
|
| 1641 | - { |
|
| 1642 | - $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1643 | - // defaults for template args |
|
| 1644 | - $template_args = [ |
|
| 1645 | - 'existing_datetime_ids' => '', |
|
| 1646 | - 'event_datetime_help_link' => '', |
|
| 1647 | - 'ticket_options_help_link' => '', |
|
| 1648 | - 'time' => null, |
|
| 1649 | - 'ticket_rows' => '', |
|
| 1650 | - 'existing_ticket_ids' => '', |
|
| 1651 | - 'total_ticket_rows' => 1, |
|
| 1652 | - 'ticket_js_structure' => '', |
|
| 1653 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1654 | - 'disabled' => '', |
|
| 1655 | - ]; |
|
| 1656 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1657 | - /** |
|
| 1658 | - * 1. Start with retrieving Datetimes |
|
| 1659 | - * 2. Fore each datetime get related tickets |
|
| 1660 | - * 3. For each ticket get related prices |
|
| 1661 | - */ |
|
| 1662 | - $times = EEM_Datetime::instance()->get_all_event_dates($event_id); |
|
| 1663 | - $first_datetime = reset($times); |
|
| 1664 | - // do we get related tickets? |
|
| 1665 | - if ( |
|
| 1666 | - $first_datetime instanceof EE_Datetime |
|
| 1667 | - && $first_datetime->ID() !== 0 |
|
| 1668 | - ) { |
|
| 1669 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1670 | - $template_args['time'] = $first_datetime; |
|
| 1671 | - $related_tickets = $first_datetime->tickets( |
|
| 1672 | - [ |
|
| 1673 | - ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1674 | - 'default_where_conditions' => 'none', |
|
| 1675 | - ] |
|
| 1676 | - ); |
|
| 1677 | - if (! empty($related_tickets)) { |
|
| 1678 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1679 | - $row = 0; |
|
| 1680 | - foreach ($related_tickets as $ticket) { |
|
| 1681 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1682 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1683 | - $row++; |
|
| 1684 | - } |
|
| 1685 | - } else { |
|
| 1686 | - $template_args['total_ticket_rows'] = 1; |
|
| 1687 | - /** @type EE_Ticket $ticket */ |
|
| 1688 | - $ticket = EEM_Ticket::instance()->create_default_object(); |
|
| 1689 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1690 | - } |
|
| 1691 | - } else { |
|
| 1692 | - $template_args['time'] = $times[0]; |
|
| 1693 | - $tickets = EEM_Ticket::instance()->get_all_default_tickets(); |
|
| 1694 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
| 1695 | - // NOTE: we're just sending the first default row |
|
| 1696 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1697 | - } |
|
| 1698 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1699 | - 'event_editor_event_datetimes_help_tab' |
|
| 1700 | - ); |
|
| 1701 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1702 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1703 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1704 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1705 | - EEM_Ticket::instance()->create_default_object(), |
|
| 1706 | - true |
|
| 1707 | - ); |
|
| 1708 | - $template = apply_filters( |
|
| 1709 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1710 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1711 | - ); |
|
| 1712 | - EEH_Template::display_template($template, $template_args); |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - |
|
| 1716 | - /** |
|
| 1717 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1718 | - * |
|
| 1719 | - * @access private |
|
| 1720 | - * @param EE_Ticket $ticket the ticket object |
|
| 1721 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1722 | - * @param int $row |
|
| 1723 | - * @return string generated html for the ticket row. |
|
| 1724 | - * @throws EE_Error |
|
| 1725 | - * @throws ReflectionException |
|
| 1726 | - */ |
|
| 1727 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1728 | - { |
|
| 1729 | - $template_args = [ |
|
| 1730 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1731 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1732 | - : '', |
|
| 1733 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1734 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1735 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1736 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1737 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1738 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1739 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1740 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1741 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1742 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1743 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1744 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1745 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1746 | - : ' disabled=disabled', |
|
| 1747 | - ]; |
|
| 1748 | - $price = $ticket->ID() !== 0 |
|
| 1749 | - ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1750 | - : null; |
|
| 1751 | - $price = $price instanceof EE_Price |
|
| 1752 | - ? $price |
|
| 1753 | - : EEM_Price::instance()->create_default_object(); |
|
| 1754 | - $price_args = [ |
|
| 1755 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1756 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1757 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1758 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1759 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1760 | - ]; |
|
| 1761 | - // make sure we have default start and end dates if skeleton |
|
| 1762 | - // handle rows that should NOT be empty |
|
| 1763 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1764 | - // if empty then the start date will be now. |
|
| 1765 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1766 | - } |
|
| 1767 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1768 | - // get the earliest datetime (if present); |
|
| 1769 | - $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1770 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1771 | - 'Datetime', |
|
| 1772 | - ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1773 | - ) |
|
| 1774 | - : null; |
|
| 1775 | - $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
| 1776 | - ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
| 1777 | - : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
| 1778 | - } |
|
| 1779 | - $template_args = array_merge($template_args, $price_args); |
|
| 1780 | - $template = apply_filters( |
|
| 1781 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1782 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1783 | - $ticket |
|
| 1784 | - ); |
|
| 1785 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1786 | - } |
|
| 1787 | - |
|
| 1788 | - |
|
| 1789 | - /** |
|
| 1790 | - * @throws EE_Error |
|
| 1791 | - * @throws ReflectionException |
|
| 1792 | - */ |
|
| 1793 | - public function registration_options_meta_box() |
|
| 1794 | - { |
|
| 1795 | - $yes_no_values = [ |
|
| 1796 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1797 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1798 | - ]; |
|
| 1799 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1800 | - [ |
|
| 1801 | - EEM_Registration::status_id_cancelled, |
|
| 1802 | - EEM_Registration::status_id_declined, |
|
| 1803 | - EEM_Registration::status_id_incomplete, |
|
| 1804 | - ], |
|
| 1805 | - true |
|
| 1806 | - ); |
|
| 1807 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1808 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1809 | - $template_args['event'] = $this->_cpt_model_obj; |
|
| 1810 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1811 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1812 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1813 | - 'default_reg_status', |
|
| 1814 | - $default_reg_status_values, |
|
| 1815 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1816 | - ); |
|
| 1817 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1818 | - 'display_desc', |
|
| 1819 | - $yes_no_values, |
|
| 1820 | - $this->_cpt_model_obj->display_description() |
|
| 1821 | - ); |
|
| 1822 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1823 | - 'display_ticket_selector', |
|
| 1824 | - $yes_no_values, |
|
| 1825 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1826 | - '', |
|
| 1827 | - '', |
|
| 1828 | - false |
|
| 1829 | - ); |
|
| 1830 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1831 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1832 | - '', |
|
| 1833 | - $template_args, |
|
| 1834 | - $yes_no_values, |
|
| 1835 | - $default_reg_status_values |
|
| 1836 | - ); |
|
| 1837 | - EEH_Template::display_template( |
|
| 1838 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1839 | - $template_args |
|
| 1840 | - ); |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - |
|
| 1844 | - /** |
|
| 1845 | - * _get_events() |
|
| 1846 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1847 | - * |
|
| 1848 | - * @access public |
|
| 1849 | - * @param int $per_page count of items per page (20 default); |
|
| 1850 | - * @param int $current_page what is the current page being viewed. |
|
| 1851 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1852 | - * If FALSE then we return an array of event objects |
|
| 1853 | - * that match the given _view and paging parameters. |
|
| 1854 | - * @return array|int an array of event objects or a count of them. |
|
| 1855 | - * @throws Exception |
|
| 1856 | - */ |
|
| 1857 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1858 | - { |
|
| 1859 | - $EEM_Event = $this->_event_model(); |
|
| 1860 | - $offset = ($current_page - 1) * $per_page; |
|
| 1861 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1862 | - $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
| 1863 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 1864 | - $month_range = $this->request->getRequestParam('month_range'); |
|
| 1865 | - if ($month_range) { |
|
| 1866 | - $pieces = explode(' ', $month_range, 3); |
|
| 1867 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1868 | - // where PHP doesn't know what to assume for date. |
|
| 1869 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1870 | - $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1871 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1872 | - } |
|
| 1873 | - $where = []; |
|
| 1874 | - $status = $this->request->getRequestParam('status'); |
|
| 1875 | - // determine what post_status our condition will have for the query. |
|
| 1876 | - switch ($status) { |
|
| 1877 | - case 'month': |
|
| 1878 | - case 'today': |
|
| 1879 | - case null: |
|
| 1880 | - case 'all': |
|
| 1881 | - break; |
|
| 1882 | - case 'draft': |
|
| 1883 | - $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1884 | - break; |
|
| 1885 | - default: |
|
| 1886 | - $where['status'] = $status; |
|
| 1887 | - } |
|
| 1888 | - // categories? |
|
| 1889 | - $category = $this->request->getRequestParam('EVT_CAT', 0, 'int'); |
|
| 1890 | - if ($category) { |
|
| 1891 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1892 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1893 | - } |
|
| 1894 | - // date where conditions |
|
| 1895 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1896 | - if ($month_range) { |
|
| 1897 | - $DateTime = new DateTime( |
|
| 1898 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1899 | - new DateTimeZone('UTC') |
|
| 1900 | - ); |
|
| 1901 | - $start = $DateTime->getTimestamp(); |
|
| 1902 | - // set the datetime to be the end of the month |
|
| 1903 | - $DateTime->setDate( |
|
| 1904 | - $year_r, |
|
| 1905 | - $month_r, |
|
| 1906 | - $DateTime->format('t') |
|
| 1907 | - )->setTime(23, 59, 59); |
|
| 1908 | - $end = $DateTime->getTimestamp(); |
|
| 1909 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1910 | - } elseif ($status === 'today') { |
|
| 1911 | - $DateTime = |
|
| 1912 | - new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1913 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1914 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1915 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1916 | - } elseif ($status === 'month') { |
|
| 1917 | - $now = date('Y-m-01'); |
|
| 1918 | - $DateTime = |
|
| 1919 | - new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1920 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
| 1921 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1922 | - ->setTime(23, 59, 59) |
|
| 1923 | - ->format(implode(' ', $start_formats)); |
|
| 1924 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1925 | - } |
|
| 1926 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1927 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1928 | - } else { |
|
| 1929 | - if (! isset($where['status'])) { |
|
| 1930 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1931 | - $where['OR'] = [ |
|
| 1932 | - 'status*restrict_private' => ['!=', 'private'], |
|
| 1933 | - 'AND' => [ |
|
| 1934 | - 'status*inclusive' => ['=', 'private'], |
|
| 1935 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1936 | - ], |
|
| 1937 | - ]; |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - } |
|
| 1941 | - $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int'); |
|
| 1942 | - if ( |
|
| 1943 | - $wp_user |
|
| 1944 | - && $wp_user !== get_current_user_id() |
|
| 1945 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1946 | - ) { |
|
| 1947 | - $where['EVT_wp_user'] = $wp_user; |
|
| 1948 | - } |
|
| 1949 | - // search query handling |
|
| 1950 | - $search_term = $this->request->getRequestParam('s'); |
|
| 1951 | - if ($search_term) { |
|
| 1952 | - $search_term = '%' . $search_term . '%'; |
|
| 1953 | - $where['OR'] = [ |
|
| 1954 | - 'EVT_name' => ['LIKE', $search_term], |
|
| 1955 | - 'EVT_desc' => ['LIKE', $search_term], |
|
| 1956 | - 'EVT_short_desc' => ['LIKE', $search_term], |
|
| 1957 | - ]; |
|
| 1958 | - } |
|
| 1959 | - // filter events by venue. |
|
| 1960 | - $venue = $this->request->getRequestParam('venue', 0, 'int'); |
|
| 1961 | - if ($venue) { |
|
| 1962 | - $where['Venue.VNU_ID'] = $venue; |
|
| 1963 | - } |
|
| 1964 | - $request_params = $this->request->requestParams(); |
|
| 1965 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
| 1966 | - $query_params = apply_filters( |
|
| 1967 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1968 | - [ |
|
| 1969 | - $where, |
|
| 1970 | - 'limit' => $limit, |
|
| 1971 | - 'order_by' => $orderby, |
|
| 1972 | - 'order' => $order, |
|
| 1973 | - 'group_by' => 'EVT_ID', |
|
| 1974 | - ], |
|
| 1975 | - $request_params |
|
| 1976 | - ); |
|
| 1977 | - |
|
| 1978 | - // let's first check if we have special requests coming in. |
|
| 1979 | - $active_status = $this->request->getRequestParam('active_status'); |
|
| 1980 | - if ($active_status) { |
|
| 1981 | - switch ($active_status) { |
|
| 1982 | - case 'upcoming': |
|
| 1983 | - return $EEM_Event->get_upcoming_events($query_params, $count); |
|
| 1984 | - case 'expired': |
|
| 1985 | - return $EEM_Event->get_expired_events($query_params, $count); |
|
| 1986 | - case 'active': |
|
| 1987 | - return $EEM_Event->get_active_events($query_params, $count); |
|
| 1988 | - case 'inactive': |
|
| 1989 | - return $EEM_Event->get_inactive_events($query_params, $count); |
|
| 1990 | - } |
|
| 1991 | - } |
|
| 1992 | - |
|
| 1993 | - return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - |
|
| 1997 | - /** |
|
| 1998 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1999 | - * |
|
| 2000 | - * @param string $post_id |
|
| 2001 | - * @throws EE_Error |
|
| 2002 | - * @throws ReflectionException |
|
| 2003 | - */ |
|
| 2004 | - public function trash_cpt_item($post_id) |
|
| 2005 | - { |
|
| 2006 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2007 | - $this->_trash_or_restore_event('trash', false); |
|
| 2008 | - } |
|
| 2009 | - |
|
| 2010 | - |
|
| 2011 | - /** |
|
| 2012 | - * @param string $post_id |
|
| 2013 | - * @throws EE_Error |
|
| 2014 | - * @throws ReflectionException |
|
| 2015 | - */ |
|
| 2016 | - public function restore_cpt_item($post_id) |
|
| 2017 | - { |
|
| 2018 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2019 | - $this->_trash_or_restore_event('draft', false); |
|
| 2020 | - } |
|
| 2021 | - |
|
| 2022 | - |
|
| 2023 | - /** |
|
| 2024 | - * @param string $post_id |
|
| 2025 | - * @throws EE_Error |
|
| 2026 | - * @throws EE_Error |
|
| 2027 | - */ |
|
| 2028 | - public function delete_cpt_item($post_id) |
|
| 2029 | - { |
|
| 2030 | - throw new EE_Error( |
|
| 2031 | - esc_html__( |
|
| 2032 | - 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
| 2033 | - 'event_espresso' |
|
| 2034 | - ) |
|
| 2035 | - ); |
|
| 2036 | - // $this->request->setRequestParam('EVT_ID', $post_id); |
|
| 2037 | - // $this->_delete_event(); |
|
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - |
|
| 2041 | - /** |
|
| 2042 | - * _trash_or_restore_event |
|
| 2043 | - * |
|
| 2044 | - * @access protected |
|
| 2045 | - * @param string $event_status |
|
| 2046 | - * @param bool $redirect_after |
|
| 2047 | - * @throws EE_Error |
|
| 2048 | - * @throws EE_Error |
|
| 2049 | - * @throws ReflectionException |
|
| 2050 | - */ |
|
| 2051 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 2052 | - { |
|
| 2053 | - // determine the event id and set to array. |
|
| 2054 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int'); |
|
| 2055 | - // loop thru events |
|
| 2056 | - if ($EVT_ID) { |
|
| 2057 | - // clean status |
|
| 2058 | - $event_status = sanitize_key($event_status); |
|
| 2059 | - // grab status |
|
| 2060 | - if (! empty($event_status)) { |
|
| 2061 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2062 | - } else { |
|
| 2063 | - $success = false; |
|
| 2064 | - $msg = esc_html__( |
|
| 2065 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2066 | - 'event_espresso' |
|
| 2067 | - ); |
|
| 2068 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2069 | - } |
|
| 2070 | - } else { |
|
| 2071 | - $success = false; |
|
| 2072 | - $msg = esc_html__( |
|
| 2073 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2074 | - 'event_espresso' |
|
| 2075 | - ); |
|
| 2076 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2077 | - } |
|
| 2078 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2079 | - if ($redirect_after) { |
|
| 2080 | - $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2081 | - } |
|
| 2082 | - } |
|
| 2083 | - |
|
| 2084 | - |
|
| 2085 | - /** |
|
| 2086 | - * _trash_or_restore_events |
|
| 2087 | - * |
|
| 2088 | - * @access protected |
|
| 2089 | - * @param string $event_status |
|
| 2090 | - * @return void |
|
| 2091 | - * @throws EE_Error |
|
| 2092 | - * @throws EE_Error |
|
| 2093 | - * @throws ReflectionException |
|
| 2094 | - */ |
|
| 2095 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2096 | - { |
|
| 2097 | - // clean status |
|
| 2098 | - $event_status = sanitize_key($event_status); |
|
| 2099 | - // grab status |
|
| 2100 | - if (! empty($event_status)) { |
|
| 2101 | - $success = true; |
|
| 2102 | - // determine the event id and set to array. |
|
| 2103 | - $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
| 2104 | - // loop thru events |
|
| 2105 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2106 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 2107 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2108 | - $success = $results !== false ? $success : false; |
|
| 2109 | - } else { |
|
| 2110 | - $msg = sprintf( |
|
| 2111 | - esc_html__( |
|
| 2112 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2113 | - 'event_espresso' |
|
| 2114 | - ), |
|
| 2115 | - $EVT_ID |
|
| 2116 | - ); |
|
| 2117 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2118 | - $success = false; |
|
| 2119 | - } |
|
| 2120 | - } |
|
| 2121 | - } else { |
|
| 2122 | - $success = false; |
|
| 2123 | - $msg = esc_html__( |
|
| 2124 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2125 | - 'event_espresso' |
|
| 2126 | - ); |
|
| 2127 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2128 | - } |
|
| 2129 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2130 | - $success = $success ? 2 : false; |
|
| 2131 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2132 | - $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2133 | - } |
|
| 2134 | - |
|
| 2135 | - |
|
| 2136 | - /** |
|
| 2137 | - * @param int $EVT_ID |
|
| 2138 | - * @param string $event_status |
|
| 2139 | - * @return bool |
|
| 2140 | - * @throws EE_Error |
|
| 2141 | - * @throws ReflectionException |
|
| 2142 | - */ |
|
| 2143 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2144 | - { |
|
| 2145 | - // grab event id |
|
| 2146 | - if (! $EVT_ID) { |
|
| 2147 | - $msg = esc_html__( |
|
| 2148 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2149 | - 'event_espresso' |
|
| 2150 | - ); |
|
| 2151 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2152 | - return false; |
|
| 2153 | - } |
|
| 2154 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2155 | - // clean status |
|
| 2156 | - $event_status = sanitize_key($event_status); |
|
| 2157 | - // grab status |
|
| 2158 | - if (empty($event_status)) { |
|
| 2159 | - $msg = esc_html__( |
|
| 2160 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2161 | - 'event_espresso' |
|
| 2162 | - ); |
|
| 2163 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2164 | - return false; |
|
| 2165 | - } |
|
| 2166 | - // was event trashed or restored ? |
|
| 2167 | - switch ($event_status) { |
|
| 2168 | - case 'draft': |
|
| 2169 | - $action = 'restored from the trash'; |
|
| 2170 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2171 | - break; |
|
| 2172 | - case 'trash': |
|
| 2173 | - $action = 'moved to the trash'; |
|
| 2174 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2175 | - break; |
|
| 2176 | - default: |
|
| 2177 | - $action = 'updated'; |
|
| 2178 | - $hook = false; |
|
| 2179 | - } |
|
| 2180 | - // use class to change status |
|
| 2181 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2182 | - $success = $this->_cpt_model_obj->save(); |
|
| 2183 | - if (! $success) { |
|
| 2184 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2185 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2186 | - return false; |
|
| 2187 | - } |
|
| 2188 | - if ($hook) { |
|
| 2189 | - do_action($hook); |
|
| 2190 | - } |
|
| 2191 | - return true; |
|
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - |
|
| 2195 | - /** |
|
| 2196 | - * @param array $event_ids |
|
| 2197 | - * @return array |
|
| 2198 | - * @since 4.10.23.p |
|
| 2199 | - */ |
|
| 2200 | - private function cleanEventIds(array $event_ids) |
|
| 2201 | - { |
|
| 2202 | - return array_map('absint', $event_ids); |
|
| 2203 | - } |
|
| 2204 | - |
|
| 2205 | - |
|
| 2206 | - /** |
|
| 2207 | - * @return array |
|
| 2208 | - * @since 4.10.23.p |
|
| 2209 | - */ |
|
| 2210 | - private function getEventIdsFromRequest() |
|
| 2211 | - { |
|
| 2212 | - return $this->request->getRequestParam('EVT_IDs', [], 'int', true, ','); |
|
| 2213 | - } |
|
| 2214 | - |
|
| 2215 | - |
|
| 2216 | - /** |
|
| 2217 | - * @param bool $preview_delete |
|
| 2218 | - * @throws EE_Error |
|
| 2219 | - */ |
|
| 2220 | - protected function _delete_event($preview_delete = true) |
|
| 2221 | - { |
|
| 2222 | - $this->_delete_events($preview_delete); |
|
| 2223 | - } |
|
| 2224 | - |
|
| 2225 | - |
|
| 2226 | - /** |
|
| 2227 | - * Gets the tree traversal batch persister. |
|
| 2228 | - * |
|
| 2229 | - * @return NodeGroupDao |
|
| 2230 | - * @throws InvalidArgumentException |
|
| 2231 | - * @throws InvalidDataTypeException |
|
| 2232 | - * @throws InvalidInterfaceException |
|
| 2233 | - * @since 4.10.12.p |
|
| 2234 | - */ |
|
| 2235 | - protected function getModelObjNodeGroupPersister() |
|
| 2236 | - { |
|
| 2237 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2238 | - $this->model_obj_node_group_persister = |
|
| 2239 | - $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2240 | - } |
|
| 2241 | - return $this->model_obj_node_group_persister; |
|
| 2242 | - } |
|
| 2243 | - |
|
| 2244 | - |
|
| 2245 | - /** |
|
| 2246 | - * @param bool $preview_delete |
|
| 2247 | - * @return void |
|
| 2248 | - * @throws EE_Error |
|
| 2249 | - */ |
|
| 2250 | - protected function _delete_events($preview_delete = true) |
|
| 2251 | - { |
|
| 2252 | - $event_ids = $this->getEventIdsFromRequest(); |
|
| 2253 | - if ($preview_delete) { |
|
| 2254 | - $this->generateDeletionPreview($event_ids); |
|
| 2255 | - } else { |
|
| 2256 | - EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]); |
|
| 2257 | - } |
|
| 2258 | - } |
|
| 2259 | - |
|
| 2260 | - |
|
| 2261 | - /** |
|
| 2262 | - * @param array $event_ids |
|
| 2263 | - */ |
|
| 2264 | - protected function generateDeletionPreview(array $event_ids) |
|
| 2265 | - { |
|
| 2266 | - $event_ids = $this->cleanEventIds($event_ids); |
|
| 2267 | - // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2268 | - $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2269 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2270 | - [ |
|
| 2271 | - 'action' => 'preview_deletion', |
|
| 2272 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2273 | - ], |
|
| 2274 | - $this->_admin_base_url |
|
| 2275 | - ); |
|
| 2276 | - EEH_URL::safeRedirectAndExit( |
|
| 2277 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2278 | - [ |
|
| 2279 | - 'page' => 'espresso_batch', |
|
| 2280 | - 'batch' => EED_Batch::batch_job, |
|
| 2281 | - 'EVT_IDs' => $event_ids, |
|
| 2282 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2283 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
| 2284 | - 'return_url' => urlencode($return_url), |
|
| 2285 | - ], |
|
| 2286 | - admin_url() |
|
| 2287 | - ) |
|
| 2288 | - ); |
|
| 2289 | - } |
|
| 2290 | - |
|
| 2291 | - |
|
| 2292 | - /** |
|
| 2293 | - * Checks for a POST submission |
|
| 2294 | - * |
|
| 2295 | - * @since 4.10.12.p |
|
| 2296 | - */ |
|
| 2297 | - protected function confirmDeletion() |
|
| 2298 | - { |
|
| 2299 | - $deletion_redirect_logic = |
|
| 2300 | - $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
| 2301 | - $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2302 | - } |
|
| 2303 | - |
|
| 2304 | - |
|
| 2305 | - /** |
|
| 2306 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2307 | - * |
|
| 2308 | - * @throws EE_Error |
|
| 2309 | - * @since 4.10.12.p |
|
| 2310 | - */ |
|
| 2311 | - protected function previewDeletion() |
|
| 2312 | - { |
|
| 2313 | - $preview_deletion_logic = |
|
| 2314 | - $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
| 2315 | - $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2316 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2317 | - } |
|
| 2318 | - |
|
| 2319 | - |
|
| 2320 | - /** |
|
| 2321 | - * get total number of events |
|
| 2322 | - * |
|
| 2323 | - * @access public |
|
| 2324 | - * @return int |
|
| 2325 | - * @throws EE_Error |
|
| 2326 | - * @throws EE_Error |
|
| 2327 | - */ |
|
| 2328 | - public function total_events() |
|
| 2329 | - { |
|
| 2330 | - return EEM_Event::instance()->count( |
|
| 2331 | - ['caps' => 'read_admin'], |
|
| 2332 | - 'EVT_ID', |
|
| 2333 | - true |
|
| 2334 | - ); |
|
| 2335 | - } |
|
| 2336 | - |
|
| 2337 | - |
|
| 2338 | - /** |
|
| 2339 | - * get total number of draft events |
|
| 2340 | - * |
|
| 2341 | - * @access public |
|
| 2342 | - * @return int |
|
| 2343 | - * @throws EE_Error |
|
| 2344 | - * @throws EE_Error |
|
| 2345 | - */ |
|
| 2346 | - public function total_events_draft() |
|
| 2347 | - { |
|
| 2348 | - return EEM_Event::instance()->count( |
|
| 2349 | - [ |
|
| 2350 | - ['status' => ['IN', ['draft', 'auto-draft']]], |
|
| 2351 | - 'caps' => 'read_admin', |
|
| 2352 | - ], |
|
| 2353 | - 'EVT_ID', |
|
| 2354 | - true |
|
| 2355 | - ); |
|
| 2356 | - } |
|
| 2357 | - |
|
| 2358 | - |
|
| 2359 | - /** |
|
| 2360 | - * get total number of trashed events |
|
| 2361 | - * |
|
| 2362 | - * @access public |
|
| 2363 | - * @return int |
|
| 2364 | - * @throws EE_Error |
|
| 2365 | - * @throws EE_Error |
|
| 2366 | - */ |
|
| 2367 | - public function total_trashed_events() |
|
| 2368 | - { |
|
| 2369 | - return EEM_Event::instance()->count( |
|
| 2370 | - [ |
|
| 2371 | - ['status' => 'trash'], |
|
| 2372 | - 'caps' => 'read_admin', |
|
| 2373 | - ], |
|
| 2374 | - 'EVT_ID', |
|
| 2375 | - true |
|
| 2376 | - ); |
|
| 2377 | - } |
|
| 2378 | - |
|
| 2379 | - |
|
| 2380 | - /** |
|
| 2381 | - * _default_event_settings |
|
| 2382 | - * This generates the Default Settings Tab |
|
| 2383 | - * |
|
| 2384 | - * @return void |
|
| 2385 | - * @throws EE_Error |
|
| 2386 | - */ |
|
| 2387 | - protected function _default_event_settings() |
|
| 2388 | - { |
|
| 2389 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2390 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2391 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2392 | - $this->display_admin_page_with_sidebar(); |
|
| 2393 | - } |
|
| 2394 | - |
|
| 2395 | - |
|
| 2396 | - /** |
|
| 2397 | - * Return the form for event settings. |
|
| 2398 | - * |
|
| 2399 | - * @return EE_Form_Section_Proper |
|
| 2400 | - * @throws EE_Error |
|
| 2401 | - */ |
|
| 2402 | - protected function _default_event_settings_form() |
|
| 2403 | - { |
|
| 2404 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2405 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2406 | - // exclude |
|
| 2407 | - [ |
|
| 2408 | - EEM_Registration::status_id_cancelled, |
|
| 2409 | - EEM_Registration::status_id_declined, |
|
| 2410 | - EEM_Registration::status_id_incomplete, |
|
| 2411 | - EEM_Registration::status_id_wait_list, |
|
| 2412 | - ], |
|
| 2413 | - true |
|
| 2414 | - ); |
|
| 2415 | - return new EE_Form_Section_Proper( |
|
| 2416 | - [ |
|
| 2417 | - 'name' => 'update_default_event_settings', |
|
| 2418 | - 'html_id' => 'update_default_event_settings', |
|
| 2419 | - 'html_class' => 'form-table', |
|
| 2420 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2421 | - 'subsections' => apply_filters( |
|
| 2422 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2423 | - [ |
|
| 2424 | - 'default_reg_status' => new EE_Select_Input( |
|
| 2425 | - $registration_stati_for_selection, |
|
| 2426 | - [ |
|
| 2427 | - 'default' => isset($registration_config->default_STS_ID) |
|
| 2428 | - && array_key_exists( |
|
| 2429 | - $registration_config->default_STS_ID, |
|
| 2430 | - $registration_stati_for_selection |
|
| 2431 | - ) |
|
| 2432 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2433 | - : EEM_Registration::status_id_pending_payment, |
|
| 2434 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2435 | - . EEH_Template::get_help_tab_link( |
|
| 2436 | - 'default_settings_status_help_tab' |
|
| 2437 | - ), |
|
| 2438 | - 'html_help_text' => esc_html__( |
|
| 2439 | - '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.', |
|
| 2440 | - 'event_espresso' |
|
| 2441 | - ), |
|
| 2442 | - ] |
|
| 2443 | - ), |
|
| 2444 | - 'default_max_tickets' => new EE_Integer_Input( |
|
| 2445 | - [ |
|
| 2446 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2447 | - ? $registration_config->default_maximum_number_of_tickets |
|
| 2448 | - : EEM_Event::get_default_additional_limit(), |
|
| 2449 | - 'html_label_text' => esc_html__( |
|
| 2450 | - 'Default Maximum Tickets Allowed Per Order:', |
|
| 2451 | - 'event_espresso' |
|
| 2452 | - ) |
|
| 2453 | - . EEH_Template::get_help_tab_link( |
|
| 2454 | - 'default_maximum_tickets_help_tab"' |
|
| 2455 | - ), |
|
| 2456 | - 'html_help_text' => esc_html__( |
|
| 2457 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2458 | - 'event_espresso' |
|
| 2459 | - ), |
|
| 2460 | - ] |
|
| 2461 | - ), |
|
| 2462 | - ] |
|
| 2463 | - ), |
|
| 2464 | - ] |
|
| 2465 | - ); |
|
| 2466 | - } |
|
| 2467 | - |
|
| 2468 | - |
|
| 2469 | - /** |
|
| 2470 | - * _update_default_event_settings |
|
| 2471 | - * |
|
| 2472 | - * @access protected |
|
| 2473 | - * @return void |
|
| 2474 | - * @throws EE_Error |
|
| 2475 | - */ |
|
| 2476 | - protected function _update_default_event_settings() |
|
| 2477 | - { |
|
| 2478 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2479 | - $form = $this->_default_event_settings_form(); |
|
| 2480 | - if ($form->was_submitted()) { |
|
| 2481 | - $form->receive_form_submission(); |
|
| 2482 | - if ($form->is_valid()) { |
|
| 2483 | - $valid_data = $form->valid_data(); |
|
| 2484 | - if (isset($valid_data['default_reg_status'])) { |
|
| 2485 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2486 | - } |
|
| 2487 | - if (isset($valid_data['default_max_tickets'])) { |
|
| 2488 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2489 | - } |
|
| 2490 | - // update because data was valid! |
|
| 2491 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2492 | - EE_Error::overwrite_success(); |
|
| 2493 | - EE_Error::add_success( |
|
| 2494 | - esc_html__('Default Event Settings were updated', 'event_espresso') |
|
| 2495 | - ); |
|
| 2496 | - } |
|
| 2497 | - } |
|
| 2498 | - $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2499 | - } |
|
| 2500 | - |
|
| 2501 | - |
|
| 2502 | - /************* Templates ************* |
|
| 2503 | - * |
|
| 2504 | - * @throws EE_Error |
|
| 2505 | - */ |
|
| 2506 | - protected function _template_settings() |
|
| 2507 | - { |
|
| 2508 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2509 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2510 | - . EVENTS_ASSETS_URL |
|
| 2511 | - . '/images/' |
|
| 2512 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2513 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2514 | - . '" />'; |
|
| 2515 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 2516 | - . esc_html__( |
|
| 2517 | - '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.', |
|
| 2518 | - 'event_espresso' |
|
| 2519 | - ) . '</strong>'; |
|
| 2520 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2521 | - } |
|
| 2522 | - |
|
| 2523 | - |
|
| 2524 | - /** Event Category Stuff **/ |
|
| 2525 | - /** |
|
| 2526 | - * set the _category property with the category object for the loaded page. |
|
| 2527 | - * |
|
| 2528 | - * @access private |
|
| 2529 | - * @return void |
|
| 2530 | - */ |
|
| 2531 | - private function _set_category_object() |
|
| 2532 | - { |
|
| 2533 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2534 | - return; |
|
| 2535 | - } //already have the category object so get out. |
|
| 2536 | - // set default category object |
|
| 2537 | - $this->_set_empty_category_object(); |
|
| 2538 | - // only set if we've got an id |
|
| 2539 | - $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 2540 | - if (! $category_ID) { |
|
| 2541 | - return; |
|
| 2542 | - } |
|
| 2543 | - $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2544 | - if (! empty($term)) { |
|
| 2545 | - $this->_category->category_name = $term->name; |
|
| 2546 | - $this->_category->category_identifier = $term->slug; |
|
| 2547 | - $this->_category->category_desc = $term->description; |
|
| 2548 | - $this->_category->id = $term->term_id; |
|
| 2549 | - $this->_category->parent = $term->parent; |
|
| 2550 | - } |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - |
|
| 2554 | - /** |
|
| 2555 | - * Clears out category properties. |
|
| 2556 | - */ |
|
| 2557 | - private function _set_empty_category_object() |
|
| 2558 | - { |
|
| 2559 | - $this->_category = new stdClass(); |
|
| 2560 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2561 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2562 | - } |
|
| 2563 | - |
|
| 2564 | - |
|
| 2565 | - /** |
|
| 2566 | - * @throws EE_Error |
|
| 2567 | - */ |
|
| 2568 | - protected function _category_list_table() |
|
| 2569 | - { |
|
| 2570 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2571 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2572 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2573 | - 'add_category', |
|
| 2574 | - 'add_category', |
|
| 2575 | - [], |
|
| 2576 | - 'add-new-h2' |
|
| 2577 | - ); |
|
| 2578 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2579 | - } |
|
| 2580 | - |
|
| 2581 | - |
|
| 2582 | - /** |
|
| 2583 | - * Output category details view. |
|
| 2584 | - * |
|
| 2585 | - * @throws EE_Error |
|
| 2586 | - * @throws EE_Error |
|
| 2587 | - */ |
|
| 2588 | - protected function _category_details($view) |
|
| 2589 | - { |
|
| 2590 | - // load formatter helper |
|
| 2591 | - // load field generator helper |
|
| 2592 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2593 | - $this->_set_add_edit_form_tags($route); |
|
| 2594 | - $this->_set_category_object(); |
|
| 2595 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2596 | - $delete_action = 'delete_category'; |
|
| 2597 | - // custom redirect |
|
| 2598 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2599 | - ['action' => 'category_list'], |
|
| 2600 | - $this->_admin_base_url |
|
| 2601 | - ); |
|
| 2602 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2603 | - // take care of contents |
|
| 2604 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2605 | - $this->display_admin_page_with_sidebar(); |
|
| 2606 | - } |
|
| 2607 | - |
|
| 2608 | - |
|
| 2609 | - /** |
|
| 2610 | - * Output category details content. |
|
| 2611 | - */ |
|
| 2612 | - protected function _category_details_content() |
|
| 2613 | - { |
|
| 2614 | - $editor_args['category_desc'] = [ |
|
| 2615 | - 'type' => 'wp_editor', |
|
| 2616 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2617 | - 'class' => 'my_editor_custom', |
|
| 2618 | - 'wpeditor_args' => ['media_buttons' => false], |
|
| 2619 | - ]; |
|
| 2620 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2621 | - $all_terms = get_terms( |
|
| 2622 | - [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2623 | - ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2624 | - ); |
|
| 2625 | - // setup category select for term parents. |
|
| 2626 | - $category_select_values[] = [ |
|
| 2627 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2628 | - 'id' => 0, |
|
| 2629 | - ]; |
|
| 2630 | - foreach ($all_terms as $term) { |
|
| 2631 | - $category_select_values[] = [ |
|
| 2632 | - 'text' => $term->name, |
|
| 2633 | - 'id' => $term->term_id, |
|
| 2634 | - ]; |
|
| 2635 | - } |
|
| 2636 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2637 | - 'category_parent', |
|
| 2638 | - $category_select_values, |
|
| 2639 | - $this->_category->parent |
|
| 2640 | - ); |
|
| 2641 | - $template_args = [ |
|
| 2642 | - 'category' => $this->_category, |
|
| 2643 | - 'category_select' => $category_select, |
|
| 2644 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2645 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2646 | - 'disable' => '', |
|
| 2647 | - 'disabled_message' => false, |
|
| 2648 | - ]; |
|
| 2649 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2650 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2651 | - } |
|
| 2652 | - |
|
| 2653 | - |
|
| 2654 | - /** |
|
| 2655 | - * Handles deleting categories. |
|
| 2656 | - * |
|
| 2657 | - * @throws EE_Error |
|
| 2658 | - */ |
|
| 2659 | - protected function _delete_categories() |
|
| 2660 | - { |
|
| 2661 | - $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
| 2662 | - foreach ($category_IDs as $category_ID) { |
|
| 2663 | - $this->_delete_category($category_ID); |
|
| 2664 | - } |
|
| 2665 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2666 | - $query_args = [ |
|
| 2667 | - 'action' => 'category_list', |
|
| 2668 | - ]; |
|
| 2669 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2670 | - } |
|
| 2671 | - |
|
| 2672 | - |
|
| 2673 | - /** |
|
| 2674 | - * Handles deleting specific category. |
|
| 2675 | - * |
|
| 2676 | - * @param int $cat_id |
|
| 2677 | - */ |
|
| 2678 | - protected function _delete_category($cat_id) |
|
| 2679 | - { |
|
| 2680 | - $cat_id = absint($cat_id); |
|
| 2681 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2682 | - } |
|
| 2683 | - |
|
| 2684 | - |
|
| 2685 | - /** |
|
| 2686 | - * Handles triggering the update or insertion of a new category. |
|
| 2687 | - * |
|
| 2688 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2689 | - * @throws EE_Error |
|
| 2690 | - * @throws EE_Error |
|
| 2691 | - */ |
|
| 2692 | - protected function _insert_or_update_category($new_category) |
|
| 2693 | - { |
|
| 2694 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2695 | - $success = 0; // we already have a success message so lets not send another. |
|
| 2696 | - if ($cat_id) { |
|
| 2697 | - $query_args = [ |
|
| 2698 | - 'action' => 'edit_category', |
|
| 2699 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2700 | - ]; |
|
| 2701 | - } else { |
|
| 2702 | - $query_args = ['action' => 'add_category']; |
|
| 2703 | - } |
|
| 2704 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2705 | - } |
|
| 2706 | - |
|
| 2707 | - |
|
| 2708 | - /** |
|
| 2709 | - * Inserts or updates category |
|
| 2710 | - * |
|
| 2711 | - * @param bool $update (true indicates we're updating a category). |
|
| 2712 | - * @return bool|mixed|string |
|
| 2713 | - */ |
|
| 2714 | - private function _insert_category($update = false) |
|
| 2715 | - { |
|
| 2716 | - $category_ID = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0; |
|
| 2717 | - $category_name = $this->request->getRequestParam('category_name', ''); |
|
| 2718 | - $category_desc = $this->request->getRequestParam('category_desc', ''); |
|
| 2719 | - $category_parent = $this->request->getRequestParam('category_parent', 0, 'int'); |
|
| 2720 | - $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
| 2721 | - |
|
| 2722 | - if (empty($category_name)) { |
|
| 2723 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2724 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2725 | - return false; |
|
| 2726 | - } |
|
| 2727 | - $term_args = [ |
|
| 2728 | - 'name' => $category_name, |
|
| 2729 | - 'description' => $category_desc, |
|
| 2730 | - 'parent' => $category_parent, |
|
| 2731 | - ]; |
|
| 2732 | - // was the category_identifier input disabled? |
|
| 2733 | - if ($category_identifier) { |
|
| 2734 | - $term_args['slug'] = $category_identifier; |
|
| 2735 | - } |
|
| 2736 | - $insert_ids = $update |
|
| 2737 | - ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2738 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2739 | - if (! is_array($insert_ids)) { |
|
| 2740 | - $msg = esc_html__( |
|
| 2741 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2742 | - 'event_espresso' |
|
| 2743 | - ); |
|
| 2744 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2745 | - } else { |
|
| 2746 | - $category_ID = $insert_ids['term_id']; |
|
| 2747 | - $msg = |
|
| 2748 | - sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2749 | - EE_Error::add_success($msg); |
|
| 2750 | - } |
|
| 2751 | - return $category_ID; |
|
| 2752 | - } |
|
| 2753 | - |
|
| 2754 | - |
|
| 2755 | - /** |
|
| 2756 | - * Gets categories or count of categories matching the arguments in the request. |
|
| 2757 | - * |
|
| 2758 | - * @param int $per_page |
|
| 2759 | - * @param int $current_page |
|
| 2760 | - * @param bool $count |
|
| 2761 | - * @return EE_Term_Taxonomy[]|int |
|
| 2762 | - * @throws EE_Error |
|
| 2763 | - * @throws EE_Error |
|
| 2764 | - */ |
|
| 2765 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2766 | - { |
|
| 2767 | - // testing term stuff |
|
| 2768 | - $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
| 2769 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 2770 | - $limit = ($current_page - 1) * $per_page; |
|
| 2771 | - $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2772 | - $search_term = $this->request->getRequestParam('s'); |
|
| 2773 | - if ($search_term) { |
|
| 2774 | - $search_term = '%' . $search_term . '%'; |
|
| 2775 | - $where['OR'] = [ |
|
| 2776 | - 'Term.name' => ['LIKE', $search_term], |
|
| 2777 | - 'description' => ['LIKE', $search_term], |
|
| 2778 | - ]; |
|
| 2779 | - } |
|
| 2780 | - $query_params = [ |
|
| 2781 | - $where, |
|
| 2782 | - 'order_by' => [$orderby => $order], |
|
| 2783 | - 'limit' => $limit . ',' . $per_page, |
|
| 2784 | - 'force_join' => ['Term'], |
|
| 2785 | - ]; |
|
| 2786 | - return $count |
|
| 2787 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2788 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2789 | - } |
|
| 2790 | - |
|
| 2791 | - /* end category stuff */ |
|
| 2792 | - /**************/ |
|
| 2793 | - |
|
| 2794 | - |
|
| 2795 | - /** |
|
| 2796 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2797 | - * |
|
| 2798 | - * @throws EE_Error |
|
| 2799 | - */ |
|
| 2800 | - public function saveTimezoneString() |
|
| 2801 | - { |
|
| 2802 | - $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
| 2803 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2804 | - EE_Error::add_error( |
|
| 2805 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2806 | - __FILE__, |
|
| 2807 | - __FUNCTION__, |
|
| 2808 | - __LINE__ |
|
| 2809 | - ); |
|
| 2810 | - $this->_template_args['error'] = true; |
|
| 2811 | - $this->_return_json(); |
|
| 2812 | - } |
|
| 2813 | - |
|
| 2814 | - update_option('timezone_string', $timezone_string); |
|
| 2815 | - EE_Error::add_success( |
|
| 2816 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2817 | - ); |
|
| 2818 | - $this->_template_args['success'] = true; |
|
| 2819 | - $this->_return_json(true, ['action' => 'create_new']); |
|
| 2820 | - } |
|
| 2821 | - |
|
| 2822 | - |
|
| 2823 | - /** |
|
| 2824 | 2504 | * @throws EE_Error |
| 2825 | - * @deprecated $VID:$ |
|
| 2826 | 2505 | */ |
| 2827 | - public function save_timezonestring_setting() |
|
| 2828 | - { |
|
| 2829 | - $this->saveTimezoneString(); |
|
| 2830 | - } |
|
| 2506 | + protected function _template_settings() |
|
| 2507 | + { |
|
| 2508 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2509 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2510 | + . EVENTS_ASSETS_URL |
|
| 2511 | + . '/images/' |
|
| 2512 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2513 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2514 | + . '" />'; |
|
| 2515 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 2516 | + . esc_html__( |
|
| 2517 | + '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.', |
|
| 2518 | + 'event_espresso' |
|
| 2519 | + ) . '</strong>'; |
|
| 2520 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2521 | + } |
|
| 2522 | + |
|
| 2523 | + |
|
| 2524 | + /** Event Category Stuff **/ |
|
| 2525 | + /** |
|
| 2526 | + * set the _category property with the category object for the loaded page. |
|
| 2527 | + * |
|
| 2528 | + * @access private |
|
| 2529 | + * @return void |
|
| 2530 | + */ |
|
| 2531 | + private function _set_category_object() |
|
| 2532 | + { |
|
| 2533 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2534 | + return; |
|
| 2535 | + } //already have the category object so get out. |
|
| 2536 | + // set default category object |
|
| 2537 | + $this->_set_empty_category_object(); |
|
| 2538 | + // only set if we've got an id |
|
| 2539 | + $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
|
| 2540 | + if (! $category_ID) { |
|
| 2541 | + return; |
|
| 2542 | + } |
|
| 2543 | + $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2544 | + if (! empty($term)) { |
|
| 2545 | + $this->_category->category_name = $term->name; |
|
| 2546 | + $this->_category->category_identifier = $term->slug; |
|
| 2547 | + $this->_category->category_desc = $term->description; |
|
| 2548 | + $this->_category->id = $term->term_id; |
|
| 2549 | + $this->_category->parent = $term->parent; |
|
| 2550 | + } |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + |
|
| 2554 | + /** |
|
| 2555 | + * Clears out category properties. |
|
| 2556 | + */ |
|
| 2557 | + private function _set_empty_category_object() |
|
| 2558 | + { |
|
| 2559 | + $this->_category = new stdClass(); |
|
| 2560 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2561 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2562 | + } |
|
| 2563 | + |
|
| 2564 | + |
|
| 2565 | + /** |
|
| 2566 | + * @throws EE_Error |
|
| 2567 | + */ |
|
| 2568 | + protected function _category_list_table() |
|
| 2569 | + { |
|
| 2570 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2571 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2572 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2573 | + 'add_category', |
|
| 2574 | + 'add_category', |
|
| 2575 | + [], |
|
| 2576 | + 'add-new-h2' |
|
| 2577 | + ); |
|
| 2578 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2579 | + } |
|
| 2580 | + |
|
| 2581 | + |
|
| 2582 | + /** |
|
| 2583 | + * Output category details view. |
|
| 2584 | + * |
|
| 2585 | + * @throws EE_Error |
|
| 2586 | + * @throws EE_Error |
|
| 2587 | + */ |
|
| 2588 | + protected function _category_details($view) |
|
| 2589 | + { |
|
| 2590 | + // load formatter helper |
|
| 2591 | + // load field generator helper |
|
| 2592 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2593 | + $this->_set_add_edit_form_tags($route); |
|
| 2594 | + $this->_set_category_object(); |
|
| 2595 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2596 | + $delete_action = 'delete_category'; |
|
| 2597 | + // custom redirect |
|
| 2598 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2599 | + ['action' => 'category_list'], |
|
| 2600 | + $this->_admin_base_url |
|
| 2601 | + ); |
|
| 2602 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2603 | + // take care of contents |
|
| 2604 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2605 | + $this->display_admin_page_with_sidebar(); |
|
| 2606 | + } |
|
| 2607 | + |
|
| 2608 | + |
|
| 2609 | + /** |
|
| 2610 | + * Output category details content. |
|
| 2611 | + */ |
|
| 2612 | + protected function _category_details_content() |
|
| 2613 | + { |
|
| 2614 | + $editor_args['category_desc'] = [ |
|
| 2615 | + 'type' => 'wp_editor', |
|
| 2616 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2617 | + 'class' => 'my_editor_custom', |
|
| 2618 | + 'wpeditor_args' => ['media_buttons' => false], |
|
| 2619 | + ]; |
|
| 2620 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2621 | + $all_terms = get_terms( |
|
| 2622 | + [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2623 | + ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2624 | + ); |
|
| 2625 | + // setup category select for term parents. |
|
| 2626 | + $category_select_values[] = [ |
|
| 2627 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2628 | + 'id' => 0, |
|
| 2629 | + ]; |
|
| 2630 | + foreach ($all_terms as $term) { |
|
| 2631 | + $category_select_values[] = [ |
|
| 2632 | + 'text' => $term->name, |
|
| 2633 | + 'id' => $term->term_id, |
|
| 2634 | + ]; |
|
| 2635 | + } |
|
| 2636 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2637 | + 'category_parent', |
|
| 2638 | + $category_select_values, |
|
| 2639 | + $this->_category->parent |
|
| 2640 | + ); |
|
| 2641 | + $template_args = [ |
|
| 2642 | + 'category' => $this->_category, |
|
| 2643 | + 'category_select' => $category_select, |
|
| 2644 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2645 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2646 | + 'disable' => '', |
|
| 2647 | + 'disabled_message' => false, |
|
| 2648 | + ]; |
|
| 2649 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2650 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2651 | + } |
|
| 2652 | + |
|
| 2653 | + |
|
| 2654 | + /** |
|
| 2655 | + * Handles deleting categories. |
|
| 2656 | + * |
|
| 2657 | + * @throws EE_Error |
|
| 2658 | + */ |
|
| 2659 | + protected function _delete_categories() |
|
| 2660 | + { |
|
| 2661 | + $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
| 2662 | + foreach ($category_IDs as $category_ID) { |
|
| 2663 | + $this->_delete_category($category_ID); |
|
| 2664 | + } |
|
| 2665 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2666 | + $query_args = [ |
|
| 2667 | + 'action' => 'category_list', |
|
| 2668 | + ]; |
|
| 2669 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2670 | + } |
|
| 2671 | + |
|
| 2672 | + |
|
| 2673 | + /** |
|
| 2674 | + * Handles deleting specific category. |
|
| 2675 | + * |
|
| 2676 | + * @param int $cat_id |
|
| 2677 | + */ |
|
| 2678 | + protected function _delete_category($cat_id) |
|
| 2679 | + { |
|
| 2680 | + $cat_id = absint($cat_id); |
|
| 2681 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2682 | + } |
|
| 2683 | + |
|
| 2684 | + |
|
| 2685 | + /** |
|
| 2686 | + * Handles triggering the update or insertion of a new category. |
|
| 2687 | + * |
|
| 2688 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2689 | + * @throws EE_Error |
|
| 2690 | + * @throws EE_Error |
|
| 2691 | + */ |
|
| 2692 | + protected function _insert_or_update_category($new_category) |
|
| 2693 | + { |
|
| 2694 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2695 | + $success = 0; // we already have a success message so lets not send another. |
|
| 2696 | + if ($cat_id) { |
|
| 2697 | + $query_args = [ |
|
| 2698 | + 'action' => 'edit_category', |
|
| 2699 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2700 | + ]; |
|
| 2701 | + } else { |
|
| 2702 | + $query_args = ['action' => 'add_category']; |
|
| 2703 | + } |
|
| 2704 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2705 | + } |
|
| 2706 | + |
|
| 2707 | + |
|
| 2708 | + /** |
|
| 2709 | + * Inserts or updates category |
|
| 2710 | + * |
|
| 2711 | + * @param bool $update (true indicates we're updating a category). |
|
| 2712 | + * @return bool|mixed|string |
|
| 2713 | + */ |
|
| 2714 | + private function _insert_category($update = false) |
|
| 2715 | + { |
|
| 2716 | + $category_ID = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0; |
|
| 2717 | + $category_name = $this->request->getRequestParam('category_name', ''); |
|
| 2718 | + $category_desc = $this->request->getRequestParam('category_desc', ''); |
|
| 2719 | + $category_parent = $this->request->getRequestParam('category_parent', 0, 'int'); |
|
| 2720 | + $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
| 2721 | + |
|
| 2722 | + if (empty($category_name)) { |
|
| 2723 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2724 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2725 | + return false; |
|
| 2726 | + } |
|
| 2727 | + $term_args = [ |
|
| 2728 | + 'name' => $category_name, |
|
| 2729 | + 'description' => $category_desc, |
|
| 2730 | + 'parent' => $category_parent, |
|
| 2731 | + ]; |
|
| 2732 | + // was the category_identifier input disabled? |
|
| 2733 | + if ($category_identifier) { |
|
| 2734 | + $term_args['slug'] = $category_identifier; |
|
| 2735 | + } |
|
| 2736 | + $insert_ids = $update |
|
| 2737 | + ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2738 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2739 | + if (! is_array($insert_ids)) { |
|
| 2740 | + $msg = esc_html__( |
|
| 2741 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2742 | + 'event_espresso' |
|
| 2743 | + ); |
|
| 2744 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2745 | + } else { |
|
| 2746 | + $category_ID = $insert_ids['term_id']; |
|
| 2747 | + $msg = |
|
| 2748 | + sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2749 | + EE_Error::add_success($msg); |
|
| 2750 | + } |
|
| 2751 | + return $category_ID; |
|
| 2752 | + } |
|
| 2753 | + |
|
| 2754 | + |
|
| 2755 | + /** |
|
| 2756 | + * Gets categories or count of categories matching the arguments in the request. |
|
| 2757 | + * |
|
| 2758 | + * @param int $per_page |
|
| 2759 | + * @param int $current_page |
|
| 2760 | + * @param bool $count |
|
| 2761 | + * @return EE_Term_Taxonomy[]|int |
|
| 2762 | + * @throws EE_Error |
|
| 2763 | + * @throws EE_Error |
|
| 2764 | + */ |
|
| 2765 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2766 | + { |
|
| 2767 | + // testing term stuff |
|
| 2768 | + $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
| 2769 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
| 2770 | + $limit = ($current_page - 1) * $per_page; |
|
| 2771 | + $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2772 | + $search_term = $this->request->getRequestParam('s'); |
|
| 2773 | + if ($search_term) { |
|
| 2774 | + $search_term = '%' . $search_term . '%'; |
|
| 2775 | + $where['OR'] = [ |
|
| 2776 | + 'Term.name' => ['LIKE', $search_term], |
|
| 2777 | + 'description' => ['LIKE', $search_term], |
|
| 2778 | + ]; |
|
| 2779 | + } |
|
| 2780 | + $query_params = [ |
|
| 2781 | + $where, |
|
| 2782 | + 'order_by' => [$orderby => $order], |
|
| 2783 | + 'limit' => $limit . ',' . $per_page, |
|
| 2784 | + 'force_join' => ['Term'], |
|
| 2785 | + ]; |
|
| 2786 | + return $count |
|
| 2787 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2788 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2789 | + } |
|
| 2790 | + |
|
| 2791 | + /* end category stuff */ |
|
| 2792 | + /**************/ |
|
| 2793 | + |
|
| 2794 | + |
|
| 2795 | + /** |
|
| 2796 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2797 | + * |
|
| 2798 | + * @throws EE_Error |
|
| 2799 | + */ |
|
| 2800 | + public function saveTimezoneString() |
|
| 2801 | + { |
|
| 2802 | + $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
| 2803 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2804 | + EE_Error::add_error( |
|
| 2805 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2806 | + __FILE__, |
|
| 2807 | + __FUNCTION__, |
|
| 2808 | + __LINE__ |
|
| 2809 | + ); |
|
| 2810 | + $this->_template_args['error'] = true; |
|
| 2811 | + $this->_return_json(); |
|
| 2812 | + } |
|
| 2813 | + |
|
| 2814 | + update_option('timezone_string', $timezone_string); |
|
| 2815 | + EE_Error::add_success( |
|
| 2816 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2817 | + ); |
|
| 2818 | + $this->_template_args['success'] = true; |
|
| 2819 | + $this->_return_json(true, ['action' => 'create_new']); |
|
| 2820 | + } |
|
| 2821 | + |
|
| 2822 | + |
|
| 2823 | + /** |
|
| 2824 | + * @throws EE_Error |
|
| 2825 | + * @deprecated $VID:$ |
|
| 2826 | + */ |
|
| 2827 | + public function save_timezonestring_setting() |
|
| 2828 | + { |
|
| 2829 | + $this->saveTimezoneString(); |
|
| 2830 | + } |
|
| 2831 | 2831 | } |
@@ -582,11 +582,11 @@ discard block |
||
| 582 | 582 | { |
| 583 | 583 | wp_register_style( |
| 584 | 584 | 'events-admin-css', |
| 585 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 585 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 586 | 586 | [], |
| 587 | 587 | EVENT_ESPRESSO_VERSION |
| 588 | 588 | ); |
| 589 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION); |
|
| 589 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION); |
|
| 590 | 590 | wp_enqueue_style('events-admin-css'); |
| 591 | 591 | wp_enqueue_style('ee-cat-admin'); |
| 592 | 592 | // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | // scripts |
| 595 | 595 | wp_register_script( |
| 596 | 596 | 'event_editor_js', |
| 597 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 597 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 598 | 598 | ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
| 599 | 599 | EVENT_ESPRESSO_VERSION, |
| 600 | 600 | true |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | wp_enqueue_style('espresso-ui-theme'); |
| 621 | 621 | wp_register_style( |
| 622 | 622 | 'event-editor-css', |
| 623 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 623 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 624 | 624 | ['ee-admin-css'], |
| 625 | 625 | EVENT_ESPRESSO_VERSION |
| 626 | 626 | ); |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | // scripts |
| 629 | 629 | wp_register_script( |
| 630 | 630 | 'event-datetime-metabox', |
| 631 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 631 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 632 | 632 | ['event_editor_js', 'ee-datepicker'], |
| 633 | 633 | EVENT_ESPRESSO_VERSION |
| 634 | 634 | ); |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | public function verify_event_edit($event = null, $req_type = '') |
| 698 | 698 | { |
| 699 | 699 | // don't need to do this when processing |
| 700 | - if (! empty($req_type)) { |
|
| 700 | + if ( ! empty($req_type)) { |
|
| 701 | 701 | return; |
| 702 | 702 | } |
| 703 | 703 | // no event? |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | $event = $this->_cpt_model_obj; |
| 707 | 707 | } |
| 708 | 708 | // STILL no event? |
| 709 | - if (! $event instanceof EE_Event) { |
|
| 709 | + if ( ! $event instanceof EE_Event) { |
|
| 710 | 710 | return; |
| 711 | 711 | } |
| 712 | 712 | $orig_status = $event->status(); |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | ); |
| 746 | 746 | } |
| 747 | 747 | // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
| 748 | - if (! $event->tickets_on_sale()) { |
|
| 748 | + if ( ! $event->tickets_on_sale()) { |
|
| 749 | 749 | return; |
| 750 | 750 | } |
| 751 | 751 | // made it here so show warning |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | { |
| 791 | 791 | $has_timezone_string = get_option('timezone_string'); |
| 792 | 792 | // only nag them about setting their timezone if it's their first event, and they haven't already done it |
| 793 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 793 | + if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 794 | 794 | EE_Error::add_attention( |
| 795 | 795 | sprintf( |
| 796 | 796 | esc_html__( |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | */ |
| 860 | 860 | protected function _event_legend_items() |
| 861 | 861 | { |
| 862 | - $items = [ |
|
| 862 | + $items = [ |
|
| 863 | 863 | 'view_details' => [ |
| 864 | 864 | 'class' => 'dashicons dashicons-search', |
| 865 | 865 | 'desc' => esc_html__('View Event', 'event_espresso'), |
@@ -876,31 +876,31 @@ discard block |
||
| 876 | 876 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 877 | 877 | $statuses = [ |
| 878 | 878 | 'sold_out_status' => [ |
| 879 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 879 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
| 880 | 880 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 881 | 881 | ], |
| 882 | 882 | 'active_status' => [ |
| 883 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 883 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
| 884 | 884 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 885 | 885 | ], |
| 886 | 886 | 'upcoming_status' => [ |
| 887 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 887 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
| 888 | 888 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 889 | 889 | ], |
| 890 | 890 | 'postponed_status' => [ |
| 891 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 891 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
| 892 | 892 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 893 | 893 | ], |
| 894 | 894 | 'cancelled_status' => [ |
| 895 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 895 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
| 896 | 896 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 897 | 897 | ], |
| 898 | 898 | 'expired_status' => [ |
| 899 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 899 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
| 900 | 900 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 901 | 901 | ], |
| 902 | 902 | 'inactive_status' => [ |
| 903 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 903 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
| 904 | 904 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 905 | 905 | ], |
| 906 | 906 | ]; |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | */ |
| 917 | 917 | private function _event_model() |
| 918 | 918 | { |
| 919 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 919 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 920 | 920 | $this->_event_model = EE_Registry::instance()->load_model('Event'); |
| 921 | 921 | } |
| 922 | 922 | return $this->_event_model; |
@@ -936,8 +936,8 @@ discard block |
||
| 936 | 936 | public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
| 937 | 937 | { |
| 938 | 938 | // make sure this is only when editing |
| 939 | - if (! empty($id)) { |
|
| 940 | - $post = get_post($id); |
|
| 939 | + if ( ! empty($id)) { |
|
| 940 | + $post = get_post($id); |
|
| 941 | 941 | $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
| 942 | 942 | . esc_html__('Shortcode', 'event_espresso') |
| 943 | 943 | . '</a> '; |
@@ -960,7 +960,7 @@ discard block |
||
| 960 | 960 | protected function _events_overview_list_table() |
| 961 | 961 | { |
| 962 | 962 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 963 | - $this->_template_args['after_list_table'] = |
|
| 963 | + $this->_template_args['after_list_table'] = |
|
| 964 | 964 | ! empty($this->_template_args['after_list_table']) |
| 965 | 965 | ? (array) $this->_template_args['after_list_table'] |
| 966 | 966 | : []; |
@@ -970,10 +970,10 @@ discard block |
||
| 970 | 970 | esc_html__("View Event Archive Page", "event_espresso"), |
| 971 | 971 | 'button' |
| 972 | 972 | ); |
| 973 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend( |
|
| 973 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend( |
|
| 974 | 974 | $this->_event_legend_items() |
| 975 | 975 | ); |
| 976 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 976 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 977 | 977 | 'create_new', |
| 978 | 978 | 'add', |
| 979 | 979 | [], |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | [$this, '_default_tickets_update'], |
| 1070 | 1070 | ] |
| 1071 | 1071 | ); |
| 1072 | - $att_success = true; |
|
| 1072 | + $att_success = true; |
|
| 1073 | 1073 | foreach ($event_update_callbacks as $e_callback) { |
| 1074 | 1074 | $_success = is_callable($e_callback) |
| 1075 | 1075 | ? call_user_func($e_callback, $event, $this->request->requestParams()) |
@@ -1131,7 +1131,7 @@ discard block |
||
| 1131 | 1131 | */ |
| 1132 | 1132 | protected function _default_venue_update(EE_Event $event, $data) |
| 1133 | 1133 | { |
| 1134 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1134 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1135 | 1135 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
| 1136 | 1136 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
| 1137 | 1137 | // very important. If we don't have a venue name... |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | 'status' => 'publish', |
| 1163 | 1163 | ]; |
| 1164 | 1164 | // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
| 1165 | - if (! empty($venue_id)) { |
|
| 1165 | + if ( ! empty($venue_id)) { |
|
| 1166 | 1166 | $update_where = [$venue_model->primary_key_name() => $venue_id]; |
| 1167 | 1167 | $rows_affected = $venue_model->update($venue_array, [$update_where]); |
| 1168 | 1168 | // 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. |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
| 1201 | 1201 | ? $datetime_data['DTT_EVT_end'] |
| 1202 | 1202 | : $datetime_data['DTT_EVT_start']; |
| 1203 | - $datetime_values = [ |
|
| 1203 | + $datetime_values = [ |
|
| 1204 | 1204 | 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
| 1205 | 1205 | 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
| 1206 | 1206 | 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
@@ -1209,9 +1209,9 @@ discard block |
||
| 1209 | 1209 | ]; |
| 1210 | 1210 | // if we have an id then let's get existing object first and then set the new values. |
| 1211 | 1211 | // Otherwise we instantiate a new object for save. |
| 1212 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 1212 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
| 1213 | 1213 | $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
| 1214 | - if (! $datetime instanceof EE_Ticket) { |
|
| 1214 | + if ( ! $datetime instanceof EE_Ticket) { |
|
| 1215 | 1215 | throw new RuntimeException( |
| 1216 | 1216 | sprintf( |
| 1217 | 1217 | esc_html__( |
@@ -1230,7 +1230,7 @@ discard block |
||
| 1230 | 1230 | } else { |
| 1231 | 1231 | $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
| 1232 | 1232 | } |
| 1233 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1233 | + if ( ! $datetime instanceof EE_Datetime) { |
|
| 1234 | 1234 | throw new RuntimeException( |
| 1235 | 1235 | sprintf( |
| 1236 | 1236 | esc_html__( |
@@ -1256,7 +1256,7 @@ discard block |
||
| 1256 | 1256 | |
| 1257 | 1257 | // set up some default start and end dates in case those are not present in the incoming data |
| 1258 | 1258 | $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
| 1259 | - $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
| 1259 | + $default_start_date = $default_start_date->format($date_formats[0].' '.$date_formats[1]); |
|
| 1260 | 1260 | // use the start date of the first datetime for the end date |
| 1261 | 1261 | $first_datetime = $event->first_datetime(); |
| 1262 | 1262 | $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
@@ -1264,8 +1264,8 @@ discard block |
||
| 1264 | 1264 | // now process the incoming data |
| 1265 | 1265 | foreach ($data['edit_tickets'] as $row => $ticket_data) { |
| 1266 | 1266 | $update_prices = false; |
| 1267 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1268 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1267 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1268 | + ? $data['edit_prices'][$row][1]['PRC_amount'] |
|
| 1269 | 1269 | : 0; |
| 1270 | 1270 | // trim inputs to ensure any excess whitespace is removed. |
| 1271 | 1271 | $ticket_data = array_map('trim', $ticket_data); |
@@ -1306,9 +1306,9 @@ discard block |
||
| 1306 | 1306 | // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
| 1307 | 1307 | // keep in mind that if the ticket has been sold (and we have changed pricing information), |
| 1308 | 1308 | // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
| 1309 | - if (! empty($ticket_data['TKT_ID'])) { |
|
| 1309 | + if ( ! empty($ticket_data['TKT_ID'])) { |
|
| 1310 | 1310 | $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
| 1311 | - if (! $existing_ticket instanceof EE_Ticket) { |
|
| 1311 | + if ( ! $existing_ticket instanceof EE_Ticket) { |
|
| 1312 | 1312 | throw new RuntimeException( |
| 1313 | 1313 | sprintf( |
| 1314 | 1314 | esc_html__( |
@@ -1357,7 +1357,7 @@ discard block |
||
| 1357 | 1357 | $existing_ticket->save(); |
| 1358 | 1358 | // make sure this ticket is still recorded in our $saved_tickets |
| 1359 | 1359 | // so we don't run it through the regular trash routine. |
| 1360 | - $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
| 1360 | + $saved_tickets[$existing_ticket->ID()] = $existing_ticket; |
|
| 1361 | 1361 | // create new ticket that's a copy of the existing except, |
| 1362 | 1362 | // (a new id of course and not archived) AND has the new TKT_price associated with it. |
| 1363 | 1363 | $new_ticket = clone $existing_ticket; |
@@ -1374,7 +1374,7 @@ discard block |
||
| 1374 | 1374 | $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
| 1375 | 1375 | $update_prices = true; |
| 1376 | 1376 | } |
| 1377 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1377 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1378 | 1378 | throw new RuntimeException( |
| 1379 | 1379 | sprintf( |
| 1380 | 1380 | esc_html__( |
@@ -1398,9 +1398,9 @@ discard block |
||
| 1398 | 1398 | } |
| 1399 | 1399 | // initially let's add the ticket to the datetime |
| 1400 | 1400 | $datetime->_add_relation_to($ticket, 'Ticket'); |
| 1401 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 1401 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
| 1402 | 1402 | // add prices to ticket |
| 1403 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices); |
|
| 1403 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $ticket, $update_prices); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | // however now we need to handle permanently deleting tickets via the ui. |
| 1406 | 1406 | // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
@@ -1412,7 +1412,7 @@ discard block |
||
| 1412 | 1412 | $id = absint($id); |
| 1413 | 1413 | // get the ticket for this id |
| 1414 | 1414 | $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
| 1415 | - if (! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1415 | + if ( ! $ticket_to_remove instanceof EE_Ticket) { |
|
| 1416 | 1416 | continue; |
| 1417 | 1417 | } |
| 1418 | 1418 | // need to get all the related datetimes on this ticket and remove from every single one of them |
@@ -1469,7 +1469,7 @@ discard block |
||
| 1469 | 1469 | $price->set($field, $new_price); |
| 1470 | 1470 | } |
| 1471 | 1471 | } |
| 1472 | - if (! $price instanceof EE_Price) { |
|
| 1472 | + if ( ! $price instanceof EE_Price) { |
|
| 1473 | 1473 | throw new RuntimeException( |
| 1474 | 1474 | sprintf( |
| 1475 | 1475 | esc_html__( |
@@ -1512,13 +1512,13 @@ discard block |
||
| 1512 | 1512 | { |
| 1513 | 1513 | // load formatter helper |
| 1514 | 1514 | // args for getting related registrations |
| 1515 | - $approved_query_args = [ |
|
| 1515 | + $approved_query_args = [ |
|
| 1516 | 1516 | [ |
| 1517 | 1517 | 'REG_deleted' => 0, |
| 1518 | 1518 | 'STS_ID' => EEM_Registration::status_id_approved, |
| 1519 | 1519 | ], |
| 1520 | 1520 | ]; |
| 1521 | - $not_approved_query_args = [ |
|
| 1521 | + $not_approved_query_args = [ |
|
| 1522 | 1522 | [ |
| 1523 | 1523 | 'REG_deleted' => 0, |
| 1524 | 1524 | 'STS_ID' => EEM_Registration::status_id_not_approved, |
@@ -1581,7 +1581,7 @@ discard block |
||
| 1581 | 1581 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1582 | 1582 | // load template |
| 1583 | 1583 | EEH_Template::display_template( |
| 1584 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1584 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1585 | 1585 | $publish_box_extra_args |
| 1586 | 1586 | ); |
| 1587 | 1587 | } |
@@ -1653,7 +1653,7 @@ discard block |
||
| 1653 | 1653 | 'trash_icon' => 'ee-lock-icon', |
| 1654 | 1654 | 'disabled' => '', |
| 1655 | 1655 | ]; |
| 1656 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1656 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1657 | 1657 | /** |
| 1658 | 1658 | * 1. Start with retrieving Datetimes |
| 1659 | 1659 | * 2. Fore each datetime get related tickets |
@@ -1674,18 +1674,18 @@ discard block |
||
| 1674 | 1674 | 'default_where_conditions' => 'none', |
| 1675 | 1675 | ] |
| 1676 | 1676 | ); |
| 1677 | - if (! empty($related_tickets)) { |
|
| 1677 | + if ( ! empty($related_tickets)) { |
|
| 1678 | 1678 | $template_args['total_ticket_rows'] = count($related_tickets); |
| 1679 | 1679 | $row = 0; |
| 1680 | 1680 | foreach ($related_tickets as $ticket) { |
| 1681 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1681 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1682 | 1682 | $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
| 1683 | 1683 | $row++; |
| 1684 | 1684 | } |
| 1685 | 1685 | } else { |
| 1686 | 1686 | $template_args['total_ticket_rows'] = 1; |
| 1687 | 1687 | /** @type EE_Ticket $ticket */ |
| 1688 | - $ticket = EEM_Ticket::instance()->create_default_object(); |
|
| 1688 | + $ticket = EEM_Ticket::instance()->create_default_object(); |
|
| 1689 | 1689 | $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
| 1690 | 1690 | } |
| 1691 | 1691 | } else { |
@@ -1705,9 +1705,9 @@ discard block |
||
| 1705 | 1705 | EEM_Ticket::instance()->create_default_object(), |
| 1706 | 1706 | true |
| 1707 | 1707 | ); |
| 1708 | - $template = apply_filters( |
|
| 1708 | + $template = apply_filters( |
|
| 1709 | 1709 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1710 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1710 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1711 | 1711 | ); |
| 1712 | 1712 | EEH_Template::display_template($template, $template_args); |
| 1713 | 1713 | } |
@@ -1727,7 +1727,7 @@ discard block |
||
| 1727 | 1727 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1728 | 1728 | { |
| 1729 | 1729 | $template_args = [ |
| 1730 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1730 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1731 | 1731 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1732 | 1732 | : '', |
| 1733 | 1733 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1739,10 +1739,10 @@ discard block |
||
| 1739 | 1739 | 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
| 1740 | 1740 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
| 1741 | 1741 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
| 1742 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1743 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1742 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1743 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1744 | 1744 | ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
| 1745 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1745 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1746 | 1746 | : ' disabled=disabled', |
| 1747 | 1747 | ]; |
| 1748 | 1748 | $price = $ticket->ID() !== 0 |
@@ -1766,7 +1766,7 @@ discard block |
||
| 1766 | 1766 | } |
| 1767 | 1767 | if (empty($template_args['TKT_end_date'])) { |
| 1768 | 1768 | // get the earliest datetime (if present); |
| 1769 | - $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1769 | + $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
| 1770 | 1770 | ? $this->_cpt_model_obj->get_first_related( |
| 1771 | 1771 | 'Datetime', |
| 1772 | 1772 | ['order_by' => ['DTT_EVT_start' => 'ASC']] |
@@ -1779,7 +1779,7 @@ discard block |
||
| 1779 | 1779 | $template_args = array_merge($template_args, $price_args); |
| 1780 | 1780 | $template = apply_filters( |
| 1781 | 1781 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1782 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1782 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1783 | 1783 | $ticket |
| 1784 | 1784 | ); |
| 1785 | 1785 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1792,7 +1792,7 @@ discard block |
||
| 1792 | 1792 | */ |
| 1793 | 1793 | public function registration_options_meta_box() |
| 1794 | 1794 | { |
| 1795 | - $yes_no_values = [ |
|
| 1795 | + $yes_no_values = [ |
|
| 1796 | 1796 | ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
| 1797 | 1797 | ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
| 1798 | 1798 | ]; |
@@ -1814,12 +1814,12 @@ discard block |
||
| 1814 | 1814 | $default_reg_status_values, |
| 1815 | 1815 | $this->_cpt_model_obj->default_registration_status() |
| 1816 | 1816 | ); |
| 1817 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1817 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1818 | 1818 | 'display_desc', |
| 1819 | 1819 | $yes_no_values, |
| 1820 | 1820 | $this->_cpt_model_obj->display_description() |
| 1821 | 1821 | ); |
| 1822 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1822 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1823 | 1823 | 'display_ticket_selector', |
| 1824 | 1824 | $yes_no_values, |
| 1825 | 1825 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -1835,7 +1835,7 @@ discard block |
||
| 1835 | 1835 | $default_reg_status_values |
| 1836 | 1836 | ); |
| 1837 | 1837 | EEH_Template::display_template( |
| 1838 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1838 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1839 | 1839 | $template_args |
| 1840 | 1840 | ); |
| 1841 | 1841 | } |
@@ -1858,7 +1858,7 @@ discard block |
||
| 1858 | 1858 | { |
| 1859 | 1859 | $EEM_Event = $this->_event_model(); |
| 1860 | 1860 | $offset = ($current_page - 1) * $per_page; |
| 1861 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1861 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1862 | 1862 | $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
| 1863 | 1863 | $order = $this->request->getRequestParam('order', 'DESC'); |
| 1864 | 1864 | $month_range = $this->request->getRequestParam('month_range'); |
@@ -1895,10 +1895,10 @@ discard block |
||
| 1895 | 1895 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1896 | 1896 | if ($month_range) { |
| 1897 | 1897 | $DateTime = new DateTime( |
| 1898 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1898 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1899 | 1899 | new DateTimeZone('UTC') |
| 1900 | 1900 | ); |
| 1901 | - $start = $DateTime->getTimestamp(); |
|
| 1901 | + $start = $DateTime->getTimestamp(); |
|
| 1902 | 1902 | // set the datetime to be the end of the month |
| 1903 | 1903 | $DateTime->setDate( |
| 1904 | 1904 | $year_r, |
@@ -1923,11 +1923,11 @@ discard block |
||
| 1923 | 1923 | ->format(implode(' ', $start_formats)); |
| 1924 | 1924 | $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
| 1925 | 1925 | } |
| 1926 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1926 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1927 | 1927 | $where['EVT_wp_user'] = get_current_user_id(); |
| 1928 | 1928 | } else { |
| 1929 | - if (! isset($where['status'])) { |
|
| 1930 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1929 | + if ( ! isset($where['status'])) { |
|
| 1930 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1931 | 1931 | $where['OR'] = [ |
| 1932 | 1932 | 'status*restrict_private' => ['!=', 'private'], |
| 1933 | 1933 | 'AND' => [ |
@@ -1949,7 +1949,7 @@ discard block |
||
| 1949 | 1949 | // search query handling |
| 1950 | 1950 | $search_term = $this->request->getRequestParam('s'); |
| 1951 | 1951 | if ($search_term) { |
| 1952 | - $search_term = '%' . $search_term . '%'; |
|
| 1952 | + $search_term = '%'.$search_term.'%'; |
|
| 1953 | 1953 | $where['OR'] = [ |
| 1954 | 1954 | 'EVT_name' => ['LIKE', $search_term], |
| 1955 | 1955 | 'EVT_desc' => ['LIKE', $search_term], |
@@ -2057,7 +2057,7 @@ discard block |
||
| 2057 | 2057 | // clean status |
| 2058 | 2058 | $event_status = sanitize_key($event_status); |
| 2059 | 2059 | // grab status |
| 2060 | - if (! empty($event_status)) { |
|
| 2060 | + if ( ! empty($event_status)) { |
|
| 2061 | 2061 | $success = $this->_change_event_status($EVT_ID, $event_status); |
| 2062 | 2062 | } else { |
| 2063 | 2063 | $success = false; |
@@ -2097,7 +2097,7 @@ discard block |
||
| 2097 | 2097 | // clean status |
| 2098 | 2098 | $event_status = sanitize_key($event_status); |
| 2099 | 2099 | // grab status |
| 2100 | - if (! empty($event_status)) { |
|
| 2100 | + if ( ! empty($event_status)) { |
|
| 2101 | 2101 | $success = true; |
| 2102 | 2102 | // determine the event id and set to array. |
| 2103 | 2103 | $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
@@ -2143,7 +2143,7 @@ discard block |
||
| 2143 | 2143 | private function _change_event_status($EVT_ID = 0, $event_status = '') |
| 2144 | 2144 | { |
| 2145 | 2145 | // grab event id |
| 2146 | - if (! $EVT_ID) { |
|
| 2146 | + if ( ! $EVT_ID) { |
|
| 2147 | 2147 | $msg = esc_html__( |
| 2148 | 2148 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
| 2149 | 2149 | 'event_espresso' |
@@ -2180,7 +2180,7 @@ discard block |
||
| 2180 | 2180 | // use class to change status |
| 2181 | 2181 | $this->_cpt_model_obj->set_status($event_status); |
| 2182 | 2182 | $success = $this->_cpt_model_obj->save(); |
| 2183 | - if (! $success) { |
|
| 2183 | + if ( ! $success) { |
|
| 2184 | 2184 | $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
| 2185 | 2185 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
| 2186 | 2186 | return false; |
@@ -2234,7 +2234,7 @@ discard block |
||
| 2234 | 2234 | */ |
| 2235 | 2235 | protected function getModelObjNodeGroupPersister() |
| 2236 | 2236 | { |
| 2237 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2237 | + if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2238 | 2238 | $this->model_obj_node_group_persister = |
| 2239 | 2239 | $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
| 2240 | 2240 | } |
@@ -2516,7 +2516,7 @@ discard block |
||
| 2516 | 2516 | . esc_html__( |
| 2517 | 2517 | '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.', |
| 2518 | 2518 | 'event_espresso' |
| 2519 | - ) . '</strong>'; |
|
| 2519 | + ).'</strong>'; |
|
| 2520 | 2520 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2521 | 2521 | } |
| 2522 | 2522 | |
@@ -2537,11 +2537,11 @@ discard block |
||
| 2537 | 2537 | $this->_set_empty_category_object(); |
| 2538 | 2538 | // only set if we've got an id |
| 2539 | 2539 | $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int'); |
| 2540 | - if (! $category_ID) { |
|
| 2540 | + if ( ! $category_ID) { |
|
| 2541 | 2541 | return; |
| 2542 | 2542 | } |
| 2543 | 2543 | $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
| 2544 | - if (! empty($term)) { |
|
| 2544 | + if ( ! empty($term)) { |
|
| 2545 | 2545 | $this->_category->category_name = $term->name; |
| 2546 | 2546 | $this->_category->category_identifier = $term->slug; |
| 2547 | 2547 | $this->_category->category_desc = $term->description; |
@@ -2569,7 +2569,7 @@ discard block |
||
| 2569 | 2569 | { |
| 2570 | 2570 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2571 | 2571 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
| 2572 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2572 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 2573 | 2573 | 'add_category', |
| 2574 | 2574 | 'add_category', |
| 2575 | 2575 | [], |
@@ -2638,7 +2638,7 @@ discard block |
||
| 2638 | 2638 | $category_select_values, |
| 2639 | 2639 | $this->_category->parent |
| 2640 | 2640 | ); |
| 2641 | - $template_args = [ |
|
| 2641 | + $template_args = [ |
|
| 2642 | 2642 | 'category' => $this->_category, |
| 2643 | 2643 | 'category_select' => $category_select, |
| 2644 | 2644 | 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
@@ -2646,7 +2646,7 @@ discard block |
||
| 2646 | 2646 | 'disable' => '', |
| 2647 | 2647 | 'disabled_message' => false, |
| 2648 | 2648 | ]; |
| 2649 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2649 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2650 | 2650 | return EEH_Template::display_template($template, $template_args, true); |
| 2651 | 2651 | } |
| 2652 | 2652 | |
@@ -2736,7 +2736,7 @@ discard block |
||
| 2736 | 2736 | $insert_ids = $update |
| 2737 | 2737 | ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
| 2738 | 2738 | : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
| 2739 | - if (! is_array($insert_ids)) { |
|
| 2739 | + if ( ! is_array($insert_ids)) { |
|
| 2740 | 2740 | $msg = esc_html__( |
| 2741 | 2741 | 'An error occurred and the category has not been saved to the database.', |
| 2742 | 2742 | 'event_espresso' |
@@ -2771,7 +2771,7 @@ discard block |
||
| 2771 | 2771 | $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
| 2772 | 2772 | $search_term = $this->request->getRequestParam('s'); |
| 2773 | 2773 | if ($search_term) { |
| 2774 | - $search_term = '%' . $search_term . '%'; |
|
| 2774 | + $search_term = '%'.$search_term.'%'; |
|
| 2775 | 2775 | $where['OR'] = [ |
| 2776 | 2776 | 'Term.name' => ['LIKE', $search_term], |
| 2777 | 2777 | 'description' => ['LIKE', $search_term], |
@@ -2780,7 +2780,7 @@ discard block |
||
| 2780 | 2780 | $query_params = [ |
| 2781 | 2781 | $where, |
| 2782 | 2782 | 'order_by' => [$orderby => $order], |
| 2783 | - 'limit' => $limit . ',' . $per_page, |
|
| 2783 | + 'limit' => $limit.','.$per_page, |
|
| 2784 | 2784 | 'force_join' => ['Term'], |
| 2785 | 2785 | ]; |
| 2786 | 2786 | return $count |
@@ -14,1803 +14,1803 @@ |
||
| 14 | 14 | class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not. |
|
| 19 | - */ |
|
| 20 | - const sold_out = 'TKS'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - */ |
|
| 25 | - const expired = 'TKE'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - */ |
|
| 30 | - const archived = 'TKA'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * |
|
| 34 | - */ |
|
| 35 | - const pending = 'TKP'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * |
|
| 39 | - */ |
|
| 40 | - const onsale = 'TKO'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * extra meta key for tracking ticket reservations |
|
| 44 | - * |
|
| 45 | - * @type string |
|
| 46 | - */ |
|
| 47 | - const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * cached result from method of the same name |
|
| 51 | - * |
|
| 52 | - * @var float $_ticket_total_with_taxes |
|
| 53 | - */ |
|
| 54 | - private $_ticket_total_with_taxes; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param array $props_n_values incoming values |
|
| 59 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | - * used.) |
|
| 61 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | - * date_format and the second value is the time format |
|
| 63 | - * @return EE_Ticket |
|
| 64 | - * @throws EE_Error |
|
| 65 | - * @throws ReflectionException |
|
| 66 | - */ |
|
| 67 | - public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
| 68 | - { |
|
| 69 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 70 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param array $props_n_values incoming values from the database |
|
| 76 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 77 | - * the website will be used. |
|
| 78 | - * @return EE_Ticket |
|
| 79 | - * @throws EE_Error |
|
| 80 | - * @throws ReflectionException |
|
| 81 | - */ |
|
| 82 | - public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
| 83 | - { |
|
| 84 | - return new self($props_n_values, true, $timezone); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return bool |
|
| 90 | - * @throws EE_Error |
|
| 91 | - * @throws ReflectionException |
|
| 92 | - */ |
|
| 93 | - public function parent() |
|
| 94 | - { |
|
| 95 | - return $this->get('TKT_parent'); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * return if a ticket has quantities available for purchase |
|
| 101 | - * |
|
| 102 | - * @param int $DTT_ID the primary key for a particular datetime |
|
| 103 | - * @return boolean |
|
| 104 | - * @throws EE_Error |
|
| 105 | - * @throws ReflectionException |
|
| 106 | - */ |
|
| 107 | - public function available($DTT_ID = 0) |
|
| 108 | - { |
|
| 109 | - // are we checking availability for a particular datetime ? |
|
| 110 | - if ($DTT_ID) { |
|
| 111 | - // get that datetime object |
|
| 112 | - $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]); |
|
| 113 | - // if ticket sales for this datetime have exceeded the reg limit... |
|
| 114 | - if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 115 | - return false; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - // datetime is still open for registration, but is this ticket sold out ? |
|
| 119 | - return $this->qty() < 1 || $this->qty() > $this->sold() ? true : false; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 125 | - * |
|
| 126 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
| 127 | - * relevant status const |
|
| 128 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
| 129 | - * further processing |
|
| 130 | - * @return mixed status int if the display string isn't requested |
|
| 131 | - * @throws EE_Error |
|
| 132 | - * @throws ReflectionException |
|
| 133 | - */ |
|
| 134 | - public function ticket_status($display = false, $remaining = null) |
|
| 135 | - { |
|
| 136 | - $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 137 | - if (! $remaining) { |
|
| 138 | - return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
| 139 | - } |
|
| 140 | - if ($this->get('TKT_deleted')) { |
|
| 141 | - return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
| 142 | - } |
|
| 143 | - if ($this->is_expired()) { |
|
| 144 | - return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
| 145 | - } |
|
| 146 | - if ($this->is_pending()) { |
|
| 147 | - return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
| 148 | - } |
|
| 149 | - if ($this->is_on_sale()) { |
|
| 150 | - return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
| 151 | - } |
|
| 152 | - return ''; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
| 158 | - * considering ALL the factors used for figuring that out. |
|
| 159 | - * |
|
| 160 | - * @access public |
|
| 161 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 162 | - * @return boolean true = tickets remaining, false not. |
|
| 163 | - * @throws EE_Error |
|
| 164 | - */ |
|
| 165 | - public function is_remaining($DTT_ID = 0) |
|
| 166 | - { |
|
| 167 | - $num_remaining = $this->remaining($DTT_ID); |
|
| 168 | - if ($num_remaining === 0) { |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - return true; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * return the total number of tickets available for purchase |
|
| 180 | - * |
|
| 181 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 182 | - * set to 0 for all related datetimes |
|
| 183 | - * @return int |
|
| 184 | - * @throws EE_Error |
|
| 185 | - */ |
|
| 186 | - public function remaining($DTT_ID = 0) |
|
| 187 | - { |
|
| 188 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Gets min |
|
| 194 | - * |
|
| 195 | - * @return int |
|
| 196 | - * @throws EE_Error |
|
| 197 | - * @throws ReflectionException |
|
| 198 | - */ |
|
| 199 | - public function min() |
|
| 200 | - { |
|
| 201 | - return $this->get('TKT_min'); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * return if a ticket is no longer available cause its available dates have expired. |
|
| 207 | - * |
|
| 208 | - * @return boolean |
|
| 209 | - * @throws EE_Error |
|
| 210 | - * @throws ReflectionException |
|
| 211 | - */ |
|
| 212 | - public function is_expired() |
|
| 213 | - { |
|
| 214 | - return ($this->get_raw('TKT_end_date') < time()); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Return if a ticket is yet to go on sale or not |
|
| 220 | - * |
|
| 221 | - * @return boolean |
|
| 222 | - * @throws EE_Error |
|
| 223 | - * @throws ReflectionException |
|
| 224 | - */ |
|
| 225 | - public function is_pending() |
|
| 226 | - { |
|
| 227 | - return ($this->get_raw('TKT_start_date') > time()); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Return if a ticket is on sale or not |
|
| 233 | - * |
|
| 234 | - * @return boolean |
|
| 235 | - * @throws EE_Error |
|
| 236 | - * @throws ReflectionException |
|
| 237 | - */ |
|
| 238 | - public function is_on_sale() |
|
| 239 | - { |
|
| 240 | - return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 246 | - * |
|
| 247 | - * @param string $dt_frmt |
|
| 248 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
| 249 | - * the end date ie: Jan 01 "to" Dec 31 |
|
| 250 | - * @return string |
|
| 251 | - * @throws EE_Error |
|
| 252 | - * @throws ReflectionException |
|
| 253 | - */ |
|
| 254 | - public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 255 | - { |
|
| 256 | - $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
| 257 | - $first_date = $this->first_datetime() instanceof EE_Datetime |
|
| 258 | - ? $this->first_datetime()->get_i18n_datetime( |
|
| 259 | - 'DTT_EVT_start', |
|
| 260 | - $dt_frmt |
|
| 261 | - ) : ''; |
|
| 262 | - $last_date = |
|
| 263 | - $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->get_i18n_datetime( |
|
| 264 | - 'DTT_EVT_end', |
|
| 265 | - $dt_frmt |
|
| 266 | - ) : ''; |
|
| 267 | - |
|
| 268 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * This returns the chronologically first datetime that this ticket is associated with |
|
| 274 | - * |
|
| 275 | - * @return EE_Datetime |
|
| 276 | - * @throws EE_Error |
|
| 277 | - */ |
|
| 278 | - public function first_datetime() |
|
| 279 | - { |
|
| 280 | - $datetimes = $this->datetimes(['limit' => 1]); |
|
| 281 | - return reset($datetimes); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Gets all the datetimes this ticket can be used for attending. |
|
| 287 | - * Unless otherwise specified, orders datetimes by start date. |
|
| 288 | - * |
|
| 289 | - * @param array $query_params @see |
|
| 290 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 291 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
| 292 | - * @throws EE_Error |
|
| 293 | - * @throws ReflectionException |
|
| 294 | - */ |
|
| 295 | - public function datetimes($query_params = []) |
|
| 296 | - { |
|
| 297 | - if (! isset($query_params['order_by'])) { |
|
| 298 | - $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 299 | - } |
|
| 300 | - return $this->get_many_related('Datetime', $query_params); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 306 | - * |
|
| 307 | - * @return EE_Datetime |
|
| 308 | - * @throws EE_Error |
|
| 309 | - */ |
|
| 310 | - public function last_datetime() |
|
| 311 | - { |
|
| 312 | - $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]); |
|
| 313 | - return end($datetimes); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * This returns the total tickets sold depending on the given parameters. |
|
| 319 | - * |
|
| 320 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 321 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 322 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 323 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 324 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 325 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 326 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 327 | - * @return mixed (array|int) how many tickets have sold |
|
| 328 | - * @throws EE_Error |
|
| 329 | - */ |
|
| 330 | - public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
| 331 | - { |
|
| 332 | - $total = 0; |
|
| 333 | - $tickets_sold = $this->_all_tickets_sold(); |
|
| 334 | - switch ($what) { |
|
| 335 | - case 'ticket': |
|
| 336 | - return $tickets_sold['ticket']; |
|
| 337 | - break; |
|
| 338 | - case 'datetime': |
|
| 339 | - if (empty($tickets_sold['datetime'])) { |
|
| 340 | - return $total; |
|
| 341 | - } |
|
| 342 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 343 | - EE_Error::add_error( |
|
| 344 | - esc_html__( |
|
| 345 | - 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
| 346 | - 'event_espresso' |
|
| 347 | - ), |
|
| 348 | - __FILE__, |
|
| 349 | - __FUNCTION__, |
|
| 350 | - __LINE__ |
|
| 351 | - ); |
|
| 352 | - return $total; |
|
| 353 | - } |
|
| 354 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 355 | - break; |
|
| 356 | - default: |
|
| 357 | - return $total; |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 364 | - * |
|
| 365 | - * @return EE_Ticket[] |
|
| 366 | - * @throws EE_Error |
|
| 367 | - * @throws ReflectionException |
|
| 368 | - */ |
|
| 369 | - protected function _all_tickets_sold() |
|
| 370 | - { |
|
| 371 | - $datetimes = $this->get_many_related('Datetime'); |
|
| 372 | - $tickets_sold = []; |
|
| 373 | - if (! empty($datetimes)) { |
|
| 374 | - foreach ($datetimes as $datetime) { |
|
| 375 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - // Tickets sold |
|
| 379 | - $tickets_sold['ticket'] = $this->sold(); |
|
| 380 | - return $tickets_sold; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * This returns the base price object for the ticket. |
|
| 386 | - * |
|
| 387 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 388 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 389 | - * @throws EE_Error |
|
| 390 | - * @throws ReflectionException |
|
| 391 | - */ |
|
| 392 | - public function base_price($return_array = false) |
|
| 393 | - { |
|
| 394 | - $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price]; |
|
| 395 | - return $return_array |
|
| 396 | - ? $this->get_many_related('Price', [$_where]) |
|
| 397 | - : $this->get_first_related('Price', [$_where]); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 403 | - * |
|
| 404 | - * @access public |
|
| 405 | - * @return EE_Price[] |
|
| 406 | - * @throws EE_Error |
|
| 407 | - */ |
|
| 408 | - public function price_modifiers() |
|
| 409 | - { |
|
| 410 | - $query_params = [ |
|
| 411 | - 0 => [ |
|
| 412 | - 'Price_Type.PBT_ID' => [ |
|
| 413 | - 'NOT IN', |
|
| 414 | - [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax], |
|
| 415 | - ], |
|
| 416 | - ], |
|
| 417 | - ]; |
|
| 418 | - return $this->prices($query_params); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Gets all the prices that combine to form the final price of this ticket |
|
| 424 | - * |
|
| 425 | - * @param array $query_params @see |
|
| 426 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 427 | - * @return EE_Price[]|EE_Base_Class[] |
|
| 428 | - * @throws EE_Error |
|
| 429 | - * @throws ReflectionException |
|
| 430 | - */ |
|
| 431 | - public function prices($query_params = []) |
|
| 432 | - { |
|
| 433 | - return $this->get_many_related('Price', $query_params); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 439 | - * |
|
| 440 | - * @param array $query_params @see |
|
| 441 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 442 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 443 | - * @throws EE_Error |
|
| 444 | - * @throws ReflectionException |
|
| 445 | - */ |
|
| 446 | - public function datetime_tickets($query_params = []) |
|
| 447 | - { |
|
| 448 | - return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Gets all the datetimes from the db ordered by DTT_order |
|
| 454 | - * |
|
| 455 | - * @param boolean $show_expired |
|
| 456 | - * @param boolean $show_deleted |
|
| 457 | - * @return EE_Datetime[] |
|
| 458 | - * @throws EE_Error |
|
| 459 | - */ |
|
| 460 | - public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
| 461 | - { |
|
| 462 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 463 | - $this->ID(), |
|
| 464 | - $show_expired, |
|
| 465 | - $show_deleted |
|
| 466 | - ); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Gets ID |
|
| 472 | - * |
|
| 473 | - * @return int |
|
| 474 | - * @throws EE_Error |
|
| 475 | - * @throws ReflectionException |
|
| 476 | - */ |
|
| 477 | - public function ID() |
|
| 478 | - { |
|
| 479 | - return (int) $this->get('TKT_ID'); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * get the author of the ticket. |
|
| 485 | - * |
|
| 486 | - * @return int |
|
| 487 | - * @throws EE_Error |
|
| 488 | - * @throws ReflectionException |
|
| 489 | - * @since 4.5.0 |
|
| 490 | - */ |
|
| 491 | - public function wp_user() |
|
| 492 | - { |
|
| 493 | - return $this->get('TKT_wp_user'); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Gets the template for the ticket |
|
| 499 | - * |
|
| 500 | - * @return EE_Ticket_Template|EE_Base_Class |
|
| 501 | - * @throws EE_Error |
|
| 502 | - * @throws ReflectionException |
|
| 503 | - */ |
|
| 504 | - public function template() |
|
| 505 | - { |
|
| 506 | - return $this->get_first_related('Ticket_Template'); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Simply returns an array of EE_Price objects that are taxes. |
|
| 512 | - * |
|
| 513 | - * @return EE_Price[] |
|
| 514 | - * @throws EE_Error |
|
| 515 | - */ |
|
| 516 | - public function get_ticket_taxes_for_admin() |
|
| 517 | - { |
|
| 518 | - return EE_Taxes::get_taxes_for_admin(); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * @return float |
|
| 524 | - * @throws EE_Error |
|
| 525 | - * @throws ReflectionException |
|
| 526 | - */ |
|
| 527 | - public function ticket_price() |
|
| 528 | - { |
|
| 529 | - return $this->get('TKT_price'); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * @return mixed |
|
| 535 | - * @throws EE_Error |
|
| 536 | - * @throws ReflectionException |
|
| 537 | - */ |
|
| 538 | - public function pretty_price() |
|
| 539 | - { |
|
| 540 | - return $this->get_pretty('TKT_price'); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * @return bool |
|
| 546 | - * @throws EE_Error |
|
| 547 | - */ |
|
| 548 | - public function is_free() |
|
| 549 | - { |
|
| 550 | - return $this->get_ticket_total_with_taxes() === (float) 0; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * get_ticket_total_with_taxes |
|
| 556 | - * |
|
| 557 | - * @param bool $no_cache |
|
| 558 | - * @return float |
|
| 559 | - * @throws EE_Error |
|
| 560 | - */ |
|
| 561 | - public function get_ticket_total_with_taxes($no_cache = false) |
|
| 562 | - { |
|
| 563 | - if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 564 | - $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
| 565 | - } |
|
| 566 | - return (float) $this->_ticket_total_with_taxes; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - public function ensure_TKT_Price_correct() |
|
| 571 | - { |
|
| 572 | - $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 573 | - $this->save(); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @return float |
|
| 579 | - * @throws EE_Error |
|
| 580 | - */ |
|
| 581 | - public function get_ticket_subtotal() |
|
| 582 | - { |
|
| 583 | - return EE_Taxes::get_subtotal_for_admin($this); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Returns the total taxes applied to this ticket |
|
| 589 | - * |
|
| 590 | - * @return float |
|
| 591 | - * @throws EE_Error |
|
| 592 | - */ |
|
| 593 | - public function get_ticket_taxes_total_for_admin() |
|
| 594 | - { |
|
| 595 | - return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * Sets name |
|
| 601 | - * |
|
| 602 | - * @param string $name |
|
| 603 | - * @throws EE_Error |
|
| 604 | - * @throws ReflectionException |
|
| 605 | - */ |
|
| 606 | - public function set_name($name) |
|
| 607 | - { |
|
| 608 | - $this->set('TKT_name', $name); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * Gets description |
|
| 614 | - * |
|
| 615 | - * @return string |
|
| 616 | - * @throws EE_Error |
|
| 617 | - * @throws ReflectionException |
|
| 618 | - */ |
|
| 619 | - public function description() |
|
| 620 | - { |
|
| 621 | - return $this->get('TKT_description'); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * Sets description |
|
| 627 | - * |
|
| 628 | - * @param string $description |
|
| 629 | - * @throws EE_Error |
|
| 630 | - * @throws ReflectionException |
|
| 631 | - */ |
|
| 632 | - public function set_description($description) |
|
| 633 | - { |
|
| 634 | - $this->set('TKT_description', $description); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * Gets start_date |
|
| 640 | - * |
|
| 641 | - * @param string $dt_frmt |
|
| 642 | - * @param string $tm_frmt |
|
| 643 | - * @return string |
|
| 644 | - * @throws EE_Error |
|
| 645 | - * @throws ReflectionException |
|
| 646 | - */ |
|
| 647 | - public function start_date($dt_frmt = '', $tm_frmt = '') |
|
| 648 | - { |
|
| 649 | - return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Sets start_date |
|
| 655 | - * |
|
| 656 | - * @param string $start_date |
|
| 657 | - * @return void |
|
| 658 | - * @throws EE_Error |
|
| 659 | - * @throws ReflectionException |
|
| 660 | - */ |
|
| 661 | - public function set_start_date($start_date) |
|
| 662 | - { |
|
| 663 | - $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Gets end_date |
|
| 669 | - * |
|
| 670 | - * @param string $dt_frmt |
|
| 671 | - * @param string $tm_frmt |
|
| 672 | - * @return string |
|
| 673 | - * @throws EE_Error |
|
| 674 | - * @throws ReflectionException |
|
| 675 | - */ |
|
| 676 | - public function end_date($dt_frmt = '', $tm_frmt = '') |
|
| 677 | - { |
|
| 678 | - return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * Sets end_date |
|
| 684 | - * |
|
| 685 | - * @param string $end_date |
|
| 686 | - * @return void |
|
| 687 | - * @throws EE_Error |
|
| 688 | - * @throws ReflectionException |
|
| 689 | - */ |
|
| 690 | - public function set_end_date($end_date) |
|
| 691 | - { |
|
| 692 | - $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Sets sell until time |
|
| 698 | - * |
|
| 699 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 700 | - * @throws EE_Error*@throws ReflectionException |
|
| 701 | - * @since 4.5.0 |
|
| 702 | - */ |
|
| 703 | - public function set_end_time($time) |
|
| 704 | - { |
|
| 705 | - $this->_set_time_for($time, 'TKT_end_date'); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Sets min |
|
| 711 | - * |
|
| 712 | - * @param int $min |
|
| 713 | - * @return void |
|
| 714 | - * @throws EE_Error |
|
| 715 | - * @throws ReflectionException |
|
| 716 | - */ |
|
| 717 | - public function set_min($min) |
|
| 718 | - { |
|
| 719 | - $this->set('TKT_min', $min); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * Gets max |
|
| 725 | - * |
|
| 726 | - * @return int |
|
| 727 | - * @throws EE_Error |
|
| 728 | - * @throws ReflectionException |
|
| 729 | - */ |
|
| 730 | - public function max() |
|
| 731 | - { |
|
| 732 | - return $this->get('TKT_max'); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Sets max |
|
| 738 | - * |
|
| 739 | - * @param int $max |
|
| 740 | - * @return void |
|
| 741 | - * @throws EE_Error |
|
| 742 | - * @throws ReflectionException |
|
| 743 | - */ |
|
| 744 | - public function set_max($max) |
|
| 745 | - { |
|
| 746 | - $this->set('TKT_max', $max); |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * Sets price |
|
| 752 | - * |
|
| 753 | - * @param float $price |
|
| 754 | - * @return void |
|
| 755 | - * @throws EE_Error |
|
| 756 | - * @throws ReflectionException |
|
| 757 | - */ |
|
| 758 | - public function set_price($price) |
|
| 759 | - { |
|
| 760 | - $this->set('TKT_price', $price); |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * Gets sold |
|
| 766 | - * |
|
| 767 | - * @return int |
|
| 768 | - * @throws EE_Error |
|
| 769 | - * @throws ReflectionException |
|
| 770 | - */ |
|
| 771 | - public function sold() |
|
| 772 | - { |
|
| 773 | - return $this->get_raw('TKT_sold'); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * Sets sold |
|
| 779 | - * |
|
| 780 | - * @param int $sold |
|
| 781 | - * @return void |
|
| 782 | - * @throws EE_Error |
|
| 783 | - * @throws ReflectionException |
|
| 784 | - */ |
|
| 785 | - public function set_sold($sold) |
|
| 786 | - { |
|
| 787 | - // sold can not go below zero |
|
| 788 | - $sold = max(0, $sold); |
|
| 789 | - $this->set('TKT_sold', $sold); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 795 | - * associated datetimes. |
|
| 796 | - * |
|
| 797 | - * @param int $qty |
|
| 798 | - * @return boolean |
|
| 799 | - * @throws EE_Error |
|
| 800 | - * @throws InvalidArgumentException |
|
| 801 | - * @throws InvalidDataTypeException |
|
| 802 | - * @throws InvalidInterfaceException |
|
| 803 | - * @throws ReflectionException |
|
| 804 | - * @since 4.9.80.p |
|
| 805 | - */ |
|
| 806 | - public function increaseSold($qty = 1) |
|
| 807 | - { |
|
| 808 | - $qty = absint($qty); |
|
| 809 | - // increment sold and decrement reserved datetime quantities simultaneously |
|
| 810 | - // don't worry about failures, because they must have already had a spot reserved |
|
| 811 | - $this->increaseSoldForDatetimes($qty); |
|
| 812 | - // Increment and decrement ticket quantities simultaneously |
|
| 813 | - $success = $this->adjustNumericFieldsInDb( |
|
| 814 | - [ |
|
| 815 | - 'TKT_reserved' => $qty * -1, |
|
| 816 | - 'TKT_sold' => $qty, |
|
| 817 | - ] |
|
| 818 | - ); |
|
| 819 | - do_action( |
|
| 820 | - 'AHEE__EE_Ticket__increase_sold', |
|
| 821 | - $this, |
|
| 822 | - $qty, |
|
| 823 | - $this->sold(), |
|
| 824 | - $success |
|
| 825 | - ); |
|
| 826 | - return $success; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 832 | - * |
|
| 833 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
|
| 834 | - * counts), Negative means to decreases old counts (and increase reserved counts). |
|
| 835 | - * @param EE_Datetime[] $datetimes |
|
| 836 | - * @throws EE_Error |
|
| 837 | - * @throws InvalidArgumentException |
|
| 838 | - * @throws InvalidDataTypeException |
|
| 839 | - * @throws InvalidInterfaceException |
|
| 840 | - * @throws ReflectionException |
|
| 841 | - * @since 4.9.80.p |
|
| 842 | - */ |
|
| 843 | - protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
| 844 | - { |
|
| 845 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 846 | - foreach ($datetimes as $datetime) { |
|
| 847 | - $datetime->increaseSold($qty); |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - |
|
| 852 | - /** |
|
| 853 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 854 | - * DB and then updates the model objects. |
|
| 855 | - * Does not affect the reserved counts. |
|
| 856 | - * |
|
| 857 | - * @param int $qty |
|
| 858 | - * @return boolean |
|
| 859 | - * @throws EE_Error |
|
| 860 | - * @throws InvalidArgumentException |
|
| 861 | - * @throws InvalidDataTypeException |
|
| 862 | - * @throws InvalidInterfaceException |
|
| 863 | - * @throws ReflectionException |
|
| 864 | - * @since 4.9.80.p |
|
| 865 | - */ |
|
| 866 | - public function decreaseSold($qty = 1) |
|
| 867 | - { |
|
| 868 | - $qty = absint($qty); |
|
| 869 | - $this->decreaseSoldForDatetimes($qty); |
|
| 870 | - $success = $this->adjustNumericFieldsInDb( |
|
| 871 | - [ |
|
| 872 | - 'TKT_sold' => $qty * -1, |
|
| 873 | - ] |
|
| 874 | - ); |
|
| 875 | - do_action( |
|
| 876 | - 'AHEE__EE_Ticket__decrease_sold', |
|
| 877 | - $this, |
|
| 878 | - $qty, |
|
| 879 | - $this->sold(), |
|
| 880 | - $success |
|
| 881 | - ); |
|
| 882 | - return $success; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * Decreases sold on related datetimes |
|
| 888 | - * |
|
| 889 | - * @param int $qty |
|
| 890 | - * @param EE_Datetime[] $datetimes |
|
| 891 | - * @return void |
|
| 892 | - * @throws EE_Error |
|
| 893 | - * @throws InvalidArgumentException |
|
| 894 | - * @throws InvalidDataTypeException |
|
| 895 | - * @throws InvalidInterfaceException |
|
| 896 | - * @throws ReflectionException |
|
| 897 | - * @since 4.9.80.p |
|
| 898 | - */ |
|
| 899 | - protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
| 900 | - { |
|
| 901 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 902 | - if (is_array($datetimes)) { |
|
| 903 | - foreach ($datetimes as $datetime) { |
|
| 904 | - if ($datetime instanceof EE_Datetime) { |
|
| 905 | - $datetime->decreaseSold($qty); |
|
| 906 | - } |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * Gets qty of reserved tickets |
|
| 914 | - * |
|
| 915 | - * @return int |
|
| 916 | - * @throws EE_Error |
|
| 917 | - * @throws ReflectionException |
|
| 918 | - */ |
|
| 919 | - public function reserved() |
|
| 920 | - { |
|
| 921 | - return $this->get_raw('TKT_reserved'); |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * Sets reserved |
|
| 927 | - * |
|
| 928 | - * @param int $reserved |
|
| 929 | - * @return void |
|
| 930 | - * @throws EE_Error |
|
| 931 | - * @throws ReflectionException |
|
| 932 | - */ |
|
| 933 | - public function set_reserved($reserved) |
|
| 934 | - { |
|
| 935 | - // reserved can not go below zero |
|
| 936 | - $reserved = max(0, (int) $reserved); |
|
| 937 | - $this->set('TKT_reserved', $reserved); |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - |
|
| 941 | - /** |
|
| 942 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 943 | - * |
|
| 944 | - * @param int $qty |
|
| 945 | - * @param string $source |
|
| 946 | - * @return bool whether we successfully reserved the ticket or not. |
|
| 947 | - * @throws EE_Error |
|
| 948 | - * @throws InvalidArgumentException |
|
| 949 | - * @throws ReflectionException |
|
| 950 | - * @throws InvalidDataTypeException |
|
| 951 | - * @throws InvalidInterfaceException |
|
| 952 | - * @since 4.9.80.p |
|
| 953 | - */ |
|
| 954 | - public function increaseReserved($qty = 1, $source = 'unknown') |
|
| 955 | - { |
|
| 956 | - $qty = absint($qty); |
|
| 957 | - do_action( |
|
| 958 | - 'AHEE__EE_Ticket__increase_reserved__begin', |
|
| 959 | - $this, |
|
| 960 | - $qty, |
|
| 961 | - $source |
|
| 962 | - ); |
|
| 963 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
| 964 | - $success = false; |
|
| 965 | - $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
| 966 | - if ($datetimes_adjusted_successfully) { |
|
| 967 | - $success = $this->incrementFieldConditionallyInDb( |
|
| 968 | - 'TKT_reserved', |
|
| 969 | - 'TKT_sold', |
|
| 970 | - 'TKT_qty', |
|
| 971 | - $qty |
|
| 972 | - ); |
|
| 973 | - if (! $success) { |
|
| 974 | - // The datetimes were successfully bumped, but not the |
|
| 975 | - // ticket. So we need to manually rollback the datetimes. |
|
| 976 | - $this->decreaseReservedForDatetimes($qty); |
|
| 977 | - } |
|
| 978 | - } |
|
| 979 | - do_action( |
|
| 980 | - 'AHEE__EE_Ticket__increase_reserved', |
|
| 981 | - $this, |
|
| 982 | - $qty, |
|
| 983 | - $this->reserved(), |
|
| 984 | - $success |
|
| 985 | - ); |
|
| 986 | - return $success; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * Increases reserved counts on related datetimes |
|
| 992 | - * |
|
| 993 | - * @param int $qty |
|
| 994 | - * @param EE_Datetime[] $datetimes |
|
| 995 | - * @return boolean indicating success |
|
| 996 | - * @throws EE_Error |
|
| 997 | - * @throws InvalidArgumentException |
|
| 998 | - * @throws InvalidDataTypeException |
|
| 999 | - * @throws InvalidInterfaceException |
|
| 1000 | - * @throws ReflectionException |
|
| 1001 | - * @since 4.9.80.p |
|
| 1002 | - */ |
|
| 1003 | - protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1004 | - { |
|
| 1005 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1006 | - $datetimes_updated = []; |
|
| 1007 | - $limit_exceeded = false; |
|
| 1008 | - if (is_array($datetimes)) { |
|
| 1009 | - foreach ($datetimes as $datetime) { |
|
| 1010 | - if ($datetime instanceof EE_Datetime) { |
|
| 1011 | - if ($datetime->increaseReserved($qty)) { |
|
| 1012 | - $datetimes_updated[] = $datetime; |
|
| 1013 | - } else { |
|
| 1014 | - $limit_exceeded = true; |
|
| 1015 | - break; |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - // If somewhere along the way we detected a datetime whose |
|
| 1020 | - // limit was exceeded, do a manual rollback. |
|
| 1021 | - if ($limit_exceeded) { |
|
| 1022 | - $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
| 1023 | - return false; |
|
| 1024 | - } |
|
| 1025 | - } |
|
| 1026 | - return true; |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1032 | - * |
|
| 1033 | - * @param int $qty |
|
| 1034 | - * @param bool $adjust_datetimes |
|
| 1035 | - * @param string $source |
|
| 1036 | - * @return boolean |
|
| 1037 | - * @throws EE_Error |
|
| 1038 | - * @throws InvalidArgumentException |
|
| 1039 | - * @throws ReflectionException |
|
| 1040 | - * @throws InvalidDataTypeException |
|
| 1041 | - * @throws InvalidInterfaceException |
|
| 1042 | - * @since 4.9.80.p |
|
| 1043 | - */ |
|
| 1044 | - public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1045 | - { |
|
| 1046 | - $qty = absint($qty); |
|
| 1047 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
| 1048 | - if ($adjust_datetimes) { |
|
| 1049 | - $this->decreaseReservedForDatetimes($qty); |
|
| 1050 | - } |
|
| 1051 | - $success = $this->adjustNumericFieldsInDb( |
|
| 1052 | - [ |
|
| 1053 | - 'TKT_reserved' => $qty * -1, |
|
| 1054 | - ] |
|
| 1055 | - ); |
|
| 1056 | - do_action( |
|
| 1057 | - 'AHEE__EE_Ticket__decrease_reserved', |
|
| 1058 | - $this, |
|
| 1059 | - $qty, |
|
| 1060 | - $this->reserved(), |
|
| 1061 | - $success |
|
| 1062 | - ); |
|
| 1063 | - return $success; |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * Decreases the reserved count on the specified datetimes. |
|
| 1069 | - * |
|
| 1070 | - * @param int $qty |
|
| 1071 | - * @param EE_Datetime[] $datetimes |
|
| 1072 | - * @throws EE_Error |
|
| 1073 | - * @throws InvalidArgumentException |
|
| 1074 | - * @throws ReflectionException |
|
| 1075 | - * @throws InvalidDataTypeException |
|
| 1076 | - * @throws InvalidInterfaceException |
|
| 1077 | - * @since 4.9.80.p |
|
| 1078 | - */ |
|
| 1079 | - protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1080 | - { |
|
| 1081 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1082 | - foreach ($datetimes as $datetime) { |
|
| 1083 | - if ($datetime instanceof EE_Datetime) { |
|
| 1084 | - $datetime->decreaseReserved($qty); |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - /** |
|
| 1091 | - * Gets ticket quantity |
|
| 1092 | - * |
|
| 1093 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1094 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 1095 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 1096 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1097 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1098 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1099 | - * @return int |
|
| 1100 | - * @throws EE_Error |
|
| 1101 | - * @throws ReflectionException |
|
| 1102 | - */ |
|
| 1103 | - public function qty($context = '') |
|
| 1104 | - { |
|
| 1105 | - switch ($context) { |
|
| 1106 | - case 'reg_limit': |
|
| 1107 | - return $this->real_quantity_on_ticket(); |
|
| 1108 | - case 'saleable': |
|
| 1109 | - return $this->real_quantity_on_ticket('saleable'); |
|
| 1110 | - default: |
|
| 1111 | - return $this->get_raw('TKT_qty'); |
|
| 1112 | - } |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - |
|
| 1116 | - /** |
|
| 1117 | - * Gets ticket quantity |
|
| 1118 | - * |
|
| 1119 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1120 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1121 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1122 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1123 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1124 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1125 | - * set to 0 for all related datetimes |
|
| 1126 | - * @return int |
|
| 1127 | - * @throws EE_Error |
|
| 1128 | - * @throws ReflectionException |
|
| 1129 | - */ |
|
| 1130 | - public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
| 1131 | - { |
|
| 1132 | - $raw = $this->get_raw('TKT_qty'); |
|
| 1133 | - // return immediately if it's zero |
|
| 1134 | - if ($raw === 0) { |
|
| 1135 | - return $raw; |
|
| 1136 | - } |
|
| 1137 | - // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
| 1138 | - // ensure qty doesn't exceed raw value for THIS ticket |
|
| 1139 | - $qty = min(EE_INF, $raw); |
|
| 1140 | - // echo "\n . qty: " . $qty . '<br />'; |
|
| 1141 | - // calculate this ticket's total sales and reservations |
|
| 1142 | - $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
| 1143 | - // echo "\n . sold: " . $this->sold() . '<br />'; |
|
| 1144 | - // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
| 1145 | - // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
| 1146 | - // first we need to calculate the maximum number of tickets available for the datetime |
|
| 1147 | - // do we want data for one datetime or all of them ? |
|
| 1148 | - $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : []; |
|
| 1149 | - $datetimes = $this->datetimes($query_params); |
|
| 1150 | - if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1151 | - foreach ($datetimes as $datetime) { |
|
| 1152 | - if ($datetime instanceof EE_Datetime) { |
|
| 1153 | - $datetime->refresh_from_db(); |
|
| 1154 | - // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
| 1155 | - // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
| 1156 | - // initialize with no restrictions for each datetime |
|
| 1157 | - // but adjust datetime qty based on datetime reg limit |
|
| 1158 | - $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1159 | - // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
| 1160 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1161 | - // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
| 1162 | - // and reservations for this datetime, that do NOT include sales and reservations |
|
| 1163 | - // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
| 1164 | - if ($context === 'saleable') { |
|
| 1165 | - $datetime_qty = max( |
|
| 1166 | - $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
| 1167 | - 0 |
|
| 1168 | - ); |
|
| 1169 | - // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
| 1170 | - // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
| 1171 | - // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
| 1172 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1173 | - $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
| 1174 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1175 | - } |
|
| 1176 | - $qty = min($datetime_qty, $qty); |
|
| 1177 | - // echo "\n . . qty: " . $qty . '<br />'; |
|
| 1178 | - } |
|
| 1179 | - } |
|
| 1180 | - } |
|
| 1181 | - // NOW that we know the maximum number of tickets available for the datetime |
|
| 1182 | - // we can finally factor in the details for this specific ticket |
|
| 1183 | - if ($qty > 0 && $context === 'saleable') { |
|
| 1184 | - // and subtract the sales for THIS ticket |
|
| 1185 | - $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1186 | - // echo "\n . qty: " . $qty . '<br />'; |
|
| 1187 | - } |
|
| 1188 | - // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
| 1189 | - return $qty; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - |
|
| 1193 | - /** |
|
| 1194 | - * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
| 1195 | - * |
|
| 1196 | - * @param int $qty |
|
| 1197 | - * @return void |
|
| 1198 | - * @throws EE_Error |
|
| 1199 | - * @throws ReflectionException |
|
| 1200 | - */ |
|
| 1201 | - public function set_qty($qty) |
|
| 1202 | - { |
|
| 1203 | - $datetimes = $this->datetimes(); |
|
| 1204 | - foreach ($datetimes as $datetime) { |
|
| 1205 | - if ($datetime instanceof EE_Datetime) { |
|
| 1206 | - $qty = min($qty, $datetime->reg_limit()); |
|
| 1207 | - } |
|
| 1208 | - } |
|
| 1209 | - $this->set('TKT_qty', $qty); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - |
|
| 1213 | - /** |
|
| 1214 | - * Gets uses |
|
| 1215 | - * |
|
| 1216 | - * @return int |
|
| 1217 | - * @throws EE_Error |
|
| 1218 | - * @throws ReflectionException |
|
| 1219 | - */ |
|
| 1220 | - public function uses() |
|
| 1221 | - { |
|
| 1222 | - return $this->get('TKT_uses'); |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - |
|
| 1226 | - /** |
|
| 1227 | - * Sets uses |
|
| 1228 | - * |
|
| 1229 | - * @param int $uses |
|
| 1230 | - * @return void |
|
| 1231 | - * @throws EE_Error |
|
| 1232 | - * @throws ReflectionException |
|
| 1233 | - */ |
|
| 1234 | - public function set_uses($uses) |
|
| 1235 | - { |
|
| 1236 | - $this->set('TKT_uses', $uses); |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * returns whether ticket is required or not. |
|
| 1242 | - * |
|
| 1243 | - * @return boolean |
|
| 1244 | - * @throws EE_Error |
|
| 1245 | - * @throws ReflectionException |
|
| 1246 | - */ |
|
| 1247 | - public function required() |
|
| 1248 | - { |
|
| 1249 | - return $this->get('TKT_required'); |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - |
|
| 1253 | - /** |
|
| 1254 | - * sets the TKT_required property |
|
| 1255 | - * |
|
| 1256 | - * @param boolean $required |
|
| 1257 | - * @return void |
|
| 1258 | - * @throws EE_Error |
|
| 1259 | - * @throws ReflectionException |
|
| 1260 | - */ |
|
| 1261 | - public function set_required($required) |
|
| 1262 | - { |
|
| 1263 | - $this->set('TKT_required', $required); |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - |
|
| 1267 | - /** |
|
| 1268 | - * Gets taxable |
|
| 1269 | - * |
|
| 1270 | - * @return boolean |
|
| 1271 | - * @throws EE_Error |
|
| 1272 | - * @throws ReflectionException |
|
| 1273 | - */ |
|
| 1274 | - public function taxable() |
|
| 1275 | - { |
|
| 1276 | - return $this->get('TKT_taxable'); |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * Sets taxable |
|
| 1282 | - * |
|
| 1283 | - * @param boolean $taxable |
|
| 1284 | - * @return void |
|
| 1285 | - * @throws EE_Error |
|
| 1286 | - * @throws ReflectionException |
|
| 1287 | - */ |
|
| 1288 | - public function set_taxable($taxable) |
|
| 1289 | - { |
|
| 1290 | - $this->set('TKT_taxable', $taxable); |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /** |
|
| 1295 | - * Gets is_default |
|
| 1296 | - * |
|
| 1297 | - * @return boolean |
|
| 1298 | - * @throws EE_Error |
|
| 1299 | - * @throws ReflectionException |
|
| 1300 | - */ |
|
| 1301 | - public function is_default() |
|
| 1302 | - { |
|
| 1303 | - return $this->get('TKT_is_default'); |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * Sets is_default |
|
| 1309 | - * |
|
| 1310 | - * @param boolean $is_default |
|
| 1311 | - * @return void |
|
| 1312 | - * @throws EE_Error |
|
| 1313 | - * @throws ReflectionException |
|
| 1314 | - */ |
|
| 1315 | - public function set_is_default($is_default) |
|
| 1316 | - { |
|
| 1317 | - $this->set('TKT_is_default', $is_default); |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * Gets order |
|
| 1323 | - * |
|
| 1324 | - * @return int |
|
| 1325 | - * @throws EE_Error |
|
| 1326 | - * @throws ReflectionException |
|
| 1327 | - */ |
|
| 1328 | - public function order() |
|
| 1329 | - { |
|
| 1330 | - return $this->get('TKT_order'); |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * Sets order |
|
| 1336 | - * |
|
| 1337 | - * @param int $order |
|
| 1338 | - * @return void |
|
| 1339 | - * @throws EE_Error |
|
| 1340 | - * @throws ReflectionException |
|
| 1341 | - */ |
|
| 1342 | - public function set_order($order) |
|
| 1343 | - { |
|
| 1344 | - $this->set('TKT_order', $order); |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - |
|
| 1348 | - /** |
|
| 1349 | - * Gets row |
|
| 1350 | - * |
|
| 1351 | - * @return int |
|
| 1352 | - * @throws EE_Error |
|
| 1353 | - * @throws ReflectionException |
|
| 1354 | - */ |
|
| 1355 | - public function row() |
|
| 1356 | - { |
|
| 1357 | - return $this->get('TKT_row'); |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - |
|
| 1361 | - /** |
|
| 1362 | - * Sets row |
|
| 1363 | - * |
|
| 1364 | - * @param int $row |
|
| 1365 | - * @return void |
|
| 1366 | - * @throws EE_Error |
|
| 1367 | - * @throws ReflectionException |
|
| 1368 | - */ |
|
| 1369 | - public function set_row($row) |
|
| 1370 | - { |
|
| 1371 | - $this->set('TKT_row', $row); |
|
| 1372 | - } |
|
| 1373 | - |
|
| 1374 | - |
|
| 1375 | - /** |
|
| 1376 | - * Gets deleted |
|
| 1377 | - * |
|
| 1378 | - * @return boolean |
|
| 1379 | - * @throws EE_Error |
|
| 1380 | - * @throws ReflectionException |
|
| 1381 | - */ |
|
| 1382 | - public function deleted() |
|
| 1383 | - { |
|
| 1384 | - return $this->get('TKT_deleted'); |
|
| 1385 | - } |
|
| 1386 | - |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * Sets deleted |
|
| 1390 | - * |
|
| 1391 | - * @param boolean $deleted |
|
| 1392 | - * @return void |
|
| 1393 | - * @throws EE_Error |
|
| 1394 | - * @throws ReflectionException |
|
| 1395 | - */ |
|
| 1396 | - public function set_deleted($deleted) |
|
| 1397 | - { |
|
| 1398 | - $this->set('TKT_deleted', $deleted); |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - |
|
| 1402 | - /** |
|
| 1403 | - * Gets parent |
|
| 1404 | - * |
|
| 1405 | - * @return int |
|
| 1406 | - * @throws EE_Error |
|
| 1407 | - * @throws ReflectionException |
|
| 1408 | - */ |
|
| 1409 | - public function parent_ID() |
|
| 1410 | - { |
|
| 1411 | - return $this->get('TKT_parent'); |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - |
|
| 1415 | - /** |
|
| 1416 | - * Sets parent |
|
| 1417 | - * |
|
| 1418 | - * @param int $parent |
|
| 1419 | - * @return void |
|
| 1420 | - * @throws EE_Error |
|
| 1421 | - * @throws ReflectionException |
|
| 1422 | - */ |
|
| 1423 | - public function set_parent_ID($parent) |
|
| 1424 | - { |
|
| 1425 | - $this->set('TKT_parent', $parent); |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1431 | - * |
|
| 1432 | - * @return string |
|
| 1433 | - * @throws EE_Error |
|
| 1434 | - * @throws ReflectionException |
|
| 1435 | - */ |
|
| 1436 | - public function name_and_info() |
|
| 1437 | - { |
|
| 1438 | - $times = []; |
|
| 1439 | - foreach ($this->datetimes() as $datetime) { |
|
| 1440 | - $times[] = $datetime->start_date_and_time(); |
|
| 1441 | - } |
|
| 1442 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1443 | - } |
|
| 1444 | - |
|
| 1445 | - |
|
| 1446 | - /** |
|
| 1447 | - * Gets name |
|
| 1448 | - * |
|
| 1449 | - * @return string |
|
| 1450 | - * @throws EE_Error |
|
| 1451 | - * @throws ReflectionException |
|
| 1452 | - */ |
|
| 1453 | - public function name() |
|
| 1454 | - { |
|
| 1455 | - return $this->get('TKT_name'); |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - |
|
| 1459 | - /** |
|
| 1460 | - * Gets price |
|
| 1461 | - * |
|
| 1462 | - * @return float |
|
| 1463 | - * @throws EE_Error |
|
| 1464 | - * @throws ReflectionException |
|
| 1465 | - */ |
|
| 1466 | - public function price() |
|
| 1467 | - { |
|
| 1468 | - return $this->get('TKT_price'); |
|
| 1469 | - } |
|
| 1470 | - |
|
| 1471 | - |
|
| 1472 | - /** |
|
| 1473 | - * Gets all the registrations for this ticket |
|
| 1474 | - * |
|
| 1475 | - * @param array $query_params @see |
|
| 1476 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1477 | - * @return EE_Registration[]|EE_Base_Class[] |
|
| 1478 | - * @throws EE_Error |
|
| 1479 | - * @throws ReflectionException |
|
| 1480 | - */ |
|
| 1481 | - public function registrations($query_params = []) |
|
| 1482 | - { |
|
| 1483 | - return $this->get_many_related('Registration', $query_params); |
|
| 1484 | - } |
|
| 1485 | - |
|
| 1486 | - |
|
| 1487 | - /** |
|
| 1488 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1489 | - * |
|
| 1490 | - * @return int |
|
| 1491 | - * @throws EE_Error |
|
| 1492 | - * @throws ReflectionException |
|
| 1493 | - */ |
|
| 1494 | - public function update_tickets_sold() |
|
| 1495 | - { |
|
| 1496 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1497 | - [ |
|
| 1498 | - [ |
|
| 1499 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1500 | - 'REG_deleted' => 0, |
|
| 1501 | - ], |
|
| 1502 | - ] |
|
| 1503 | - ); |
|
| 1504 | - $this->set_sold($count_regs_for_this_ticket); |
|
| 1505 | - $this->save(); |
|
| 1506 | - return $count_regs_for_this_ticket; |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * Counts the registrations for this ticket |
|
| 1512 | - * |
|
| 1513 | - * @param array $query_params @see |
|
| 1514 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1515 | - * @return int |
|
| 1516 | - */ |
|
| 1517 | - public function count_registrations($query_params = []) |
|
| 1518 | - { |
|
| 1519 | - return $this->count_related('Registration', $query_params); |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1525 | - * |
|
| 1526 | - * @return string |
|
| 1527 | - * @see EEI_Visual_Representation for comments |
|
| 1528 | - */ |
|
| 1529 | - public function get_icon() |
|
| 1530 | - { |
|
| 1531 | - return '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
| 1532 | - } |
|
| 1533 | - |
|
| 1534 | - |
|
| 1535 | - /** |
|
| 1536 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1537 | - * |
|
| 1538 | - * @return EE_Event |
|
| 1539 | - * @throws EE_Error |
|
| 1540 | - * @throws UnexpectedEntityException*@throws ReflectionException |
|
| 1541 | - * @see EEI_Event_Relation for comments |
|
| 1542 | - */ |
|
| 1543 | - public function get_related_event() |
|
| 1544 | - { |
|
| 1545 | - // get one datetime to use for getting the event |
|
| 1546 | - $datetime = $this->first_datetime(); |
|
| 1547 | - if (! $datetime instanceof \EE_Datetime) { |
|
| 1548 | - throw new UnexpectedEntityException( |
|
| 1549 | - $datetime, |
|
| 1550 | - 'EE_Datetime', |
|
| 1551 | - sprintf( |
|
| 1552 | - esc_html__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1553 | - $this->name() |
|
| 1554 | - ) |
|
| 1555 | - ); |
|
| 1556 | - } |
|
| 1557 | - $event = $datetime->event(); |
|
| 1558 | - if (! $event instanceof \EE_Event) { |
|
| 1559 | - throw new UnexpectedEntityException( |
|
| 1560 | - $event, |
|
| 1561 | - 'EE_Event', |
|
| 1562 | - sprintf( |
|
| 1563 | - esc_html__('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1564 | - $this->name() |
|
| 1565 | - ) |
|
| 1566 | - ); |
|
| 1567 | - } |
|
| 1568 | - return $event; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - |
|
| 1572 | - /** |
|
| 1573 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1574 | - * |
|
| 1575 | - * @return string |
|
| 1576 | - * @throws UnexpectedEntityException |
|
| 1577 | - * @throws EE_Error*@throws ReflectionException |
|
| 1578 | - * @see EEI_Event_Relation for comments |
|
| 1579 | - */ |
|
| 1580 | - public function get_event_name() |
|
| 1581 | - { |
|
| 1582 | - $event = $this->get_related_event(); |
|
| 1583 | - return $event instanceof EE_Event ? $event->name() : ''; |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - |
|
| 1587 | - /** |
|
| 1588 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1589 | - * |
|
| 1590 | - * @return int |
|
| 1591 | - * @throws UnexpectedEntityException |
|
| 1592 | - * @throws EE_Error*@throws ReflectionException |
|
| 1593 | - * @see EEI_Event_Relation for comments |
|
| 1594 | - */ |
|
| 1595 | - public function get_event_ID() |
|
| 1596 | - { |
|
| 1597 | - $event = $this->get_related_event(); |
|
| 1598 | - return $event instanceof EE_Event ? $event->ID() : 0; |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - |
|
| 1602 | - /** |
|
| 1603 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1604 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1605 | - * If there are none then it can be permanently deleted. |
|
| 1606 | - * |
|
| 1607 | - * @return bool |
|
| 1608 | - */ |
|
| 1609 | - public function is_permanently_deleteable() |
|
| 1610 | - { |
|
| 1611 | - return $this->count_registrations() === 0; |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - |
|
| 1615 | - /******************************************************************* |
|
| 17 | + /** |
|
| 18 | + * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not. |
|
| 19 | + */ |
|
| 20 | + const sold_out = 'TKS'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + */ |
|
| 25 | + const expired = 'TKE'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + */ |
|
| 30 | + const archived = 'TKA'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * |
|
| 34 | + */ |
|
| 35 | + const pending = 'TKP'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * |
|
| 39 | + */ |
|
| 40 | + const onsale = 'TKO'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * extra meta key for tracking ticket reservations |
|
| 44 | + * |
|
| 45 | + * @type string |
|
| 46 | + */ |
|
| 47 | + const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * cached result from method of the same name |
|
| 51 | + * |
|
| 52 | + * @var float $_ticket_total_with_taxes |
|
| 53 | + */ |
|
| 54 | + private $_ticket_total_with_taxes; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param array $props_n_values incoming values |
|
| 59 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | + * used.) |
|
| 61 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | + * date_format and the second value is the time format |
|
| 63 | + * @return EE_Ticket |
|
| 64 | + * @throws EE_Error |
|
| 65 | + * @throws ReflectionException |
|
| 66 | + */ |
|
| 67 | + public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
| 68 | + { |
|
| 69 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 70 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param array $props_n_values incoming values from the database |
|
| 76 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 77 | + * the website will be used. |
|
| 78 | + * @return EE_Ticket |
|
| 79 | + * @throws EE_Error |
|
| 80 | + * @throws ReflectionException |
|
| 81 | + */ |
|
| 82 | + public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
| 83 | + { |
|
| 84 | + return new self($props_n_values, true, $timezone); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return bool |
|
| 90 | + * @throws EE_Error |
|
| 91 | + * @throws ReflectionException |
|
| 92 | + */ |
|
| 93 | + public function parent() |
|
| 94 | + { |
|
| 95 | + return $this->get('TKT_parent'); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * return if a ticket has quantities available for purchase |
|
| 101 | + * |
|
| 102 | + * @param int $DTT_ID the primary key for a particular datetime |
|
| 103 | + * @return boolean |
|
| 104 | + * @throws EE_Error |
|
| 105 | + * @throws ReflectionException |
|
| 106 | + */ |
|
| 107 | + public function available($DTT_ID = 0) |
|
| 108 | + { |
|
| 109 | + // are we checking availability for a particular datetime ? |
|
| 110 | + if ($DTT_ID) { |
|
| 111 | + // get that datetime object |
|
| 112 | + $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]); |
|
| 113 | + // if ticket sales for this datetime have exceeded the reg limit... |
|
| 114 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 115 | + return false; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + // datetime is still open for registration, but is this ticket sold out ? |
|
| 119 | + return $this->qty() < 1 || $this->qty() > $this->sold() ? true : false; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 125 | + * |
|
| 126 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
| 127 | + * relevant status const |
|
| 128 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
| 129 | + * further processing |
|
| 130 | + * @return mixed status int if the display string isn't requested |
|
| 131 | + * @throws EE_Error |
|
| 132 | + * @throws ReflectionException |
|
| 133 | + */ |
|
| 134 | + public function ticket_status($display = false, $remaining = null) |
|
| 135 | + { |
|
| 136 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 137 | + if (! $remaining) { |
|
| 138 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
| 139 | + } |
|
| 140 | + if ($this->get('TKT_deleted')) { |
|
| 141 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
| 142 | + } |
|
| 143 | + if ($this->is_expired()) { |
|
| 144 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
| 145 | + } |
|
| 146 | + if ($this->is_pending()) { |
|
| 147 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
| 148 | + } |
|
| 149 | + if ($this->is_on_sale()) { |
|
| 150 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
| 151 | + } |
|
| 152 | + return ''; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
| 158 | + * considering ALL the factors used for figuring that out. |
|
| 159 | + * |
|
| 160 | + * @access public |
|
| 161 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 162 | + * @return boolean true = tickets remaining, false not. |
|
| 163 | + * @throws EE_Error |
|
| 164 | + */ |
|
| 165 | + public function is_remaining($DTT_ID = 0) |
|
| 166 | + { |
|
| 167 | + $num_remaining = $this->remaining($DTT_ID); |
|
| 168 | + if ($num_remaining === 0) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + return true; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * return the total number of tickets available for purchase |
|
| 180 | + * |
|
| 181 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 182 | + * set to 0 for all related datetimes |
|
| 183 | + * @return int |
|
| 184 | + * @throws EE_Error |
|
| 185 | + */ |
|
| 186 | + public function remaining($DTT_ID = 0) |
|
| 187 | + { |
|
| 188 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Gets min |
|
| 194 | + * |
|
| 195 | + * @return int |
|
| 196 | + * @throws EE_Error |
|
| 197 | + * @throws ReflectionException |
|
| 198 | + */ |
|
| 199 | + public function min() |
|
| 200 | + { |
|
| 201 | + return $this->get('TKT_min'); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * return if a ticket is no longer available cause its available dates have expired. |
|
| 207 | + * |
|
| 208 | + * @return boolean |
|
| 209 | + * @throws EE_Error |
|
| 210 | + * @throws ReflectionException |
|
| 211 | + */ |
|
| 212 | + public function is_expired() |
|
| 213 | + { |
|
| 214 | + return ($this->get_raw('TKT_end_date') < time()); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Return if a ticket is yet to go on sale or not |
|
| 220 | + * |
|
| 221 | + * @return boolean |
|
| 222 | + * @throws EE_Error |
|
| 223 | + * @throws ReflectionException |
|
| 224 | + */ |
|
| 225 | + public function is_pending() |
|
| 226 | + { |
|
| 227 | + return ($this->get_raw('TKT_start_date') > time()); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Return if a ticket is on sale or not |
|
| 233 | + * |
|
| 234 | + * @return boolean |
|
| 235 | + * @throws EE_Error |
|
| 236 | + * @throws ReflectionException |
|
| 237 | + */ |
|
| 238 | + public function is_on_sale() |
|
| 239 | + { |
|
| 240 | + return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 246 | + * |
|
| 247 | + * @param string $dt_frmt |
|
| 248 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
| 249 | + * the end date ie: Jan 01 "to" Dec 31 |
|
| 250 | + * @return string |
|
| 251 | + * @throws EE_Error |
|
| 252 | + * @throws ReflectionException |
|
| 253 | + */ |
|
| 254 | + public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 255 | + { |
|
| 256 | + $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
| 257 | + $first_date = $this->first_datetime() instanceof EE_Datetime |
|
| 258 | + ? $this->first_datetime()->get_i18n_datetime( |
|
| 259 | + 'DTT_EVT_start', |
|
| 260 | + $dt_frmt |
|
| 261 | + ) : ''; |
|
| 262 | + $last_date = |
|
| 263 | + $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->get_i18n_datetime( |
|
| 264 | + 'DTT_EVT_end', |
|
| 265 | + $dt_frmt |
|
| 266 | + ) : ''; |
|
| 267 | + |
|
| 268 | + return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * This returns the chronologically first datetime that this ticket is associated with |
|
| 274 | + * |
|
| 275 | + * @return EE_Datetime |
|
| 276 | + * @throws EE_Error |
|
| 277 | + */ |
|
| 278 | + public function first_datetime() |
|
| 279 | + { |
|
| 280 | + $datetimes = $this->datetimes(['limit' => 1]); |
|
| 281 | + return reset($datetimes); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Gets all the datetimes this ticket can be used for attending. |
|
| 287 | + * Unless otherwise specified, orders datetimes by start date. |
|
| 288 | + * |
|
| 289 | + * @param array $query_params @see |
|
| 290 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 291 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
| 292 | + * @throws EE_Error |
|
| 293 | + * @throws ReflectionException |
|
| 294 | + */ |
|
| 295 | + public function datetimes($query_params = []) |
|
| 296 | + { |
|
| 297 | + if (! isset($query_params['order_by'])) { |
|
| 298 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 299 | + } |
|
| 300 | + return $this->get_many_related('Datetime', $query_params); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 306 | + * |
|
| 307 | + * @return EE_Datetime |
|
| 308 | + * @throws EE_Error |
|
| 309 | + */ |
|
| 310 | + public function last_datetime() |
|
| 311 | + { |
|
| 312 | + $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]); |
|
| 313 | + return end($datetimes); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * This returns the total tickets sold depending on the given parameters. |
|
| 319 | + * |
|
| 320 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 321 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 322 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 323 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 324 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 325 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 326 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 327 | + * @return mixed (array|int) how many tickets have sold |
|
| 328 | + * @throws EE_Error |
|
| 329 | + */ |
|
| 330 | + public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
| 331 | + { |
|
| 332 | + $total = 0; |
|
| 333 | + $tickets_sold = $this->_all_tickets_sold(); |
|
| 334 | + switch ($what) { |
|
| 335 | + case 'ticket': |
|
| 336 | + return $tickets_sold['ticket']; |
|
| 337 | + break; |
|
| 338 | + case 'datetime': |
|
| 339 | + if (empty($tickets_sold['datetime'])) { |
|
| 340 | + return $total; |
|
| 341 | + } |
|
| 342 | + if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 343 | + EE_Error::add_error( |
|
| 344 | + esc_html__( |
|
| 345 | + 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
| 346 | + 'event_espresso' |
|
| 347 | + ), |
|
| 348 | + __FILE__, |
|
| 349 | + __FUNCTION__, |
|
| 350 | + __LINE__ |
|
| 351 | + ); |
|
| 352 | + return $total; |
|
| 353 | + } |
|
| 354 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 355 | + break; |
|
| 356 | + default: |
|
| 357 | + return $total; |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 364 | + * |
|
| 365 | + * @return EE_Ticket[] |
|
| 366 | + * @throws EE_Error |
|
| 367 | + * @throws ReflectionException |
|
| 368 | + */ |
|
| 369 | + protected function _all_tickets_sold() |
|
| 370 | + { |
|
| 371 | + $datetimes = $this->get_many_related('Datetime'); |
|
| 372 | + $tickets_sold = []; |
|
| 373 | + if (! empty($datetimes)) { |
|
| 374 | + foreach ($datetimes as $datetime) { |
|
| 375 | + $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + // Tickets sold |
|
| 379 | + $tickets_sold['ticket'] = $this->sold(); |
|
| 380 | + return $tickets_sold; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * This returns the base price object for the ticket. |
|
| 386 | + * |
|
| 387 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 388 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 389 | + * @throws EE_Error |
|
| 390 | + * @throws ReflectionException |
|
| 391 | + */ |
|
| 392 | + public function base_price($return_array = false) |
|
| 393 | + { |
|
| 394 | + $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price]; |
|
| 395 | + return $return_array |
|
| 396 | + ? $this->get_many_related('Price', [$_where]) |
|
| 397 | + : $this->get_first_related('Price', [$_where]); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 403 | + * |
|
| 404 | + * @access public |
|
| 405 | + * @return EE_Price[] |
|
| 406 | + * @throws EE_Error |
|
| 407 | + */ |
|
| 408 | + public function price_modifiers() |
|
| 409 | + { |
|
| 410 | + $query_params = [ |
|
| 411 | + 0 => [ |
|
| 412 | + 'Price_Type.PBT_ID' => [ |
|
| 413 | + 'NOT IN', |
|
| 414 | + [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax], |
|
| 415 | + ], |
|
| 416 | + ], |
|
| 417 | + ]; |
|
| 418 | + return $this->prices($query_params); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Gets all the prices that combine to form the final price of this ticket |
|
| 424 | + * |
|
| 425 | + * @param array $query_params @see |
|
| 426 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 427 | + * @return EE_Price[]|EE_Base_Class[] |
|
| 428 | + * @throws EE_Error |
|
| 429 | + * @throws ReflectionException |
|
| 430 | + */ |
|
| 431 | + public function prices($query_params = []) |
|
| 432 | + { |
|
| 433 | + return $this->get_many_related('Price', $query_params); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 439 | + * |
|
| 440 | + * @param array $query_params @see |
|
| 441 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 442 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 443 | + * @throws EE_Error |
|
| 444 | + * @throws ReflectionException |
|
| 445 | + */ |
|
| 446 | + public function datetime_tickets($query_params = []) |
|
| 447 | + { |
|
| 448 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Gets all the datetimes from the db ordered by DTT_order |
|
| 454 | + * |
|
| 455 | + * @param boolean $show_expired |
|
| 456 | + * @param boolean $show_deleted |
|
| 457 | + * @return EE_Datetime[] |
|
| 458 | + * @throws EE_Error |
|
| 459 | + */ |
|
| 460 | + public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
| 461 | + { |
|
| 462 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 463 | + $this->ID(), |
|
| 464 | + $show_expired, |
|
| 465 | + $show_deleted |
|
| 466 | + ); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Gets ID |
|
| 472 | + * |
|
| 473 | + * @return int |
|
| 474 | + * @throws EE_Error |
|
| 475 | + * @throws ReflectionException |
|
| 476 | + */ |
|
| 477 | + public function ID() |
|
| 478 | + { |
|
| 479 | + return (int) $this->get('TKT_ID'); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * get the author of the ticket. |
|
| 485 | + * |
|
| 486 | + * @return int |
|
| 487 | + * @throws EE_Error |
|
| 488 | + * @throws ReflectionException |
|
| 489 | + * @since 4.5.0 |
|
| 490 | + */ |
|
| 491 | + public function wp_user() |
|
| 492 | + { |
|
| 493 | + return $this->get('TKT_wp_user'); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Gets the template for the ticket |
|
| 499 | + * |
|
| 500 | + * @return EE_Ticket_Template|EE_Base_Class |
|
| 501 | + * @throws EE_Error |
|
| 502 | + * @throws ReflectionException |
|
| 503 | + */ |
|
| 504 | + public function template() |
|
| 505 | + { |
|
| 506 | + return $this->get_first_related('Ticket_Template'); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Simply returns an array of EE_Price objects that are taxes. |
|
| 512 | + * |
|
| 513 | + * @return EE_Price[] |
|
| 514 | + * @throws EE_Error |
|
| 515 | + */ |
|
| 516 | + public function get_ticket_taxes_for_admin() |
|
| 517 | + { |
|
| 518 | + return EE_Taxes::get_taxes_for_admin(); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * @return float |
|
| 524 | + * @throws EE_Error |
|
| 525 | + * @throws ReflectionException |
|
| 526 | + */ |
|
| 527 | + public function ticket_price() |
|
| 528 | + { |
|
| 529 | + return $this->get('TKT_price'); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * @return mixed |
|
| 535 | + * @throws EE_Error |
|
| 536 | + * @throws ReflectionException |
|
| 537 | + */ |
|
| 538 | + public function pretty_price() |
|
| 539 | + { |
|
| 540 | + return $this->get_pretty('TKT_price'); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * @return bool |
|
| 546 | + * @throws EE_Error |
|
| 547 | + */ |
|
| 548 | + public function is_free() |
|
| 549 | + { |
|
| 550 | + return $this->get_ticket_total_with_taxes() === (float) 0; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * get_ticket_total_with_taxes |
|
| 556 | + * |
|
| 557 | + * @param bool $no_cache |
|
| 558 | + * @return float |
|
| 559 | + * @throws EE_Error |
|
| 560 | + */ |
|
| 561 | + public function get_ticket_total_with_taxes($no_cache = false) |
|
| 562 | + { |
|
| 563 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 564 | + $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
| 565 | + } |
|
| 566 | + return (float) $this->_ticket_total_with_taxes; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + public function ensure_TKT_Price_correct() |
|
| 571 | + { |
|
| 572 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 573 | + $this->save(); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @return float |
|
| 579 | + * @throws EE_Error |
|
| 580 | + */ |
|
| 581 | + public function get_ticket_subtotal() |
|
| 582 | + { |
|
| 583 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Returns the total taxes applied to this ticket |
|
| 589 | + * |
|
| 590 | + * @return float |
|
| 591 | + * @throws EE_Error |
|
| 592 | + */ |
|
| 593 | + public function get_ticket_taxes_total_for_admin() |
|
| 594 | + { |
|
| 595 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * Sets name |
|
| 601 | + * |
|
| 602 | + * @param string $name |
|
| 603 | + * @throws EE_Error |
|
| 604 | + * @throws ReflectionException |
|
| 605 | + */ |
|
| 606 | + public function set_name($name) |
|
| 607 | + { |
|
| 608 | + $this->set('TKT_name', $name); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * Gets description |
|
| 614 | + * |
|
| 615 | + * @return string |
|
| 616 | + * @throws EE_Error |
|
| 617 | + * @throws ReflectionException |
|
| 618 | + */ |
|
| 619 | + public function description() |
|
| 620 | + { |
|
| 621 | + return $this->get('TKT_description'); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * Sets description |
|
| 627 | + * |
|
| 628 | + * @param string $description |
|
| 629 | + * @throws EE_Error |
|
| 630 | + * @throws ReflectionException |
|
| 631 | + */ |
|
| 632 | + public function set_description($description) |
|
| 633 | + { |
|
| 634 | + $this->set('TKT_description', $description); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * Gets start_date |
|
| 640 | + * |
|
| 641 | + * @param string $dt_frmt |
|
| 642 | + * @param string $tm_frmt |
|
| 643 | + * @return string |
|
| 644 | + * @throws EE_Error |
|
| 645 | + * @throws ReflectionException |
|
| 646 | + */ |
|
| 647 | + public function start_date($dt_frmt = '', $tm_frmt = '') |
|
| 648 | + { |
|
| 649 | + return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Sets start_date |
|
| 655 | + * |
|
| 656 | + * @param string $start_date |
|
| 657 | + * @return void |
|
| 658 | + * @throws EE_Error |
|
| 659 | + * @throws ReflectionException |
|
| 660 | + */ |
|
| 661 | + public function set_start_date($start_date) |
|
| 662 | + { |
|
| 663 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Gets end_date |
|
| 669 | + * |
|
| 670 | + * @param string $dt_frmt |
|
| 671 | + * @param string $tm_frmt |
|
| 672 | + * @return string |
|
| 673 | + * @throws EE_Error |
|
| 674 | + * @throws ReflectionException |
|
| 675 | + */ |
|
| 676 | + public function end_date($dt_frmt = '', $tm_frmt = '') |
|
| 677 | + { |
|
| 678 | + return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * Sets end_date |
|
| 684 | + * |
|
| 685 | + * @param string $end_date |
|
| 686 | + * @return void |
|
| 687 | + * @throws EE_Error |
|
| 688 | + * @throws ReflectionException |
|
| 689 | + */ |
|
| 690 | + public function set_end_date($end_date) |
|
| 691 | + { |
|
| 692 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Sets sell until time |
|
| 698 | + * |
|
| 699 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 700 | + * @throws EE_Error*@throws ReflectionException |
|
| 701 | + * @since 4.5.0 |
|
| 702 | + */ |
|
| 703 | + public function set_end_time($time) |
|
| 704 | + { |
|
| 705 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Sets min |
|
| 711 | + * |
|
| 712 | + * @param int $min |
|
| 713 | + * @return void |
|
| 714 | + * @throws EE_Error |
|
| 715 | + * @throws ReflectionException |
|
| 716 | + */ |
|
| 717 | + public function set_min($min) |
|
| 718 | + { |
|
| 719 | + $this->set('TKT_min', $min); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * Gets max |
|
| 725 | + * |
|
| 726 | + * @return int |
|
| 727 | + * @throws EE_Error |
|
| 728 | + * @throws ReflectionException |
|
| 729 | + */ |
|
| 730 | + public function max() |
|
| 731 | + { |
|
| 732 | + return $this->get('TKT_max'); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Sets max |
|
| 738 | + * |
|
| 739 | + * @param int $max |
|
| 740 | + * @return void |
|
| 741 | + * @throws EE_Error |
|
| 742 | + * @throws ReflectionException |
|
| 743 | + */ |
|
| 744 | + public function set_max($max) |
|
| 745 | + { |
|
| 746 | + $this->set('TKT_max', $max); |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * Sets price |
|
| 752 | + * |
|
| 753 | + * @param float $price |
|
| 754 | + * @return void |
|
| 755 | + * @throws EE_Error |
|
| 756 | + * @throws ReflectionException |
|
| 757 | + */ |
|
| 758 | + public function set_price($price) |
|
| 759 | + { |
|
| 760 | + $this->set('TKT_price', $price); |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * Gets sold |
|
| 766 | + * |
|
| 767 | + * @return int |
|
| 768 | + * @throws EE_Error |
|
| 769 | + * @throws ReflectionException |
|
| 770 | + */ |
|
| 771 | + public function sold() |
|
| 772 | + { |
|
| 773 | + return $this->get_raw('TKT_sold'); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * Sets sold |
|
| 779 | + * |
|
| 780 | + * @param int $sold |
|
| 781 | + * @return void |
|
| 782 | + * @throws EE_Error |
|
| 783 | + * @throws ReflectionException |
|
| 784 | + */ |
|
| 785 | + public function set_sold($sold) |
|
| 786 | + { |
|
| 787 | + // sold can not go below zero |
|
| 788 | + $sold = max(0, $sold); |
|
| 789 | + $this->set('TKT_sold', $sold); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 795 | + * associated datetimes. |
|
| 796 | + * |
|
| 797 | + * @param int $qty |
|
| 798 | + * @return boolean |
|
| 799 | + * @throws EE_Error |
|
| 800 | + * @throws InvalidArgumentException |
|
| 801 | + * @throws InvalidDataTypeException |
|
| 802 | + * @throws InvalidInterfaceException |
|
| 803 | + * @throws ReflectionException |
|
| 804 | + * @since 4.9.80.p |
|
| 805 | + */ |
|
| 806 | + public function increaseSold($qty = 1) |
|
| 807 | + { |
|
| 808 | + $qty = absint($qty); |
|
| 809 | + // increment sold and decrement reserved datetime quantities simultaneously |
|
| 810 | + // don't worry about failures, because they must have already had a spot reserved |
|
| 811 | + $this->increaseSoldForDatetimes($qty); |
|
| 812 | + // Increment and decrement ticket quantities simultaneously |
|
| 813 | + $success = $this->adjustNumericFieldsInDb( |
|
| 814 | + [ |
|
| 815 | + 'TKT_reserved' => $qty * -1, |
|
| 816 | + 'TKT_sold' => $qty, |
|
| 817 | + ] |
|
| 818 | + ); |
|
| 819 | + do_action( |
|
| 820 | + 'AHEE__EE_Ticket__increase_sold', |
|
| 821 | + $this, |
|
| 822 | + $qty, |
|
| 823 | + $this->sold(), |
|
| 824 | + $success |
|
| 825 | + ); |
|
| 826 | + return $success; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 832 | + * |
|
| 833 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
|
| 834 | + * counts), Negative means to decreases old counts (and increase reserved counts). |
|
| 835 | + * @param EE_Datetime[] $datetimes |
|
| 836 | + * @throws EE_Error |
|
| 837 | + * @throws InvalidArgumentException |
|
| 838 | + * @throws InvalidDataTypeException |
|
| 839 | + * @throws InvalidInterfaceException |
|
| 840 | + * @throws ReflectionException |
|
| 841 | + * @since 4.9.80.p |
|
| 842 | + */ |
|
| 843 | + protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
| 844 | + { |
|
| 845 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 846 | + foreach ($datetimes as $datetime) { |
|
| 847 | + $datetime->increaseSold($qty); |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 854 | + * DB and then updates the model objects. |
|
| 855 | + * Does not affect the reserved counts. |
|
| 856 | + * |
|
| 857 | + * @param int $qty |
|
| 858 | + * @return boolean |
|
| 859 | + * @throws EE_Error |
|
| 860 | + * @throws InvalidArgumentException |
|
| 861 | + * @throws InvalidDataTypeException |
|
| 862 | + * @throws InvalidInterfaceException |
|
| 863 | + * @throws ReflectionException |
|
| 864 | + * @since 4.9.80.p |
|
| 865 | + */ |
|
| 866 | + public function decreaseSold($qty = 1) |
|
| 867 | + { |
|
| 868 | + $qty = absint($qty); |
|
| 869 | + $this->decreaseSoldForDatetimes($qty); |
|
| 870 | + $success = $this->adjustNumericFieldsInDb( |
|
| 871 | + [ |
|
| 872 | + 'TKT_sold' => $qty * -1, |
|
| 873 | + ] |
|
| 874 | + ); |
|
| 875 | + do_action( |
|
| 876 | + 'AHEE__EE_Ticket__decrease_sold', |
|
| 877 | + $this, |
|
| 878 | + $qty, |
|
| 879 | + $this->sold(), |
|
| 880 | + $success |
|
| 881 | + ); |
|
| 882 | + return $success; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * Decreases sold on related datetimes |
|
| 888 | + * |
|
| 889 | + * @param int $qty |
|
| 890 | + * @param EE_Datetime[] $datetimes |
|
| 891 | + * @return void |
|
| 892 | + * @throws EE_Error |
|
| 893 | + * @throws InvalidArgumentException |
|
| 894 | + * @throws InvalidDataTypeException |
|
| 895 | + * @throws InvalidInterfaceException |
|
| 896 | + * @throws ReflectionException |
|
| 897 | + * @since 4.9.80.p |
|
| 898 | + */ |
|
| 899 | + protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
| 900 | + { |
|
| 901 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 902 | + if (is_array($datetimes)) { |
|
| 903 | + foreach ($datetimes as $datetime) { |
|
| 904 | + if ($datetime instanceof EE_Datetime) { |
|
| 905 | + $datetime->decreaseSold($qty); |
|
| 906 | + } |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * Gets qty of reserved tickets |
|
| 914 | + * |
|
| 915 | + * @return int |
|
| 916 | + * @throws EE_Error |
|
| 917 | + * @throws ReflectionException |
|
| 918 | + */ |
|
| 919 | + public function reserved() |
|
| 920 | + { |
|
| 921 | + return $this->get_raw('TKT_reserved'); |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * Sets reserved |
|
| 927 | + * |
|
| 928 | + * @param int $reserved |
|
| 929 | + * @return void |
|
| 930 | + * @throws EE_Error |
|
| 931 | + * @throws ReflectionException |
|
| 932 | + */ |
|
| 933 | + public function set_reserved($reserved) |
|
| 934 | + { |
|
| 935 | + // reserved can not go below zero |
|
| 936 | + $reserved = max(0, (int) $reserved); |
|
| 937 | + $this->set('TKT_reserved', $reserved); |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + |
|
| 941 | + /** |
|
| 942 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 943 | + * |
|
| 944 | + * @param int $qty |
|
| 945 | + * @param string $source |
|
| 946 | + * @return bool whether we successfully reserved the ticket or not. |
|
| 947 | + * @throws EE_Error |
|
| 948 | + * @throws InvalidArgumentException |
|
| 949 | + * @throws ReflectionException |
|
| 950 | + * @throws InvalidDataTypeException |
|
| 951 | + * @throws InvalidInterfaceException |
|
| 952 | + * @since 4.9.80.p |
|
| 953 | + */ |
|
| 954 | + public function increaseReserved($qty = 1, $source = 'unknown') |
|
| 955 | + { |
|
| 956 | + $qty = absint($qty); |
|
| 957 | + do_action( |
|
| 958 | + 'AHEE__EE_Ticket__increase_reserved__begin', |
|
| 959 | + $this, |
|
| 960 | + $qty, |
|
| 961 | + $source |
|
| 962 | + ); |
|
| 963 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
| 964 | + $success = false; |
|
| 965 | + $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
| 966 | + if ($datetimes_adjusted_successfully) { |
|
| 967 | + $success = $this->incrementFieldConditionallyInDb( |
|
| 968 | + 'TKT_reserved', |
|
| 969 | + 'TKT_sold', |
|
| 970 | + 'TKT_qty', |
|
| 971 | + $qty |
|
| 972 | + ); |
|
| 973 | + if (! $success) { |
|
| 974 | + // The datetimes were successfully bumped, but not the |
|
| 975 | + // ticket. So we need to manually rollback the datetimes. |
|
| 976 | + $this->decreaseReservedForDatetimes($qty); |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + do_action( |
|
| 980 | + 'AHEE__EE_Ticket__increase_reserved', |
|
| 981 | + $this, |
|
| 982 | + $qty, |
|
| 983 | + $this->reserved(), |
|
| 984 | + $success |
|
| 985 | + ); |
|
| 986 | + return $success; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * Increases reserved counts on related datetimes |
|
| 992 | + * |
|
| 993 | + * @param int $qty |
|
| 994 | + * @param EE_Datetime[] $datetimes |
|
| 995 | + * @return boolean indicating success |
|
| 996 | + * @throws EE_Error |
|
| 997 | + * @throws InvalidArgumentException |
|
| 998 | + * @throws InvalidDataTypeException |
|
| 999 | + * @throws InvalidInterfaceException |
|
| 1000 | + * @throws ReflectionException |
|
| 1001 | + * @since 4.9.80.p |
|
| 1002 | + */ |
|
| 1003 | + protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1004 | + { |
|
| 1005 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1006 | + $datetimes_updated = []; |
|
| 1007 | + $limit_exceeded = false; |
|
| 1008 | + if (is_array($datetimes)) { |
|
| 1009 | + foreach ($datetimes as $datetime) { |
|
| 1010 | + if ($datetime instanceof EE_Datetime) { |
|
| 1011 | + if ($datetime->increaseReserved($qty)) { |
|
| 1012 | + $datetimes_updated[] = $datetime; |
|
| 1013 | + } else { |
|
| 1014 | + $limit_exceeded = true; |
|
| 1015 | + break; |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + // If somewhere along the way we detected a datetime whose |
|
| 1020 | + // limit was exceeded, do a manual rollback. |
|
| 1021 | + if ($limit_exceeded) { |
|
| 1022 | + $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
| 1023 | + return false; |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | + return true; |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1032 | + * |
|
| 1033 | + * @param int $qty |
|
| 1034 | + * @param bool $adjust_datetimes |
|
| 1035 | + * @param string $source |
|
| 1036 | + * @return boolean |
|
| 1037 | + * @throws EE_Error |
|
| 1038 | + * @throws InvalidArgumentException |
|
| 1039 | + * @throws ReflectionException |
|
| 1040 | + * @throws InvalidDataTypeException |
|
| 1041 | + * @throws InvalidInterfaceException |
|
| 1042 | + * @since 4.9.80.p |
|
| 1043 | + */ |
|
| 1044 | + public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1045 | + { |
|
| 1046 | + $qty = absint($qty); |
|
| 1047 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
| 1048 | + if ($adjust_datetimes) { |
|
| 1049 | + $this->decreaseReservedForDatetimes($qty); |
|
| 1050 | + } |
|
| 1051 | + $success = $this->adjustNumericFieldsInDb( |
|
| 1052 | + [ |
|
| 1053 | + 'TKT_reserved' => $qty * -1, |
|
| 1054 | + ] |
|
| 1055 | + ); |
|
| 1056 | + do_action( |
|
| 1057 | + 'AHEE__EE_Ticket__decrease_reserved', |
|
| 1058 | + $this, |
|
| 1059 | + $qty, |
|
| 1060 | + $this->reserved(), |
|
| 1061 | + $success |
|
| 1062 | + ); |
|
| 1063 | + return $success; |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + |
|
| 1067 | + /** |
|
| 1068 | + * Decreases the reserved count on the specified datetimes. |
|
| 1069 | + * |
|
| 1070 | + * @param int $qty |
|
| 1071 | + * @param EE_Datetime[] $datetimes |
|
| 1072 | + * @throws EE_Error |
|
| 1073 | + * @throws InvalidArgumentException |
|
| 1074 | + * @throws ReflectionException |
|
| 1075 | + * @throws InvalidDataTypeException |
|
| 1076 | + * @throws InvalidInterfaceException |
|
| 1077 | + * @since 4.9.80.p |
|
| 1078 | + */ |
|
| 1079 | + protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1080 | + { |
|
| 1081 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1082 | + foreach ($datetimes as $datetime) { |
|
| 1083 | + if ($datetime instanceof EE_Datetime) { |
|
| 1084 | + $datetime->decreaseReserved($qty); |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + /** |
|
| 1091 | + * Gets ticket quantity |
|
| 1092 | + * |
|
| 1093 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1094 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 1095 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 1096 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1097 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1098 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1099 | + * @return int |
|
| 1100 | + * @throws EE_Error |
|
| 1101 | + * @throws ReflectionException |
|
| 1102 | + */ |
|
| 1103 | + public function qty($context = '') |
|
| 1104 | + { |
|
| 1105 | + switch ($context) { |
|
| 1106 | + case 'reg_limit': |
|
| 1107 | + return $this->real_quantity_on_ticket(); |
|
| 1108 | + case 'saleable': |
|
| 1109 | + return $this->real_quantity_on_ticket('saleable'); |
|
| 1110 | + default: |
|
| 1111 | + return $this->get_raw('TKT_qty'); |
|
| 1112 | + } |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + |
|
| 1116 | + /** |
|
| 1117 | + * Gets ticket quantity |
|
| 1118 | + * |
|
| 1119 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1120 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1121 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1122 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1123 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1124 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1125 | + * set to 0 for all related datetimes |
|
| 1126 | + * @return int |
|
| 1127 | + * @throws EE_Error |
|
| 1128 | + * @throws ReflectionException |
|
| 1129 | + */ |
|
| 1130 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
| 1131 | + { |
|
| 1132 | + $raw = $this->get_raw('TKT_qty'); |
|
| 1133 | + // return immediately if it's zero |
|
| 1134 | + if ($raw === 0) { |
|
| 1135 | + return $raw; |
|
| 1136 | + } |
|
| 1137 | + // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
| 1138 | + // ensure qty doesn't exceed raw value for THIS ticket |
|
| 1139 | + $qty = min(EE_INF, $raw); |
|
| 1140 | + // echo "\n . qty: " . $qty . '<br />'; |
|
| 1141 | + // calculate this ticket's total sales and reservations |
|
| 1142 | + $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
| 1143 | + // echo "\n . sold: " . $this->sold() . '<br />'; |
|
| 1144 | + // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
| 1145 | + // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
| 1146 | + // first we need to calculate the maximum number of tickets available for the datetime |
|
| 1147 | + // do we want data for one datetime or all of them ? |
|
| 1148 | + $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : []; |
|
| 1149 | + $datetimes = $this->datetimes($query_params); |
|
| 1150 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1151 | + foreach ($datetimes as $datetime) { |
|
| 1152 | + if ($datetime instanceof EE_Datetime) { |
|
| 1153 | + $datetime->refresh_from_db(); |
|
| 1154 | + // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
| 1155 | + // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
| 1156 | + // initialize with no restrictions for each datetime |
|
| 1157 | + // but adjust datetime qty based on datetime reg limit |
|
| 1158 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1159 | + // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
| 1160 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1161 | + // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
| 1162 | + // and reservations for this datetime, that do NOT include sales and reservations |
|
| 1163 | + // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
| 1164 | + if ($context === 'saleable') { |
|
| 1165 | + $datetime_qty = max( |
|
| 1166 | + $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
| 1167 | + 0 |
|
| 1168 | + ); |
|
| 1169 | + // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
| 1170 | + // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
| 1171 | + // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
| 1172 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1173 | + $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
| 1174 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1175 | + } |
|
| 1176 | + $qty = min($datetime_qty, $qty); |
|
| 1177 | + // echo "\n . . qty: " . $qty . '<br />'; |
|
| 1178 | + } |
|
| 1179 | + } |
|
| 1180 | + } |
|
| 1181 | + // NOW that we know the maximum number of tickets available for the datetime |
|
| 1182 | + // we can finally factor in the details for this specific ticket |
|
| 1183 | + if ($qty > 0 && $context === 'saleable') { |
|
| 1184 | + // and subtract the sales for THIS ticket |
|
| 1185 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1186 | + // echo "\n . qty: " . $qty . '<br />'; |
|
| 1187 | + } |
|
| 1188 | + // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
| 1189 | + return $qty; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + |
|
| 1193 | + /** |
|
| 1194 | + * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
| 1195 | + * |
|
| 1196 | + * @param int $qty |
|
| 1197 | + * @return void |
|
| 1198 | + * @throws EE_Error |
|
| 1199 | + * @throws ReflectionException |
|
| 1200 | + */ |
|
| 1201 | + public function set_qty($qty) |
|
| 1202 | + { |
|
| 1203 | + $datetimes = $this->datetimes(); |
|
| 1204 | + foreach ($datetimes as $datetime) { |
|
| 1205 | + if ($datetime instanceof EE_Datetime) { |
|
| 1206 | + $qty = min($qty, $datetime->reg_limit()); |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + $this->set('TKT_qty', $qty); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + |
|
| 1213 | + /** |
|
| 1214 | + * Gets uses |
|
| 1215 | + * |
|
| 1216 | + * @return int |
|
| 1217 | + * @throws EE_Error |
|
| 1218 | + * @throws ReflectionException |
|
| 1219 | + */ |
|
| 1220 | + public function uses() |
|
| 1221 | + { |
|
| 1222 | + return $this->get('TKT_uses'); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + |
|
| 1226 | + /** |
|
| 1227 | + * Sets uses |
|
| 1228 | + * |
|
| 1229 | + * @param int $uses |
|
| 1230 | + * @return void |
|
| 1231 | + * @throws EE_Error |
|
| 1232 | + * @throws ReflectionException |
|
| 1233 | + */ |
|
| 1234 | + public function set_uses($uses) |
|
| 1235 | + { |
|
| 1236 | + $this->set('TKT_uses', $uses); |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * returns whether ticket is required or not. |
|
| 1242 | + * |
|
| 1243 | + * @return boolean |
|
| 1244 | + * @throws EE_Error |
|
| 1245 | + * @throws ReflectionException |
|
| 1246 | + */ |
|
| 1247 | + public function required() |
|
| 1248 | + { |
|
| 1249 | + return $this->get('TKT_required'); |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + |
|
| 1253 | + /** |
|
| 1254 | + * sets the TKT_required property |
|
| 1255 | + * |
|
| 1256 | + * @param boolean $required |
|
| 1257 | + * @return void |
|
| 1258 | + * @throws EE_Error |
|
| 1259 | + * @throws ReflectionException |
|
| 1260 | + */ |
|
| 1261 | + public function set_required($required) |
|
| 1262 | + { |
|
| 1263 | + $this->set('TKT_required', $required); |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + |
|
| 1267 | + /** |
|
| 1268 | + * Gets taxable |
|
| 1269 | + * |
|
| 1270 | + * @return boolean |
|
| 1271 | + * @throws EE_Error |
|
| 1272 | + * @throws ReflectionException |
|
| 1273 | + */ |
|
| 1274 | + public function taxable() |
|
| 1275 | + { |
|
| 1276 | + return $this->get('TKT_taxable'); |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * Sets taxable |
|
| 1282 | + * |
|
| 1283 | + * @param boolean $taxable |
|
| 1284 | + * @return void |
|
| 1285 | + * @throws EE_Error |
|
| 1286 | + * @throws ReflectionException |
|
| 1287 | + */ |
|
| 1288 | + public function set_taxable($taxable) |
|
| 1289 | + { |
|
| 1290 | + $this->set('TKT_taxable', $taxable); |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /** |
|
| 1295 | + * Gets is_default |
|
| 1296 | + * |
|
| 1297 | + * @return boolean |
|
| 1298 | + * @throws EE_Error |
|
| 1299 | + * @throws ReflectionException |
|
| 1300 | + */ |
|
| 1301 | + public function is_default() |
|
| 1302 | + { |
|
| 1303 | + return $this->get('TKT_is_default'); |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * Sets is_default |
|
| 1309 | + * |
|
| 1310 | + * @param boolean $is_default |
|
| 1311 | + * @return void |
|
| 1312 | + * @throws EE_Error |
|
| 1313 | + * @throws ReflectionException |
|
| 1314 | + */ |
|
| 1315 | + public function set_is_default($is_default) |
|
| 1316 | + { |
|
| 1317 | + $this->set('TKT_is_default', $is_default); |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * Gets order |
|
| 1323 | + * |
|
| 1324 | + * @return int |
|
| 1325 | + * @throws EE_Error |
|
| 1326 | + * @throws ReflectionException |
|
| 1327 | + */ |
|
| 1328 | + public function order() |
|
| 1329 | + { |
|
| 1330 | + return $this->get('TKT_order'); |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * Sets order |
|
| 1336 | + * |
|
| 1337 | + * @param int $order |
|
| 1338 | + * @return void |
|
| 1339 | + * @throws EE_Error |
|
| 1340 | + * @throws ReflectionException |
|
| 1341 | + */ |
|
| 1342 | + public function set_order($order) |
|
| 1343 | + { |
|
| 1344 | + $this->set('TKT_order', $order); |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + |
|
| 1348 | + /** |
|
| 1349 | + * Gets row |
|
| 1350 | + * |
|
| 1351 | + * @return int |
|
| 1352 | + * @throws EE_Error |
|
| 1353 | + * @throws ReflectionException |
|
| 1354 | + */ |
|
| 1355 | + public function row() |
|
| 1356 | + { |
|
| 1357 | + return $this->get('TKT_row'); |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + |
|
| 1361 | + /** |
|
| 1362 | + * Sets row |
|
| 1363 | + * |
|
| 1364 | + * @param int $row |
|
| 1365 | + * @return void |
|
| 1366 | + * @throws EE_Error |
|
| 1367 | + * @throws ReflectionException |
|
| 1368 | + */ |
|
| 1369 | + public function set_row($row) |
|
| 1370 | + { |
|
| 1371 | + $this->set('TKT_row', $row); |
|
| 1372 | + } |
|
| 1373 | + |
|
| 1374 | + |
|
| 1375 | + /** |
|
| 1376 | + * Gets deleted |
|
| 1377 | + * |
|
| 1378 | + * @return boolean |
|
| 1379 | + * @throws EE_Error |
|
| 1380 | + * @throws ReflectionException |
|
| 1381 | + */ |
|
| 1382 | + public function deleted() |
|
| 1383 | + { |
|
| 1384 | + return $this->get('TKT_deleted'); |
|
| 1385 | + } |
|
| 1386 | + |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * Sets deleted |
|
| 1390 | + * |
|
| 1391 | + * @param boolean $deleted |
|
| 1392 | + * @return void |
|
| 1393 | + * @throws EE_Error |
|
| 1394 | + * @throws ReflectionException |
|
| 1395 | + */ |
|
| 1396 | + public function set_deleted($deleted) |
|
| 1397 | + { |
|
| 1398 | + $this->set('TKT_deleted', $deleted); |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + |
|
| 1402 | + /** |
|
| 1403 | + * Gets parent |
|
| 1404 | + * |
|
| 1405 | + * @return int |
|
| 1406 | + * @throws EE_Error |
|
| 1407 | + * @throws ReflectionException |
|
| 1408 | + */ |
|
| 1409 | + public function parent_ID() |
|
| 1410 | + { |
|
| 1411 | + return $this->get('TKT_parent'); |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + |
|
| 1415 | + /** |
|
| 1416 | + * Sets parent |
|
| 1417 | + * |
|
| 1418 | + * @param int $parent |
|
| 1419 | + * @return void |
|
| 1420 | + * @throws EE_Error |
|
| 1421 | + * @throws ReflectionException |
|
| 1422 | + */ |
|
| 1423 | + public function set_parent_ID($parent) |
|
| 1424 | + { |
|
| 1425 | + $this->set('TKT_parent', $parent); |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1431 | + * |
|
| 1432 | + * @return string |
|
| 1433 | + * @throws EE_Error |
|
| 1434 | + * @throws ReflectionException |
|
| 1435 | + */ |
|
| 1436 | + public function name_and_info() |
|
| 1437 | + { |
|
| 1438 | + $times = []; |
|
| 1439 | + foreach ($this->datetimes() as $datetime) { |
|
| 1440 | + $times[] = $datetime->start_date_and_time(); |
|
| 1441 | + } |
|
| 1442 | + return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1443 | + } |
|
| 1444 | + |
|
| 1445 | + |
|
| 1446 | + /** |
|
| 1447 | + * Gets name |
|
| 1448 | + * |
|
| 1449 | + * @return string |
|
| 1450 | + * @throws EE_Error |
|
| 1451 | + * @throws ReflectionException |
|
| 1452 | + */ |
|
| 1453 | + public function name() |
|
| 1454 | + { |
|
| 1455 | + return $this->get('TKT_name'); |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + |
|
| 1459 | + /** |
|
| 1460 | + * Gets price |
|
| 1461 | + * |
|
| 1462 | + * @return float |
|
| 1463 | + * @throws EE_Error |
|
| 1464 | + * @throws ReflectionException |
|
| 1465 | + */ |
|
| 1466 | + public function price() |
|
| 1467 | + { |
|
| 1468 | + return $this->get('TKT_price'); |
|
| 1469 | + } |
|
| 1470 | + |
|
| 1471 | + |
|
| 1472 | + /** |
|
| 1473 | + * Gets all the registrations for this ticket |
|
| 1474 | + * |
|
| 1475 | + * @param array $query_params @see |
|
| 1476 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1477 | + * @return EE_Registration[]|EE_Base_Class[] |
|
| 1478 | + * @throws EE_Error |
|
| 1479 | + * @throws ReflectionException |
|
| 1480 | + */ |
|
| 1481 | + public function registrations($query_params = []) |
|
| 1482 | + { |
|
| 1483 | + return $this->get_many_related('Registration', $query_params); |
|
| 1484 | + } |
|
| 1485 | + |
|
| 1486 | + |
|
| 1487 | + /** |
|
| 1488 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1489 | + * |
|
| 1490 | + * @return int |
|
| 1491 | + * @throws EE_Error |
|
| 1492 | + * @throws ReflectionException |
|
| 1493 | + */ |
|
| 1494 | + public function update_tickets_sold() |
|
| 1495 | + { |
|
| 1496 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1497 | + [ |
|
| 1498 | + [ |
|
| 1499 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1500 | + 'REG_deleted' => 0, |
|
| 1501 | + ], |
|
| 1502 | + ] |
|
| 1503 | + ); |
|
| 1504 | + $this->set_sold($count_regs_for_this_ticket); |
|
| 1505 | + $this->save(); |
|
| 1506 | + return $count_regs_for_this_ticket; |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + |
|
| 1510 | + /** |
|
| 1511 | + * Counts the registrations for this ticket |
|
| 1512 | + * |
|
| 1513 | + * @param array $query_params @see |
|
| 1514 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1515 | + * @return int |
|
| 1516 | + */ |
|
| 1517 | + public function count_registrations($query_params = []) |
|
| 1518 | + { |
|
| 1519 | + return $this->count_related('Registration', $query_params); |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1525 | + * |
|
| 1526 | + * @return string |
|
| 1527 | + * @see EEI_Visual_Representation for comments |
|
| 1528 | + */ |
|
| 1529 | + public function get_icon() |
|
| 1530 | + { |
|
| 1531 | + return '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
| 1532 | + } |
|
| 1533 | + |
|
| 1534 | + |
|
| 1535 | + /** |
|
| 1536 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1537 | + * |
|
| 1538 | + * @return EE_Event |
|
| 1539 | + * @throws EE_Error |
|
| 1540 | + * @throws UnexpectedEntityException*@throws ReflectionException |
|
| 1541 | + * @see EEI_Event_Relation for comments |
|
| 1542 | + */ |
|
| 1543 | + public function get_related_event() |
|
| 1544 | + { |
|
| 1545 | + // get one datetime to use for getting the event |
|
| 1546 | + $datetime = $this->first_datetime(); |
|
| 1547 | + if (! $datetime instanceof \EE_Datetime) { |
|
| 1548 | + throw new UnexpectedEntityException( |
|
| 1549 | + $datetime, |
|
| 1550 | + 'EE_Datetime', |
|
| 1551 | + sprintf( |
|
| 1552 | + esc_html__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1553 | + $this->name() |
|
| 1554 | + ) |
|
| 1555 | + ); |
|
| 1556 | + } |
|
| 1557 | + $event = $datetime->event(); |
|
| 1558 | + if (! $event instanceof \EE_Event) { |
|
| 1559 | + throw new UnexpectedEntityException( |
|
| 1560 | + $event, |
|
| 1561 | + 'EE_Event', |
|
| 1562 | + sprintf( |
|
| 1563 | + esc_html__('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1564 | + $this->name() |
|
| 1565 | + ) |
|
| 1566 | + ); |
|
| 1567 | + } |
|
| 1568 | + return $event; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + |
|
| 1572 | + /** |
|
| 1573 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1574 | + * |
|
| 1575 | + * @return string |
|
| 1576 | + * @throws UnexpectedEntityException |
|
| 1577 | + * @throws EE_Error*@throws ReflectionException |
|
| 1578 | + * @see EEI_Event_Relation for comments |
|
| 1579 | + */ |
|
| 1580 | + public function get_event_name() |
|
| 1581 | + { |
|
| 1582 | + $event = $this->get_related_event(); |
|
| 1583 | + return $event instanceof EE_Event ? $event->name() : ''; |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + |
|
| 1587 | + /** |
|
| 1588 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1589 | + * |
|
| 1590 | + * @return int |
|
| 1591 | + * @throws UnexpectedEntityException |
|
| 1592 | + * @throws EE_Error*@throws ReflectionException |
|
| 1593 | + * @see EEI_Event_Relation for comments |
|
| 1594 | + */ |
|
| 1595 | + public function get_event_ID() |
|
| 1596 | + { |
|
| 1597 | + $event = $this->get_related_event(); |
|
| 1598 | + return $event instanceof EE_Event ? $event->ID() : 0; |
|
| 1599 | + } |
|
| 1600 | + |
|
| 1601 | + |
|
| 1602 | + /** |
|
| 1603 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1604 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1605 | + * If there are none then it can be permanently deleted. |
|
| 1606 | + * |
|
| 1607 | + * @return bool |
|
| 1608 | + */ |
|
| 1609 | + public function is_permanently_deleteable() |
|
| 1610 | + { |
|
| 1611 | + return $this->count_registrations() === 0; |
|
| 1612 | + } |
|
| 1613 | + |
|
| 1614 | + |
|
| 1615 | + /******************************************************************* |
|
| 1616 | 1616 | *********************** DEPRECATED METHODS ********************** |
| 1617 | 1617 | *******************************************************************/ |
| 1618 | 1618 | |
| 1619 | 1619 | |
| 1620 | - /** |
|
| 1621 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 1622 | - * associated datetimes. |
|
| 1623 | - * |
|
| 1624 | - * @param int $qty |
|
| 1625 | - * @return void |
|
| 1626 | - * @throws EE_Error |
|
| 1627 | - * @throws InvalidArgumentException |
|
| 1628 | - * @throws InvalidDataTypeException |
|
| 1629 | - * @throws InvalidInterfaceException |
|
| 1630 | - * @throws ReflectionException |
|
| 1631 | - * @deprecated 4.9.80.p |
|
| 1632 | - */ |
|
| 1633 | - public function increase_sold($qty = 1) |
|
| 1634 | - { |
|
| 1635 | - EE_Error::doing_it_wrong( |
|
| 1636 | - __FUNCTION__, |
|
| 1637 | - esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
| 1638 | - '4.9.80.p', |
|
| 1639 | - '5.0.0.p' |
|
| 1640 | - ); |
|
| 1641 | - $this->increaseSold($qty); |
|
| 1642 | - } |
|
| 1643 | - |
|
| 1644 | - |
|
| 1645 | - /** |
|
| 1646 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 1647 | - * |
|
| 1648 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
| 1649 | - * Negative means to decreases old counts (and increase reserved counts). |
|
| 1650 | - * @throws EE_Error |
|
| 1651 | - * @throws InvalidArgumentException |
|
| 1652 | - * @throws InvalidDataTypeException |
|
| 1653 | - * @throws InvalidInterfaceException |
|
| 1654 | - * @throws ReflectionException |
|
| 1655 | - * @deprecated 4.9.80.p |
|
| 1656 | - */ |
|
| 1657 | - protected function _increase_sold_for_datetimes($qty) |
|
| 1658 | - { |
|
| 1659 | - EE_Error::doing_it_wrong( |
|
| 1660 | - __FUNCTION__, |
|
| 1661 | - esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1662 | - '4.9.80.p', |
|
| 1663 | - '5.0.0.p' |
|
| 1664 | - ); |
|
| 1665 | - $this->increaseSoldForDatetimes($qty); |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - |
|
| 1669 | - /** |
|
| 1670 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 1671 | - * DB and then updates the model objects. |
|
| 1672 | - * Does not affect the reserved counts. |
|
| 1673 | - * |
|
| 1674 | - * @param int $qty |
|
| 1675 | - * @return void |
|
| 1676 | - * @throws EE_Error |
|
| 1677 | - * @throws InvalidArgumentException |
|
| 1678 | - * @throws InvalidDataTypeException |
|
| 1679 | - * @throws InvalidInterfaceException |
|
| 1680 | - * @throws ReflectionException |
|
| 1681 | - * @deprecated 4.9.80.p |
|
| 1682 | - */ |
|
| 1683 | - public function decrease_sold($qty = 1) |
|
| 1684 | - { |
|
| 1685 | - EE_Error::doing_it_wrong( |
|
| 1686 | - __FUNCTION__, |
|
| 1687 | - esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
| 1688 | - '4.9.80.p', |
|
| 1689 | - '5.0.0.p' |
|
| 1690 | - ); |
|
| 1691 | - $this->decreaseSold($qty); |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - |
|
| 1695 | - /** |
|
| 1696 | - * Decreases sold on related datetimes |
|
| 1697 | - * |
|
| 1698 | - * @param int $qty |
|
| 1699 | - * @return void |
|
| 1700 | - * @throws EE_Error |
|
| 1701 | - * @throws InvalidArgumentException |
|
| 1702 | - * @throws InvalidDataTypeException |
|
| 1703 | - * @throws InvalidInterfaceException |
|
| 1704 | - * @throws ReflectionException |
|
| 1705 | - * @deprecated 4.9.80.p |
|
| 1706 | - */ |
|
| 1707 | - protected function _decrease_sold_for_datetimes($qty = 1) |
|
| 1708 | - { |
|
| 1709 | - EE_Error::doing_it_wrong( |
|
| 1710 | - __FUNCTION__, |
|
| 1711 | - esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1712 | - '4.9.80.p', |
|
| 1713 | - '5.0.0.p' |
|
| 1714 | - ); |
|
| 1715 | - $this->decreaseSoldForDatetimes($qty); |
|
| 1716 | - } |
|
| 1717 | - |
|
| 1718 | - |
|
| 1719 | - /** |
|
| 1720 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1721 | - * |
|
| 1722 | - * @param int $qty |
|
| 1723 | - * @param string $source |
|
| 1724 | - * @return bool whether we successfully reserved the ticket or not. |
|
| 1725 | - * @throws EE_Error |
|
| 1726 | - * @throws InvalidArgumentException |
|
| 1727 | - * @throws ReflectionException |
|
| 1728 | - * @throws InvalidDataTypeException |
|
| 1729 | - * @throws InvalidInterfaceException |
|
| 1730 | - * @deprecated 4.9.80.p |
|
| 1731 | - */ |
|
| 1732 | - public function increase_reserved($qty = 1, $source = 'unknown') |
|
| 1733 | - { |
|
| 1734 | - EE_Error::doing_it_wrong( |
|
| 1735 | - __FUNCTION__, |
|
| 1736 | - esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
| 1737 | - '4.9.80.p', |
|
| 1738 | - '5.0.0.p' |
|
| 1739 | - ); |
|
| 1740 | - return $this->increaseReserved($qty); |
|
| 1741 | - } |
|
| 1742 | - |
|
| 1743 | - |
|
| 1744 | - /** |
|
| 1745 | - * Increases sold on related datetimes |
|
| 1746 | - * |
|
| 1747 | - * @param int $qty |
|
| 1748 | - * @return boolean indicating success |
|
| 1749 | - * @throws EE_Error |
|
| 1750 | - * @throws InvalidArgumentException |
|
| 1751 | - * @throws InvalidDataTypeException |
|
| 1752 | - * @throws InvalidInterfaceException |
|
| 1753 | - * @throws ReflectionException |
|
| 1754 | - * @deprecated 4.9.80.p |
|
| 1755 | - */ |
|
| 1756 | - protected function _increase_reserved_for_datetimes($qty = 1) |
|
| 1757 | - { |
|
| 1758 | - EE_Error::doing_it_wrong( |
|
| 1759 | - __FUNCTION__, |
|
| 1760 | - esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1761 | - '4.9.80.p', |
|
| 1762 | - '5.0.0.p' |
|
| 1763 | - ); |
|
| 1764 | - return $this->increaseReservedForDatetimes($qty); |
|
| 1765 | - } |
|
| 1766 | - |
|
| 1767 | - |
|
| 1768 | - /** |
|
| 1769 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1770 | - * |
|
| 1771 | - * @param int $qty |
|
| 1772 | - * @param bool $adjust_datetimes |
|
| 1773 | - * @param string $source |
|
| 1774 | - * @return void |
|
| 1775 | - * @throws EE_Error |
|
| 1776 | - * @throws InvalidArgumentException |
|
| 1777 | - * @throws ReflectionException |
|
| 1778 | - * @throws InvalidDataTypeException |
|
| 1779 | - * @throws InvalidInterfaceException |
|
| 1780 | - * @deprecated 4.9.80.p |
|
| 1781 | - */ |
|
| 1782 | - public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1783 | - { |
|
| 1784 | - EE_Error::doing_it_wrong( |
|
| 1785 | - __FUNCTION__, |
|
| 1786 | - esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
| 1787 | - '4.9.80.p', |
|
| 1788 | - '5.0.0.p' |
|
| 1789 | - ); |
|
| 1790 | - $this->decreaseReserved($qty); |
|
| 1791 | - } |
|
| 1792 | - |
|
| 1793 | - |
|
| 1794 | - /** |
|
| 1795 | - * Decreases reserved on related datetimes |
|
| 1796 | - * |
|
| 1797 | - * @param int $qty |
|
| 1798 | - * @return void |
|
| 1799 | - * @throws EE_Error |
|
| 1800 | - * @throws InvalidArgumentException |
|
| 1801 | - * @throws ReflectionException |
|
| 1802 | - * @throws InvalidDataTypeException |
|
| 1803 | - * @throws InvalidInterfaceException |
|
| 1804 | - * @deprecated 4.9.80.p |
|
| 1805 | - */ |
|
| 1806 | - protected function _decrease_reserved_for_datetimes($qty = 1) |
|
| 1807 | - { |
|
| 1808 | - EE_Error::doing_it_wrong( |
|
| 1809 | - __FUNCTION__, |
|
| 1810 | - esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1811 | - '4.9.80.p', |
|
| 1812 | - '5.0.0.p' |
|
| 1813 | - ); |
|
| 1814 | - $this->decreaseReservedForDatetimes($qty); |
|
| 1815 | - } |
|
| 1620 | + /** |
|
| 1621 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 1622 | + * associated datetimes. |
|
| 1623 | + * |
|
| 1624 | + * @param int $qty |
|
| 1625 | + * @return void |
|
| 1626 | + * @throws EE_Error |
|
| 1627 | + * @throws InvalidArgumentException |
|
| 1628 | + * @throws InvalidDataTypeException |
|
| 1629 | + * @throws InvalidInterfaceException |
|
| 1630 | + * @throws ReflectionException |
|
| 1631 | + * @deprecated 4.9.80.p |
|
| 1632 | + */ |
|
| 1633 | + public function increase_sold($qty = 1) |
|
| 1634 | + { |
|
| 1635 | + EE_Error::doing_it_wrong( |
|
| 1636 | + __FUNCTION__, |
|
| 1637 | + esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
| 1638 | + '4.9.80.p', |
|
| 1639 | + '5.0.0.p' |
|
| 1640 | + ); |
|
| 1641 | + $this->increaseSold($qty); |
|
| 1642 | + } |
|
| 1643 | + |
|
| 1644 | + |
|
| 1645 | + /** |
|
| 1646 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 1647 | + * |
|
| 1648 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
| 1649 | + * Negative means to decreases old counts (and increase reserved counts). |
|
| 1650 | + * @throws EE_Error |
|
| 1651 | + * @throws InvalidArgumentException |
|
| 1652 | + * @throws InvalidDataTypeException |
|
| 1653 | + * @throws InvalidInterfaceException |
|
| 1654 | + * @throws ReflectionException |
|
| 1655 | + * @deprecated 4.9.80.p |
|
| 1656 | + */ |
|
| 1657 | + protected function _increase_sold_for_datetimes($qty) |
|
| 1658 | + { |
|
| 1659 | + EE_Error::doing_it_wrong( |
|
| 1660 | + __FUNCTION__, |
|
| 1661 | + esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1662 | + '4.9.80.p', |
|
| 1663 | + '5.0.0.p' |
|
| 1664 | + ); |
|
| 1665 | + $this->increaseSoldForDatetimes($qty); |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + |
|
| 1669 | + /** |
|
| 1670 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 1671 | + * DB and then updates the model objects. |
|
| 1672 | + * Does not affect the reserved counts. |
|
| 1673 | + * |
|
| 1674 | + * @param int $qty |
|
| 1675 | + * @return void |
|
| 1676 | + * @throws EE_Error |
|
| 1677 | + * @throws InvalidArgumentException |
|
| 1678 | + * @throws InvalidDataTypeException |
|
| 1679 | + * @throws InvalidInterfaceException |
|
| 1680 | + * @throws ReflectionException |
|
| 1681 | + * @deprecated 4.9.80.p |
|
| 1682 | + */ |
|
| 1683 | + public function decrease_sold($qty = 1) |
|
| 1684 | + { |
|
| 1685 | + EE_Error::doing_it_wrong( |
|
| 1686 | + __FUNCTION__, |
|
| 1687 | + esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
| 1688 | + '4.9.80.p', |
|
| 1689 | + '5.0.0.p' |
|
| 1690 | + ); |
|
| 1691 | + $this->decreaseSold($qty); |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + |
|
| 1695 | + /** |
|
| 1696 | + * Decreases sold on related datetimes |
|
| 1697 | + * |
|
| 1698 | + * @param int $qty |
|
| 1699 | + * @return void |
|
| 1700 | + * @throws EE_Error |
|
| 1701 | + * @throws InvalidArgumentException |
|
| 1702 | + * @throws InvalidDataTypeException |
|
| 1703 | + * @throws InvalidInterfaceException |
|
| 1704 | + * @throws ReflectionException |
|
| 1705 | + * @deprecated 4.9.80.p |
|
| 1706 | + */ |
|
| 1707 | + protected function _decrease_sold_for_datetimes($qty = 1) |
|
| 1708 | + { |
|
| 1709 | + EE_Error::doing_it_wrong( |
|
| 1710 | + __FUNCTION__, |
|
| 1711 | + esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1712 | + '4.9.80.p', |
|
| 1713 | + '5.0.0.p' |
|
| 1714 | + ); |
|
| 1715 | + $this->decreaseSoldForDatetimes($qty); |
|
| 1716 | + } |
|
| 1717 | + |
|
| 1718 | + |
|
| 1719 | + /** |
|
| 1720 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1721 | + * |
|
| 1722 | + * @param int $qty |
|
| 1723 | + * @param string $source |
|
| 1724 | + * @return bool whether we successfully reserved the ticket or not. |
|
| 1725 | + * @throws EE_Error |
|
| 1726 | + * @throws InvalidArgumentException |
|
| 1727 | + * @throws ReflectionException |
|
| 1728 | + * @throws InvalidDataTypeException |
|
| 1729 | + * @throws InvalidInterfaceException |
|
| 1730 | + * @deprecated 4.9.80.p |
|
| 1731 | + */ |
|
| 1732 | + public function increase_reserved($qty = 1, $source = 'unknown') |
|
| 1733 | + { |
|
| 1734 | + EE_Error::doing_it_wrong( |
|
| 1735 | + __FUNCTION__, |
|
| 1736 | + esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
| 1737 | + '4.9.80.p', |
|
| 1738 | + '5.0.0.p' |
|
| 1739 | + ); |
|
| 1740 | + return $this->increaseReserved($qty); |
|
| 1741 | + } |
|
| 1742 | + |
|
| 1743 | + |
|
| 1744 | + /** |
|
| 1745 | + * Increases sold on related datetimes |
|
| 1746 | + * |
|
| 1747 | + * @param int $qty |
|
| 1748 | + * @return boolean indicating success |
|
| 1749 | + * @throws EE_Error |
|
| 1750 | + * @throws InvalidArgumentException |
|
| 1751 | + * @throws InvalidDataTypeException |
|
| 1752 | + * @throws InvalidInterfaceException |
|
| 1753 | + * @throws ReflectionException |
|
| 1754 | + * @deprecated 4.9.80.p |
|
| 1755 | + */ |
|
| 1756 | + protected function _increase_reserved_for_datetimes($qty = 1) |
|
| 1757 | + { |
|
| 1758 | + EE_Error::doing_it_wrong( |
|
| 1759 | + __FUNCTION__, |
|
| 1760 | + esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1761 | + '4.9.80.p', |
|
| 1762 | + '5.0.0.p' |
|
| 1763 | + ); |
|
| 1764 | + return $this->increaseReservedForDatetimes($qty); |
|
| 1765 | + } |
|
| 1766 | + |
|
| 1767 | + |
|
| 1768 | + /** |
|
| 1769 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1770 | + * |
|
| 1771 | + * @param int $qty |
|
| 1772 | + * @param bool $adjust_datetimes |
|
| 1773 | + * @param string $source |
|
| 1774 | + * @return void |
|
| 1775 | + * @throws EE_Error |
|
| 1776 | + * @throws InvalidArgumentException |
|
| 1777 | + * @throws ReflectionException |
|
| 1778 | + * @throws InvalidDataTypeException |
|
| 1779 | + * @throws InvalidInterfaceException |
|
| 1780 | + * @deprecated 4.9.80.p |
|
| 1781 | + */ |
|
| 1782 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1783 | + { |
|
| 1784 | + EE_Error::doing_it_wrong( |
|
| 1785 | + __FUNCTION__, |
|
| 1786 | + esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
| 1787 | + '4.9.80.p', |
|
| 1788 | + '5.0.0.p' |
|
| 1789 | + ); |
|
| 1790 | + $this->decreaseReserved($qty); |
|
| 1791 | + } |
|
| 1792 | + |
|
| 1793 | + |
|
| 1794 | + /** |
|
| 1795 | + * Decreases reserved on related datetimes |
|
| 1796 | + * |
|
| 1797 | + * @param int $qty |
|
| 1798 | + * @return void |
|
| 1799 | + * @throws EE_Error |
|
| 1800 | + * @throws InvalidArgumentException |
|
| 1801 | + * @throws ReflectionException |
|
| 1802 | + * @throws InvalidDataTypeException |
|
| 1803 | + * @throws InvalidInterfaceException |
|
| 1804 | + * @deprecated 4.9.80.p |
|
| 1805 | + */ |
|
| 1806 | + protected function _decrease_reserved_for_datetimes($qty = 1) |
|
| 1807 | + { |
|
| 1808 | + EE_Error::doing_it_wrong( |
|
| 1809 | + __FUNCTION__, |
|
| 1810 | + esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1811 | + '4.9.80.p', |
|
| 1812 | + '5.0.0.p' |
|
| 1813 | + ); |
|
| 1814 | + $this->decreaseReservedForDatetimes($qty); |
|
| 1815 | + } |
|
| 1816 | 1816 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | public function ticket_status($display = false, $remaining = null) |
| 135 | 135 | { |
| 136 | 136 | $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
| 137 | - if (! $remaining) { |
|
| 137 | + if ( ! $remaining) { |
|
| 138 | 138 | return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
| 139 | 139 | } |
| 140 | 140 | if ($this->get('TKT_deleted')) { |
@@ -259,13 +259,13 @@ discard block |
||
| 259 | 259 | 'DTT_EVT_start', |
| 260 | 260 | $dt_frmt |
| 261 | 261 | ) : ''; |
| 262 | - $last_date = |
|
| 262 | + $last_date = |
|
| 263 | 263 | $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->get_i18n_datetime( |
| 264 | 264 | 'DTT_EVT_end', |
| 265 | 265 | $dt_frmt |
| 266 | 266 | ) : ''; |
| 267 | 267 | |
| 268 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 268 | + return $first_date && $last_date ? $first_date.$conjunction.$last_date : ''; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | public function datetimes($query_params = []) |
| 296 | 296 | { |
| 297 | - if (! isset($query_params['order_by'])) { |
|
| 297 | + if ( ! isset($query_params['order_by'])) { |
|
| 298 | 298 | $query_params['order_by']['DTT_order'] = 'ASC'; |
| 299 | 299 | } |
| 300 | 300 | return $this->get_many_related('Datetime', $query_params); |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | if (empty($tickets_sold['datetime'])) { |
| 340 | 340 | return $total; |
| 341 | 341 | } |
| 342 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 342 | + if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) { |
|
| 343 | 343 | EE_Error::add_error( |
| 344 | 344 | esc_html__( |
| 345 | 345 | 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | ); |
| 352 | 352 | return $total; |
| 353 | 353 | } |
| 354 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 354 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id]; |
|
| 355 | 355 | break; |
| 356 | 356 | default: |
| 357 | 357 | return $total; |
@@ -370,9 +370,9 @@ discard block |
||
| 370 | 370 | { |
| 371 | 371 | $datetimes = $this->get_many_related('Datetime'); |
| 372 | 372 | $tickets_sold = []; |
| 373 | - if (! empty($datetimes)) { |
|
| 373 | + if ( ! empty($datetimes)) { |
|
| 374 | 374 | foreach ($datetimes as $datetime) { |
| 375 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 375 | + $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold'); |
|
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | // Tickets sold |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | 'TKT_qty', |
| 971 | 971 | $qty |
| 972 | 972 | ); |
| 973 | - if (! $success) { |
|
| 973 | + if ( ! $success) { |
|
| 974 | 974 | // The datetimes were successfully bumped, but not the |
| 975 | 975 | // ticket. So we need to manually rollback the datetimes. |
| 976 | 976 | $this->decreaseReservedForDatetimes($qty); |
@@ -1439,7 +1439,7 @@ discard block |
||
| 1439 | 1439 | foreach ($this->datetimes() as $datetime) { |
| 1440 | 1440 | $times[] = $datetime->start_date_and_time(); |
| 1441 | 1441 | } |
| 1442 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1442 | + return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price(); |
|
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | |
@@ -1544,7 +1544,7 @@ discard block |
||
| 1544 | 1544 | { |
| 1545 | 1545 | // get one datetime to use for getting the event |
| 1546 | 1546 | $datetime = $this->first_datetime(); |
| 1547 | - if (! $datetime instanceof \EE_Datetime) { |
|
| 1547 | + if ( ! $datetime instanceof \EE_Datetime) { |
|
| 1548 | 1548 | throw new UnexpectedEntityException( |
| 1549 | 1549 | $datetime, |
| 1550 | 1550 | 'EE_Datetime', |
@@ -1555,7 +1555,7 @@ discard block |
||
| 1555 | 1555 | ); |
| 1556 | 1556 | } |
| 1557 | 1557 | $event = $datetime->event(); |
| 1558 | - if (! $event instanceof \EE_Event) { |
|
| 1558 | + if ( ! $event instanceof \EE_Event) { |
|
| 1559 | 1559 | throw new UnexpectedEntityException( |
| 1560 | 1560 | $event, |
| 1561 | 1561 | 'EE_Event', |
@@ -18,4187 +18,4187 @@ |
||
| 18 | 18 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var LoaderInterface |
|
| 23 | - */ |
|
| 24 | - protected $loader; |
|
| 21 | + /** |
|
| 22 | + * @var LoaderInterface |
|
| 23 | + */ |
|
| 24 | + protected $loader; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var RequestInterface |
|
| 28 | - */ |
|
| 29 | - protected $request; |
|
| 26 | + /** |
|
| 27 | + * @var RequestInterface |
|
| 28 | + */ |
|
| 29 | + protected $request; |
|
| 30 | 30 | |
| 31 | - // set in _init_page_props() |
|
| 32 | - public $page_slug; |
|
| 31 | + // set in _init_page_props() |
|
| 32 | + public $page_slug; |
|
| 33 | 33 | |
| 34 | - public $page_label; |
|
| 34 | + public $page_label; |
|
| 35 | 35 | |
| 36 | - public $page_folder; |
|
| 36 | + public $page_folder; |
|
| 37 | 37 | |
| 38 | - // set in define_page_props() |
|
| 39 | - protected $_admin_base_url; |
|
| 38 | + // set in define_page_props() |
|
| 39 | + protected $_admin_base_url; |
|
| 40 | 40 | |
| 41 | - protected $_admin_base_path; |
|
| 41 | + protected $_admin_base_path; |
|
| 42 | 42 | |
| 43 | - protected $_admin_page_title; |
|
| 43 | + protected $_admin_page_title; |
|
| 44 | 44 | |
| 45 | - protected $_labels; |
|
| 45 | + protected $_labels; |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - // set early within EE_Admin_Init |
|
| 49 | - protected $_wp_page_slug; |
|
| 48 | + // set early within EE_Admin_Init |
|
| 49 | + protected $_wp_page_slug; |
|
| 50 | 50 | |
| 51 | - // navtabs |
|
| 52 | - protected $_nav_tabs; |
|
| 51 | + // navtabs |
|
| 52 | + protected $_nav_tabs; |
|
| 53 | 53 | |
| 54 | - protected $_default_nav_tab_name; |
|
| 54 | + protected $_default_nav_tab_name; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var array $_help_tour |
|
| 58 | - */ |
|
| 59 | - protected $_help_tour = []; |
|
| 56 | + /** |
|
| 57 | + * @var array $_help_tour |
|
| 58 | + */ |
|
| 59 | + protected $_help_tour = []; |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - // template variables (used by templates) |
|
| 63 | - protected $_template_path; |
|
| 62 | + // template variables (used by templates) |
|
| 63 | + protected $_template_path; |
|
| 64 | 64 | |
| 65 | - protected $_column_template_path; |
|
| 65 | + protected $_column_template_path; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @var array $_template_args |
|
| 69 | - */ |
|
| 70 | - protected $_template_args = []; |
|
| 67 | + /** |
|
| 68 | + * @var array $_template_args |
|
| 69 | + */ |
|
| 70 | + protected $_template_args = []; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * this will hold the list table object for a given view. |
|
| 74 | - * |
|
| 75 | - * @var EE_Admin_List_Table $_list_table_object |
|
| 76 | - */ |
|
| 77 | - protected $_list_table_object; |
|
| 72 | + /** |
|
| 73 | + * this will hold the list table object for a given view. |
|
| 74 | + * |
|
| 75 | + * @var EE_Admin_List_Table $_list_table_object |
|
| 76 | + */ |
|
| 77 | + protected $_list_table_object; |
|
| 78 | 78 | |
| 79 | - // bools |
|
| 80 | - protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 79 | + // bools |
|
| 80 | + protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
| 81 | 81 | |
| 82 | - protected $_routing; |
|
| 82 | + protected $_routing; |
|
| 83 | 83 | |
| 84 | - // list table args |
|
| 85 | - protected $_view; |
|
| 84 | + // list table args |
|
| 85 | + protected $_view; |
|
| 86 | 86 | |
| 87 | - protected $_views; |
|
| 87 | + protected $_views; |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - // action => method pairs used for routing incoming requests |
|
| 91 | - protected $_page_routes; |
|
| 90 | + // action => method pairs used for routing incoming requests |
|
| 91 | + protected $_page_routes; |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @var array $_page_config |
|
| 95 | - */ |
|
| 96 | - protected $_page_config; |
|
| 93 | + /** |
|
| 94 | + * @var array $_page_config |
|
| 95 | + */ |
|
| 96 | + protected $_page_config; |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * the current page route and route config |
|
| 100 | - * |
|
| 101 | - * @var string $_route |
|
| 102 | - */ |
|
| 103 | - protected $_route; |
|
| 98 | + /** |
|
| 99 | + * the current page route and route config |
|
| 100 | + * |
|
| 101 | + * @var string $_route |
|
| 102 | + */ |
|
| 103 | + protected $_route; |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @var string $_cpt_route |
|
| 107 | - */ |
|
| 108 | - protected $_cpt_route; |
|
| 105 | + /** |
|
| 106 | + * @var string $_cpt_route |
|
| 107 | + */ |
|
| 108 | + protected $_cpt_route; |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * @var array $_route_config |
|
| 112 | - */ |
|
| 113 | - protected $_route_config; |
|
| 110 | + /** |
|
| 111 | + * @var array $_route_config |
|
| 112 | + */ |
|
| 113 | + protected $_route_config; |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 117 | - * actions. |
|
| 118 | - * |
|
| 119 | - * @since 4.6.x |
|
| 120 | - * @var array. |
|
| 121 | - */ |
|
| 122 | - protected $_default_route_query_args; |
|
| 123 | - |
|
| 124 | - // set via request page and action args. |
|
| 125 | - protected $_current_page; |
|
| 126 | - |
|
| 127 | - protected $_current_view; |
|
| 128 | - |
|
| 129 | - protected $_current_page_view_url; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * unprocessed value for the 'action' request param (default '') |
|
| 133 | - * |
|
| 134 | - * @var string |
|
| 135 | - */ |
|
| 136 | - protected $raw_req_action = ''; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * unprocessed value for the 'page' request param (default '') |
|
| 140 | - * |
|
| 141 | - * @var string |
|
| 142 | - */ |
|
| 143 | - protected $raw_req_page = ''; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * sanitized request action (and nonce) |
|
| 147 | - * |
|
| 148 | - * @var string |
|
| 149 | - */ |
|
| 150 | - protected $_req_action = ''; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * sanitized request action nonce |
|
| 154 | - * |
|
| 155 | - * @var string |
|
| 156 | - */ |
|
| 157 | - protected $_req_nonce = ''; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @var string |
|
| 161 | - */ |
|
| 162 | - protected $_search_btn_label = ''; |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @var string |
|
| 166 | - */ |
|
| 167 | - protected $_search_box_callback = ''; |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @var WP_Screen |
|
| 171 | - */ |
|
| 172 | - protected $_current_screen; |
|
| 173 | - |
|
| 174 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 175 | - protected $_hook_obj; |
|
| 176 | - |
|
| 177 | - // for holding incoming request data |
|
| 178 | - protected $_req_data = []; |
|
| 179 | - |
|
| 180 | - // yes / no array for admin form fields |
|
| 181 | - protected $_yes_no_values = []; |
|
| 182 | - |
|
| 183 | - // some default things shared by all child classes |
|
| 184 | - protected $_default_espresso_metaboxes; |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @var EE_Registry |
|
| 188 | - */ |
|
| 189 | - protected $EE = null; |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 194 | - * |
|
| 195 | - * @var boolean |
|
| 196 | - */ |
|
| 197 | - protected $_is_caf = false; |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @Constructor |
|
| 202 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 203 | - * @throws EE_Error |
|
| 204 | - * @throws InvalidArgumentException |
|
| 205 | - * @throws ReflectionException |
|
| 206 | - * @throws InvalidDataTypeException |
|
| 207 | - * @throws InvalidInterfaceException |
|
| 208 | - */ |
|
| 209 | - public function __construct($routing = true) |
|
| 210 | - { |
|
| 211 | - $this->loader = LoaderFactory::getLoader(); |
|
| 212 | - $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 213 | - $this->_routing = $routing; |
|
| 214 | - |
|
| 215 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 216 | - $this->_is_caf = true; |
|
| 217 | - } |
|
| 218 | - $this->_yes_no_values = [ |
|
| 219 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 220 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 221 | - ]; |
|
| 222 | - // set the _req_data property. |
|
| 223 | - $this->_req_data = $this->request->requestParams(); |
|
| 224 | - // set initial page props (child method) |
|
| 225 | - $this->_init_page_props(); |
|
| 226 | - // set global defaults |
|
| 227 | - $this->_set_defaults(); |
|
| 228 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 229 | - $this->_global_ajax_hooks(); |
|
| 230 | - $this->_ajax_hooks(); |
|
| 231 | - // other_page_hooks have to be early too. |
|
| 232 | - $this->_do_other_page_hooks(); |
|
| 233 | - // set up page dependencies |
|
| 234 | - $this->_before_page_setup(); |
|
| 235 | - $this->_page_setup(); |
|
| 236 | - // die(); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * _init_page_props |
|
| 242 | - * Child classes use to set at least the following properties: |
|
| 243 | - * $page_slug. |
|
| 244 | - * $page_label. |
|
| 245 | - * |
|
| 246 | - * @abstract |
|
| 247 | - * @return void |
|
| 248 | - */ |
|
| 249 | - abstract protected function _init_page_props(); |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * _ajax_hooks |
|
| 254 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 255 | - * Note: within the ajax callback methods. |
|
| 256 | - * |
|
| 257 | - * @abstract |
|
| 258 | - * @return void |
|
| 259 | - */ |
|
| 260 | - abstract protected function _ajax_hooks(); |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * _define_page_props |
|
| 265 | - * child classes define page properties in here. Must include at least: |
|
| 266 | - * $_admin_base_url = base_url for all admin pages |
|
| 267 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 268 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 269 | - * array( |
|
| 270 | - * 'buttons' => array( |
|
| 271 | - * 'add' => esc_html__('label for add new button'), |
|
| 272 | - * 'edit' => esc_html__('label for edit button'), |
|
| 273 | - * 'delete' => esc_html__('label for delete button') |
|
| 274 | - * ) |
|
| 275 | - * ) |
|
| 276 | - * |
|
| 277 | - * @abstract |
|
| 278 | - * @return void |
|
| 279 | - */ |
|
| 280 | - abstract protected function _define_page_props(); |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * _set_page_routes |
|
| 285 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 286 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 287 | - * have a 'default' route. Here's the format |
|
| 288 | - * $this->_page_routes = array( |
|
| 289 | - * 'default' => array( |
|
| 290 | - * 'func' => '_default_method_handling_route', |
|
| 291 | - * 'args' => array('array','of','args'), |
|
| 292 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 293 | - * ajax request, backend processing) |
|
| 294 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 295 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 296 | - * headers sent route. |
|
| 297 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 298 | - * this route. |
|
| 299 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 300 | - * checks). |
|
| 301 | - * ), |
|
| 302 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 303 | - * handling method. |
|
| 304 | - * ) |
|
| 305 | - * ) |
|
| 306 | - * |
|
| 307 | - * @abstract |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - abstract protected function _set_page_routes(); |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * _set_page_config |
|
| 315 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 316 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 317 | - * $this->_page_config = array( |
|
| 318 | - * 'default' => array( |
|
| 319 | - * 'labels' => array( |
|
| 320 | - * 'buttons' => array( |
|
| 321 | - * 'add' => esc_html__('label for adding item'), |
|
| 322 | - * 'edit' => esc_html__('label for editing item'), |
|
| 323 | - * 'delete' => esc_html__('label for deleting item') |
|
| 324 | - * ), |
|
| 325 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 326 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 327 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 328 | - * _define_page_props() method |
|
| 329 | - * 'nav' => array( |
|
| 330 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 331 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 332 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 333 | - * 'order' => 10, //required to indicate tab position. |
|
| 334 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 335 | - * displayed then add this parameter. |
|
| 336 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 337 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 338 | - * metaboxes set for eventespresso admin pages. |
|
| 339 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 340 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 341 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 342 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 343 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 344 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 345 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 346 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 347 | - * want to display. |
|
| 348 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 349 | - * 'tab_id' => array( |
|
| 350 | - * 'title' => 'tab_title', |
|
| 351 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 352 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 353 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 354 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 355 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 356 | - * attempt to use the callback which should match the name of a method in the class |
|
| 357 | - * ), |
|
| 358 | - * 'tab2_id' => array( |
|
| 359 | - * 'title' => 'tab2 title', |
|
| 360 | - * 'filename' => 'file_name_2' |
|
| 361 | - * 'callback' => 'callback_method_for_content', |
|
| 362 | - * ), |
|
| 363 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 364 | - * help tab area on an admin page. @return void |
|
| 365 | - * |
|
| 366 | - * @link |
|
| 367 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 368 | - * 'help_tour' => array( |
|
| 369 | - * 'name_of_help_tour_class', //all help tours should be a child class of EE_Help_Tour and located |
|
| 370 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 371 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 372 | - * ), |
|
| 373 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default |
|
| 374 | - * is true if it isn't present). To remove the requirement for a nonce check when this route is |
|
| 375 | - * visited just set |
|
| 376 | - * 'require_nonce' to FALSE |
|
| 377 | - * ) |
|
| 378 | - * ) |
|
| 379 | - * |
|
| 380 | - * @abstract |
|
| 381 | - */ |
|
| 382 | - abstract protected function _set_page_config(); |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** end sample help_tour methods **/ |
|
| 389 | - /** |
|
| 390 | - * _add_screen_options |
|
| 391 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 392 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 393 | - * to a particular view. |
|
| 394 | - * |
|
| 395 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 396 | - * see also WP_Screen object documents... |
|
| 397 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 398 | - * @abstract |
|
| 399 | - * @return void |
|
| 400 | - */ |
|
| 401 | - abstract protected function _add_screen_options(); |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * _add_feature_pointers |
|
| 406 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 407 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 408 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 409 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 410 | - * extended) also see: |
|
| 411 | - * |
|
| 412 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 413 | - * @abstract |
|
| 414 | - * @return void |
|
| 415 | - */ |
|
| 416 | - abstract protected function _add_feature_pointers(); |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * load_scripts_styles |
|
| 421 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 422 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 423 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 424 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 425 | - * |
|
| 426 | - * @abstract |
|
| 427 | - * @return void |
|
| 428 | - */ |
|
| 429 | - abstract public function load_scripts_styles(); |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * admin_init |
|
| 434 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 435 | - * all pages/views loaded by child class. |
|
| 436 | - * |
|
| 437 | - * @abstract |
|
| 438 | - * @return void |
|
| 439 | - */ |
|
| 440 | - abstract public function admin_init(); |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * admin_notices |
|
| 445 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 446 | - * all pages/views loaded by child class. |
|
| 447 | - * |
|
| 448 | - * @abstract |
|
| 449 | - * @return void |
|
| 450 | - */ |
|
| 451 | - abstract public function admin_notices(); |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * admin_footer_scripts |
|
| 456 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 457 | - * will apply to all pages/views loaded by child class. |
|
| 458 | - * |
|
| 459 | - * @return void |
|
| 460 | - */ |
|
| 461 | - abstract public function admin_footer_scripts(); |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * admin_footer |
|
| 466 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 467 | - * apply to all pages/views loaded by child class. |
|
| 468 | - * |
|
| 469 | - * @return void |
|
| 470 | - */ |
|
| 471 | - public function admin_footer() |
|
| 472 | - { |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * _global_ajax_hooks |
|
| 478 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 479 | - * Note: within the ajax callback methods. |
|
| 480 | - * |
|
| 481 | - * @abstract |
|
| 482 | - * @return void |
|
| 483 | - */ |
|
| 484 | - protected function _global_ajax_hooks() |
|
| 485 | - { |
|
| 486 | - // for lazy loading of metabox content |
|
| 487 | - add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - public function ajax_metabox_content() |
|
| 492 | - { |
|
| 493 | - $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 494 | - $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 495 | - self::cached_rss_display($content_id, $content_url); |
|
| 496 | - wp_die(); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 502 | - * |
|
| 503 | - * @return void |
|
| 504 | - */ |
|
| 505 | - protected function _before_page_setup() |
|
| 506 | - { |
|
| 507 | - // default is to do nothing |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Makes sure any things that need to be loaded early get handled. |
|
| 513 | - * We also escape early here if the page requested doesn't match the object. |
|
| 514 | - * |
|
| 515 | - * @final |
|
| 516 | - * @return void |
|
| 517 | - * @throws EE_Error |
|
| 518 | - * @throws InvalidArgumentException |
|
| 519 | - * @throws ReflectionException |
|
| 520 | - * @throws InvalidDataTypeException |
|
| 521 | - * @throws InvalidInterfaceException |
|
| 522 | - */ |
|
| 523 | - final protected function _page_setup() |
|
| 524 | - { |
|
| 525 | - // requires? |
|
| 526 | - // admin_init stuff - global - we're setting this REALLY early |
|
| 527 | - // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 528 | - // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 529 | - add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 530 | - // next verify if we need to load anything... |
|
| 531 | - $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 532 | - $this->page_folder = strtolower( |
|
| 533 | - str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
| 534 | - ); |
|
| 535 | - global $ee_menu_slugs; |
|
| 536 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 537 | - if ( |
|
| 538 | - ! $this->request->isAjax() |
|
| 539 | - && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 540 | - ) { |
|
| 541 | - return; |
|
| 542 | - } |
|
| 543 | - // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 544 | - // we need to copy the action from the second to the first |
|
| 545 | - $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 546 | - $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 547 | - $action = $action !== '-1' ? $action : $action2; |
|
| 548 | - $req_action = $action !== '-1' ? $action : 'default'; |
|
| 549 | - |
|
| 550 | - // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 551 | - // then let's use the route as the action. |
|
| 552 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 553 | - $route = $this->request->getRequestParam('route'); |
|
| 554 | - $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 555 | - ? $route |
|
| 556 | - : $req_action; |
|
| 557 | - |
|
| 558 | - $this->_current_view = $this->_req_action; |
|
| 559 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 560 | - $this->_define_page_props(); |
|
| 561 | - $this->_current_page_view_url = add_query_arg( |
|
| 562 | - ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 563 | - $this->_admin_base_url |
|
| 564 | - ); |
|
| 565 | - // default things |
|
| 566 | - $this->_default_espresso_metaboxes = [ |
|
| 567 | - '_espresso_news_post_box', |
|
| 568 | - '_espresso_links_post_box', |
|
| 569 | - '_espresso_ratings_request', |
|
| 570 | - '_espresso_sponsors_post_box', |
|
| 571 | - ]; |
|
| 572 | - // set page configs |
|
| 573 | - $this->_set_page_routes(); |
|
| 574 | - $this->_set_page_config(); |
|
| 575 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 576 | - if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 577 | - $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 578 | - if ($wp_referer) { |
|
| 579 | - $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - // for caffeinated and other extended functionality. |
|
| 583 | - // If there is a _extend_page_config method |
|
| 584 | - // then let's run that to modify the all the various page configuration arrays |
|
| 585 | - if (method_exists($this, '_extend_page_config')) { |
|
| 586 | - $this->_extend_page_config(); |
|
| 587 | - } |
|
| 588 | - // for CPT and other extended functionality. |
|
| 589 | - // If there is an _extend_page_config_for_cpt |
|
| 590 | - // then let's run that to modify all the various page configuration arrays. |
|
| 591 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 592 | - $this->_extend_page_config_for_cpt(); |
|
| 593 | - } |
|
| 594 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 595 | - $this->_page_routes = apply_filters( |
|
| 596 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 597 | - $this->_page_routes, |
|
| 598 | - $this |
|
| 599 | - ); |
|
| 600 | - $this->_page_config = apply_filters( |
|
| 601 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 602 | - $this->_page_config, |
|
| 603 | - $this |
|
| 604 | - ); |
|
| 605 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 606 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 607 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 608 | - add_action( |
|
| 609 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 610 | - [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 611 | - 10, |
|
| 612 | - 2 |
|
| 613 | - ); |
|
| 614 | - } |
|
| 615 | - // next route only if routing enabled |
|
| 616 | - if ($this->_routing && ! $this->request->isAjax()) { |
|
| 617 | - $this->_verify_routes(); |
|
| 618 | - // next let's just check user_access and kill if no access |
|
| 619 | - $this->check_user_access(); |
|
| 620 | - if ($this->_is_UI_request) { |
|
| 621 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 622 | - add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 623 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 624 | - add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 625 | - } |
|
| 626 | - } else { |
|
| 627 | - // hijack regular WP loading and route admin request immediately |
|
| 628 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 629 | - $this->route_admin_request(); |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 637 | - * |
|
| 638 | - * @return void |
|
| 639 | - * @throws EE_Error |
|
| 640 | - */ |
|
| 641 | - private function _do_other_page_hooks() |
|
| 642 | - { |
|
| 643 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 644 | - foreach ($registered_pages as $page) { |
|
| 645 | - // now let's setup the file name and class that should be present |
|
| 646 | - $classname = str_replace('.class.php', '', $page); |
|
| 647 | - // autoloaders should take care of loading file |
|
| 648 | - if (! class_exists($classname)) { |
|
| 649 | - $error_msg[] = sprintf( |
|
| 650 | - esc_html__( |
|
| 651 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 652 | - 'event_espresso' |
|
| 653 | - ), |
|
| 654 | - $page |
|
| 655 | - ); |
|
| 656 | - $error_msg[] = $error_msg[0] |
|
| 657 | - . "\r\n" |
|
| 658 | - . sprintf( |
|
| 659 | - esc_html__( |
|
| 660 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 661 | - 'event_espresso' |
|
| 662 | - ), |
|
| 663 | - $page, |
|
| 664 | - '<br />', |
|
| 665 | - '<strong>' . $classname . '</strong>' |
|
| 666 | - ); |
|
| 667 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 668 | - } |
|
| 669 | - // notice we are passing the instance of this class to the hook object. |
|
| 670 | - $this->loader->getShared($classname, [$this]); |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * @throws ReflectionException |
|
| 677 | - * @throws EE_Error |
|
| 678 | - */ |
|
| 679 | - public function load_page_dependencies() |
|
| 680 | - { |
|
| 681 | - try { |
|
| 682 | - $this->_load_page_dependencies(); |
|
| 683 | - } catch (EE_Error $e) { |
|
| 684 | - $e->get_error(); |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * load_page_dependencies |
|
| 691 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 692 | - * |
|
| 693 | - * @return void |
|
| 694 | - * @throws DomainException |
|
| 695 | - * @throws EE_Error |
|
| 696 | - * @throws InvalidArgumentException |
|
| 697 | - * @throws InvalidDataTypeException |
|
| 698 | - * @throws InvalidInterfaceException |
|
| 699 | - */ |
|
| 700 | - protected function _load_page_dependencies() |
|
| 701 | - { |
|
| 702 | - // let's set the current_screen and screen options to override what WP set |
|
| 703 | - $this->_current_screen = get_current_screen(); |
|
| 704 | - // load admin_notices - global, page class, and view specific |
|
| 705 | - add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 706 | - add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 707 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 708 | - add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 709 | - } |
|
| 710 | - // load network admin_notices - global, page class, and view specific |
|
| 711 | - add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 712 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 713 | - add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 714 | - } |
|
| 715 | - // this will save any per_page screen options if they are present |
|
| 716 | - $this->_set_per_page_screen_options(); |
|
| 717 | - // setup list table properties |
|
| 718 | - $this->_set_list_table(); |
|
| 719 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 720 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 721 | - $this->_add_registered_meta_boxes(); |
|
| 722 | - $this->_add_screen_columns(); |
|
| 723 | - // add screen options - global, page child class, and view specific |
|
| 724 | - $this->_add_global_screen_options(); |
|
| 725 | - $this->_add_screen_options(); |
|
| 726 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 727 | - if (method_exists($this, $add_screen_options)) { |
|
| 728 | - $this->{$add_screen_options}(); |
|
| 729 | - } |
|
| 730 | - // add help tab(s) and tours- set via page_config and qtips. |
|
| 731 | - // $this->_add_help_tour(); |
|
| 732 | - $this->_add_help_tabs(); |
|
| 733 | - $this->_add_qtips(); |
|
| 734 | - // add feature_pointers - global, page child class, and view specific |
|
| 735 | - $this->_add_feature_pointers(); |
|
| 736 | - $this->_add_global_feature_pointers(); |
|
| 737 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 738 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 739 | - $this->{$add_feature_pointer}(); |
|
| 740 | - } |
|
| 741 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 742 | - add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 743 | - add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 744 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 745 | - add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 746 | - } |
|
| 747 | - add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 748 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 749 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 750 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 751 | - // is a good use case. Notice the late priority we're giving these |
|
| 752 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 753 | - add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 754 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 755 | - add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 756 | - } |
|
| 757 | - // admin footer scripts |
|
| 758 | - add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 759 | - add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 760 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 761 | - add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 762 | - } |
|
| 763 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 764 | - // targeted hook |
|
| 765 | - do_action( |
|
| 766 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 767 | - ); |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * _set_defaults |
|
| 773 | - * This sets some global defaults for class properties. |
|
| 774 | - */ |
|
| 775 | - private function _set_defaults() |
|
| 776 | - { |
|
| 777 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 778 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 779 | - $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 780 | - $this->_page_config = $this->_default_route_query_args = []; |
|
| 781 | - $this->_default_nav_tab_name = 'overview'; |
|
| 782 | - // init template args |
|
| 783 | - $this->_template_args = [ |
|
| 784 | - 'admin_page_header' => '', |
|
| 785 | - 'admin_page_content' => '', |
|
| 786 | - 'post_body_content' => '', |
|
| 787 | - 'before_list_table' => '', |
|
| 788 | - 'after_list_table' => '', |
|
| 789 | - ]; |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * route_admin_request |
|
| 795 | - * |
|
| 796 | - * @return void |
|
| 797 | - * @throws InvalidArgumentException |
|
| 798 | - * @throws InvalidInterfaceException |
|
| 799 | - * @throws InvalidDataTypeException |
|
| 800 | - * @throws EE_Error |
|
| 801 | - * @throws ReflectionException |
|
| 802 | - * @see _route_admin_request() |
|
| 803 | - */ |
|
| 804 | - public function route_admin_request() |
|
| 805 | - { |
|
| 806 | - try { |
|
| 807 | - $this->_route_admin_request(); |
|
| 808 | - } catch (EE_Error $e) { |
|
| 809 | - $e->get_error(); |
|
| 810 | - } |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - public function set_wp_page_slug($wp_page_slug) |
|
| 815 | - { |
|
| 816 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 817 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 818 | - if (is_network_admin()) { |
|
| 819 | - $this->_wp_page_slug .= '-network'; |
|
| 820 | - } |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * _verify_routes |
|
| 826 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 827 | - * we know if we need to drop out. |
|
| 828 | - * |
|
| 829 | - * @return bool |
|
| 830 | - * @throws EE_Error |
|
| 831 | - */ |
|
| 832 | - protected function _verify_routes() |
|
| 833 | - { |
|
| 834 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 835 | - if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 836 | - return false; |
|
| 837 | - } |
|
| 838 | - $this->_route = false; |
|
| 839 | - // check that the page_routes array is not empty |
|
| 840 | - if (empty($this->_page_routes)) { |
|
| 841 | - // user error msg |
|
| 842 | - $error_msg = sprintf( |
|
| 843 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 844 | - $this->_admin_page_title |
|
| 845 | - ); |
|
| 846 | - // developer error msg |
|
| 847 | - $error_msg .= '||' . $error_msg |
|
| 848 | - . esc_html__( |
|
| 849 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 850 | - 'event_espresso' |
|
| 851 | - ); |
|
| 852 | - throw new EE_Error($error_msg); |
|
| 853 | - } |
|
| 854 | - // and that the requested page route exists |
|
| 855 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 856 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 857 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 858 | - ? $this->_page_config[ $this->_req_action ] |
|
| 859 | - : []; |
|
| 860 | - } else { |
|
| 861 | - // user error msg |
|
| 862 | - $error_msg = sprintf( |
|
| 863 | - esc_html__( |
|
| 864 | - 'The requested page route does not exist for the %s admin page.', |
|
| 865 | - 'event_espresso' |
|
| 866 | - ), |
|
| 867 | - $this->_admin_page_title |
|
| 868 | - ); |
|
| 869 | - // developer error msg |
|
| 870 | - $error_msg .= '||' . $error_msg |
|
| 871 | - . sprintf( |
|
| 872 | - esc_html__( |
|
| 873 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 874 | - 'event_espresso' |
|
| 875 | - ), |
|
| 876 | - $this->_req_action |
|
| 877 | - ); |
|
| 878 | - throw new EE_Error($error_msg); |
|
| 879 | - } |
|
| 880 | - // and that a default route exists |
|
| 881 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 882 | - // user error msg |
|
| 883 | - $error_msg = sprintf( |
|
| 884 | - esc_html__( |
|
| 885 | - 'A default page route has not been set for the % admin page.', |
|
| 886 | - 'event_espresso' |
|
| 887 | - ), |
|
| 888 | - $this->_admin_page_title |
|
| 889 | - ); |
|
| 890 | - // developer error msg |
|
| 891 | - $error_msg .= '||' . $error_msg |
|
| 892 | - . esc_html__( |
|
| 893 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 894 | - 'event_espresso' |
|
| 895 | - ); |
|
| 896 | - throw new EE_Error($error_msg); |
|
| 897 | - } |
|
| 898 | - // first lets' catch if the UI request has EVER been set. |
|
| 899 | - if ($this->_is_UI_request === null) { |
|
| 900 | - // lets set if this is a UI request or not. |
|
| 901 | - $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 902 | - // wait a minute... we might have a noheader in the route array |
|
| 903 | - $this->_is_UI_request = ! ( |
|
| 904 | - is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 905 | - ) |
|
| 906 | - ? $this->_is_UI_request |
|
| 907 | - : false; |
|
| 908 | - } |
|
| 909 | - $this->_set_current_labels(); |
|
| 910 | - return true; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - |
|
| 914 | - /** |
|
| 915 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 916 | - * |
|
| 917 | - * @param string $route the route name we're verifying |
|
| 918 | - * @return bool we'll throw an exception if this isn't a valid route. |
|
| 919 | - * @throws EE_Error |
|
| 920 | - */ |
|
| 921 | - protected function _verify_route($route) |
|
| 922 | - { |
|
| 923 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 924 | - return true; |
|
| 925 | - } |
|
| 926 | - // user error msg |
|
| 927 | - $error_msg = sprintf( |
|
| 928 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 929 | - $this->_admin_page_title |
|
| 930 | - ); |
|
| 931 | - // developer error msg |
|
| 932 | - $error_msg .= '||' . $error_msg |
|
| 933 | - . sprintf( |
|
| 934 | - esc_html__( |
|
| 935 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 936 | - 'event_espresso' |
|
| 937 | - ), |
|
| 938 | - $route |
|
| 939 | - ); |
|
| 940 | - throw new EE_Error($error_msg); |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - |
|
| 944 | - /** |
|
| 945 | - * perform nonce verification |
|
| 946 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 947 | - * using this method (and save retyping!) |
|
| 948 | - * |
|
| 949 | - * @param string $nonce The nonce sent |
|
| 950 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 951 | - * @return void |
|
| 952 | - * @throws EE_Error |
|
| 953 | - */ |
|
| 954 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 955 | - { |
|
| 956 | - // verify nonce against expected value |
|
| 957 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 958 | - // these are not the droids you are looking for !!! |
|
| 959 | - $msg = sprintf( |
|
| 960 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 961 | - '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 962 | - '</a>' |
|
| 963 | - ); |
|
| 964 | - if (WP_DEBUG) { |
|
| 965 | - $msg .= "\n "; |
|
| 966 | - $msg .= sprintf( |
|
| 967 | - esc_html__( |
|
| 968 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 969 | - 'event_espresso' |
|
| 970 | - ), |
|
| 971 | - __CLASS__ |
|
| 972 | - ); |
|
| 973 | - } |
|
| 974 | - if (! $this->request->isAjax()) { |
|
| 975 | - wp_die($msg); |
|
| 976 | - } |
|
| 977 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 978 | - $this->_return_json(); |
|
| 979 | - } |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - |
|
| 983 | - /** |
|
| 984 | - * _route_admin_request() |
|
| 985 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 986 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 987 | - * in the page routes and then will try to load the corresponding method. |
|
| 988 | - * |
|
| 989 | - * @return void |
|
| 990 | - * @throws EE_Error |
|
| 991 | - * @throws InvalidArgumentException |
|
| 992 | - * @throws InvalidDataTypeException |
|
| 993 | - * @throws InvalidInterfaceException |
|
| 994 | - * @throws ReflectionException |
|
| 995 | - */ |
|
| 996 | - protected function _route_admin_request() |
|
| 997 | - { |
|
| 998 | - if (! $this->_is_UI_request) { |
|
| 999 | - $this->_verify_routes(); |
|
| 1000 | - } |
|
| 1001 | - $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 1002 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1003 | - // set nonce from post data |
|
| 1004 | - $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 1005 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1006 | - } |
|
| 1007 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 1008 | - if ($this->_is_UI_request) { |
|
| 1009 | - $this->_set_nav_tabs(); |
|
| 1010 | - } |
|
| 1011 | - // grab callback function |
|
| 1012 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 1013 | - // check if callback has args |
|
| 1014 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 1015 | - $error_msg = ''; |
|
| 1016 | - // action right before calling route |
|
| 1017 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1018 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1019 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1020 | - } |
|
| 1021 | - // right before calling the route, let's clean the _wp_http_referer |
|
| 1022 | - $this->request->setServerParam( |
|
| 1023 | - 'REQUEST_URI', |
|
| 1024 | - remove_query_arg( |
|
| 1025 | - '_wp_http_referer', |
|
| 1026 | - wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1027 | - ) |
|
| 1028 | - ); |
|
| 1029 | - if (! empty($func)) { |
|
| 1030 | - if (is_array($func)) { |
|
| 1031 | - list($class, $method) = $func; |
|
| 1032 | - } elseif (strpos($func, '::') !== false) { |
|
| 1033 | - list($class, $method) = explode('::', $func); |
|
| 1034 | - } else { |
|
| 1035 | - $class = $this; |
|
| 1036 | - $method = $func; |
|
| 1037 | - } |
|
| 1038 | - if (! (is_object($class) && $class === $this)) { |
|
| 1039 | - // send along this admin page object for access by addons. |
|
| 1040 | - $args['admin_page_object'] = $this; |
|
| 1041 | - } |
|
| 1042 | - if ( |
|
| 115 | + /** |
|
| 116 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
| 117 | + * actions. |
|
| 118 | + * |
|
| 119 | + * @since 4.6.x |
|
| 120 | + * @var array. |
|
| 121 | + */ |
|
| 122 | + protected $_default_route_query_args; |
|
| 123 | + |
|
| 124 | + // set via request page and action args. |
|
| 125 | + protected $_current_page; |
|
| 126 | + |
|
| 127 | + protected $_current_view; |
|
| 128 | + |
|
| 129 | + protected $_current_page_view_url; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * unprocessed value for the 'action' request param (default '') |
|
| 133 | + * |
|
| 134 | + * @var string |
|
| 135 | + */ |
|
| 136 | + protected $raw_req_action = ''; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * unprocessed value for the 'page' request param (default '') |
|
| 140 | + * |
|
| 141 | + * @var string |
|
| 142 | + */ |
|
| 143 | + protected $raw_req_page = ''; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * sanitized request action (and nonce) |
|
| 147 | + * |
|
| 148 | + * @var string |
|
| 149 | + */ |
|
| 150 | + protected $_req_action = ''; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * sanitized request action nonce |
|
| 154 | + * |
|
| 155 | + * @var string |
|
| 156 | + */ |
|
| 157 | + protected $_req_nonce = ''; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @var string |
|
| 161 | + */ |
|
| 162 | + protected $_search_btn_label = ''; |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @var string |
|
| 166 | + */ |
|
| 167 | + protected $_search_box_callback = ''; |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @var WP_Screen |
|
| 171 | + */ |
|
| 172 | + protected $_current_screen; |
|
| 173 | + |
|
| 174 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 175 | + protected $_hook_obj; |
|
| 176 | + |
|
| 177 | + // for holding incoming request data |
|
| 178 | + protected $_req_data = []; |
|
| 179 | + |
|
| 180 | + // yes / no array for admin form fields |
|
| 181 | + protected $_yes_no_values = []; |
|
| 182 | + |
|
| 183 | + // some default things shared by all child classes |
|
| 184 | + protected $_default_espresso_metaboxes; |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @var EE_Registry |
|
| 188 | + */ |
|
| 189 | + protected $EE = null; |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 194 | + * |
|
| 195 | + * @var boolean |
|
| 196 | + */ |
|
| 197 | + protected $_is_caf = false; |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @Constructor |
|
| 202 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 203 | + * @throws EE_Error |
|
| 204 | + * @throws InvalidArgumentException |
|
| 205 | + * @throws ReflectionException |
|
| 206 | + * @throws InvalidDataTypeException |
|
| 207 | + * @throws InvalidInterfaceException |
|
| 208 | + */ |
|
| 209 | + public function __construct($routing = true) |
|
| 210 | + { |
|
| 211 | + $this->loader = LoaderFactory::getLoader(); |
|
| 212 | + $this->request = $this->loader->getShared(RequestInterface::class); |
|
| 213 | + $this->_routing = $routing; |
|
| 214 | + |
|
| 215 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 216 | + $this->_is_caf = true; |
|
| 217 | + } |
|
| 218 | + $this->_yes_no_values = [ |
|
| 219 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 220 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 221 | + ]; |
|
| 222 | + // set the _req_data property. |
|
| 223 | + $this->_req_data = $this->request->requestParams(); |
|
| 224 | + // set initial page props (child method) |
|
| 225 | + $this->_init_page_props(); |
|
| 226 | + // set global defaults |
|
| 227 | + $this->_set_defaults(); |
|
| 228 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 229 | + $this->_global_ajax_hooks(); |
|
| 230 | + $this->_ajax_hooks(); |
|
| 231 | + // other_page_hooks have to be early too. |
|
| 232 | + $this->_do_other_page_hooks(); |
|
| 233 | + // set up page dependencies |
|
| 234 | + $this->_before_page_setup(); |
|
| 235 | + $this->_page_setup(); |
|
| 236 | + // die(); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * _init_page_props |
|
| 242 | + * Child classes use to set at least the following properties: |
|
| 243 | + * $page_slug. |
|
| 244 | + * $page_label. |
|
| 245 | + * |
|
| 246 | + * @abstract |
|
| 247 | + * @return void |
|
| 248 | + */ |
|
| 249 | + abstract protected function _init_page_props(); |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * _ajax_hooks |
|
| 254 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 255 | + * Note: within the ajax callback methods. |
|
| 256 | + * |
|
| 257 | + * @abstract |
|
| 258 | + * @return void |
|
| 259 | + */ |
|
| 260 | + abstract protected function _ajax_hooks(); |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * _define_page_props |
|
| 265 | + * child classes define page properties in here. Must include at least: |
|
| 266 | + * $_admin_base_url = base_url for all admin pages |
|
| 267 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 268 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 269 | + * array( |
|
| 270 | + * 'buttons' => array( |
|
| 271 | + * 'add' => esc_html__('label for add new button'), |
|
| 272 | + * 'edit' => esc_html__('label for edit button'), |
|
| 273 | + * 'delete' => esc_html__('label for delete button') |
|
| 274 | + * ) |
|
| 275 | + * ) |
|
| 276 | + * |
|
| 277 | + * @abstract |
|
| 278 | + * @return void |
|
| 279 | + */ |
|
| 280 | + abstract protected function _define_page_props(); |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * _set_page_routes |
|
| 285 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 286 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 287 | + * have a 'default' route. Here's the format |
|
| 288 | + * $this->_page_routes = array( |
|
| 289 | + * 'default' => array( |
|
| 290 | + * 'func' => '_default_method_handling_route', |
|
| 291 | + * 'args' => array('array','of','args'), |
|
| 292 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 293 | + * ajax request, backend processing) |
|
| 294 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 295 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 296 | + * headers sent route. |
|
| 297 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 298 | + * this route. |
|
| 299 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 300 | + * checks). |
|
| 301 | + * ), |
|
| 302 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 303 | + * handling method. |
|
| 304 | + * ) |
|
| 305 | + * ) |
|
| 306 | + * |
|
| 307 | + * @abstract |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + abstract protected function _set_page_routes(); |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * _set_page_config |
|
| 315 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 316 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 317 | + * $this->_page_config = array( |
|
| 318 | + * 'default' => array( |
|
| 319 | + * 'labels' => array( |
|
| 320 | + * 'buttons' => array( |
|
| 321 | + * 'add' => esc_html__('label for adding item'), |
|
| 322 | + * 'edit' => esc_html__('label for editing item'), |
|
| 323 | + * 'delete' => esc_html__('label for deleting item') |
|
| 324 | + * ), |
|
| 325 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 326 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 327 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 328 | + * _define_page_props() method |
|
| 329 | + * 'nav' => array( |
|
| 330 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 331 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 332 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 333 | + * 'order' => 10, //required to indicate tab position. |
|
| 334 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 335 | + * displayed then add this parameter. |
|
| 336 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 337 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 338 | + * metaboxes set for eventespresso admin pages. |
|
| 339 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 340 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 341 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 342 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 343 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 344 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 345 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 346 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 347 | + * want to display. |
|
| 348 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 349 | + * 'tab_id' => array( |
|
| 350 | + * 'title' => 'tab_title', |
|
| 351 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 352 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 353 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 354 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 355 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 356 | + * attempt to use the callback which should match the name of a method in the class |
|
| 357 | + * ), |
|
| 358 | + * 'tab2_id' => array( |
|
| 359 | + * 'title' => 'tab2 title', |
|
| 360 | + * 'filename' => 'file_name_2' |
|
| 361 | + * 'callback' => 'callback_method_for_content', |
|
| 362 | + * ), |
|
| 363 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 364 | + * help tab area on an admin page. @return void |
|
| 365 | + * |
|
| 366 | + * @link |
|
| 367 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 368 | + * 'help_tour' => array( |
|
| 369 | + * 'name_of_help_tour_class', //all help tours should be a child class of EE_Help_Tour and located |
|
| 370 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 371 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 372 | + * ), |
|
| 373 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default |
|
| 374 | + * is true if it isn't present). To remove the requirement for a nonce check when this route is |
|
| 375 | + * visited just set |
|
| 376 | + * 'require_nonce' to FALSE |
|
| 377 | + * ) |
|
| 378 | + * ) |
|
| 379 | + * |
|
| 380 | + * @abstract |
|
| 381 | + */ |
|
| 382 | + abstract protected function _set_page_config(); |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** end sample help_tour methods **/ |
|
| 389 | + /** |
|
| 390 | + * _add_screen_options |
|
| 391 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 392 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 393 | + * to a particular view. |
|
| 394 | + * |
|
| 395 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 396 | + * see also WP_Screen object documents... |
|
| 397 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 398 | + * @abstract |
|
| 399 | + * @return void |
|
| 400 | + */ |
|
| 401 | + abstract protected function _add_screen_options(); |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * _add_feature_pointers |
|
| 406 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 407 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 408 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 409 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 410 | + * extended) also see: |
|
| 411 | + * |
|
| 412 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 413 | + * @abstract |
|
| 414 | + * @return void |
|
| 415 | + */ |
|
| 416 | + abstract protected function _add_feature_pointers(); |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * load_scripts_styles |
|
| 421 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 422 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 423 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 424 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 425 | + * |
|
| 426 | + * @abstract |
|
| 427 | + * @return void |
|
| 428 | + */ |
|
| 429 | + abstract public function load_scripts_styles(); |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * admin_init |
|
| 434 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 435 | + * all pages/views loaded by child class. |
|
| 436 | + * |
|
| 437 | + * @abstract |
|
| 438 | + * @return void |
|
| 439 | + */ |
|
| 440 | + abstract public function admin_init(); |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * admin_notices |
|
| 445 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 446 | + * all pages/views loaded by child class. |
|
| 447 | + * |
|
| 448 | + * @abstract |
|
| 449 | + * @return void |
|
| 450 | + */ |
|
| 451 | + abstract public function admin_notices(); |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * admin_footer_scripts |
|
| 456 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 457 | + * will apply to all pages/views loaded by child class. |
|
| 458 | + * |
|
| 459 | + * @return void |
|
| 460 | + */ |
|
| 461 | + abstract public function admin_footer_scripts(); |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * admin_footer |
|
| 466 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 467 | + * apply to all pages/views loaded by child class. |
|
| 468 | + * |
|
| 469 | + * @return void |
|
| 470 | + */ |
|
| 471 | + public function admin_footer() |
|
| 472 | + { |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * _global_ajax_hooks |
|
| 478 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 479 | + * Note: within the ajax callback methods. |
|
| 480 | + * |
|
| 481 | + * @abstract |
|
| 482 | + * @return void |
|
| 483 | + */ |
|
| 484 | + protected function _global_ajax_hooks() |
|
| 485 | + { |
|
| 486 | + // for lazy loading of metabox content |
|
| 487 | + add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + public function ajax_metabox_content() |
|
| 492 | + { |
|
| 493 | + $content_id = $this->request->getRequestParam('contentid', ''); |
|
| 494 | + $content_url = $this->request->getRequestParam('contenturl', '', 'url'); |
|
| 495 | + self::cached_rss_display($content_id, $content_url); |
|
| 496 | + wp_die(); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * allows extending classes do something specific before the parent constructor runs _page_setup(). |
|
| 502 | + * |
|
| 503 | + * @return void |
|
| 504 | + */ |
|
| 505 | + protected function _before_page_setup() |
|
| 506 | + { |
|
| 507 | + // default is to do nothing |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Makes sure any things that need to be loaded early get handled. |
|
| 513 | + * We also escape early here if the page requested doesn't match the object. |
|
| 514 | + * |
|
| 515 | + * @final |
|
| 516 | + * @return void |
|
| 517 | + * @throws EE_Error |
|
| 518 | + * @throws InvalidArgumentException |
|
| 519 | + * @throws ReflectionException |
|
| 520 | + * @throws InvalidDataTypeException |
|
| 521 | + * @throws InvalidInterfaceException |
|
| 522 | + */ |
|
| 523 | + final protected function _page_setup() |
|
| 524 | + { |
|
| 525 | + // requires? |
|
| 526 | + // admin_init stuff - global - we're setting this REALLY early |
|
| 527 | + // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 528 | + // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 529 | + add_action('admin_init', [$this, 'admin_init_global'], 5); |
|
| 530 | + // next verify if we need to load anything... |
|
| 531 | + $this->_current_page = $this->request->getRequestParam('page', '', 'key'); |
|
| 532 | + $this->page_folder = strtolower( |
|
| 533 | + str_replace(['_Admin_Page', 'Extend_'], '', get_class($this)) |
|
| 534 | + ); |
|
| 535 | + global $ee_menu_slugs; |
|
| 536 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 537 | + if ( |
|
| 538 | + ! $this->request->isAjax() |
|
| 539 | + && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ])) |
|
| 540 | + ) { |
|
| 541 | + return; |
|
| 542 | + } |
|
| 543 | + // because WP List tables have two duplicate select inputs for choosing bulk actions, |
|
| 544 | + // we need to copy the action from the second to the first |
|
| 545 | + $action = $this->request->getRequestParam('action', '-1', 'key'); |
|
| 546 | + $action2 = $this->request->getRequestParam('action2', '-1', 'key'); |
|
| 547 | + $action = $action !== '-1' ? $action : $action2; |
|
| 548 | + $req_action = $action !== '-1' ? $action : 'default'; |
|
| 549 | + |
|
| 550 | + // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax |
|
| 551 | + // then let's use the route as the action. |
|
| 552 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 553 | + $route = $this->request->getRequestParam('route'); |
|
| 554 | + $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax()) |
|
| 555 | + ? $route |
|
| 556 | + : $req_action; |
|
| 557 | + |
|
| 558 | + $this->_current_view = $this->_req_action; |
|
| 559 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 560 | + $this->_define_page_props(); |
|
| 561 | + $this->_current_page_view_url = add_query_arg( |
|
| 562 | + ['page' => $this->_current_page, 'action' => $this->_current_view], |
|
| 563 | + $this->_admin_base_url |
|
| 564 | + ); |
|
| 565 | + // default things |
|
| 566 | + $this->_default_espresso_metaboxes = [ |
|
| 567 | + '_espresso_news_post_box', |
|
| 568 | + '_espresso_links_post_box', |
|
| 569 | + '_espresso_ratings_request', |
|
| 570 | + '_espresso_sponsors_post_box', |
|
| 571 | + ]; |
|
| 572 | + // set page configs |
|
| 573 | + $this->_set_page_routes(); |
|
| 574 | + $this->_set_page_config(); |
|
| 575 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 576 | + if ($this->request->requestParamIsSet('wp_referer')) { |
|
| 577 | + $wp_referer = $this->request->getRequestParam('wp_referer'); |
|
| 578 | + if ($wp_referer) { |
|
| 579 | + $this->_default_route_query_args['wp_referer'] = $wp_referer; |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + // for caffeinated and other extended functionality. |
|
| 583 | + // If there is a _extend_page_config method |
|
| 584 | + // then let's run that to modify the all the various page configuration arrays |
|
| 585 | + if (method_exists($this, '_extend_page_config')) { |
|
| 586 | + $this->_extend_page_config(); |
|
| 587 | + } |
|
| 588 | + // for CPT and other extended functionality. |
|
| 589 | + // If there is an _extend_page_config_for_cpt |
|
| 590 | + // then let's run that to modify all the various page configuration arrays. |
|
| 591 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 592 | + $this->_extend_page_config_for_cpt(); |
|
| 593 | + } |
|
| 594 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 595 | + $this->_page_routes = apply_filters( |
|
| 596 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 597 | + $this->_page_routes, |
|
| 598 | + $this |
|
| 599 | + ); |
|
| 600 | + $this->_page_config = apply_filters( |
|
| 601 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 602 | + $this->_page_config, |
|
| 603 | + $this |
|
| 604 | + ); |
|
| 605 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 606 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 607 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 608 | + add_action( |
|
| 609 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 610 | + [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view], |
|
| 611 | + 10, |
|
| 612 | + 2 |
|
| 613 | + ); |
|
| 614 | + } |
|
| 615 | + // next route only if routing enabled |
|
| 616 | + if ($this->_routing && ! $this->request->isAjax()) { |
|
| 617 | + $this->_verify_routes(); |
|
| 618 | + // next let's just check user_access and kill if no access |
|
| 619 | + $this->check_user_access(); |
|
| 620 | + if ($this->_is_UI_request) { |
|
| 621 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 622 | + add_action('admin_init', [$this, 'admin_init'], 10); |
|
| 623 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 624 | + add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15); |
|
| 625 | + } |
|
| 626 | + } else { |
|
| 627 | + // hijack regular WP loading and route admin request immediately |
|
| 628 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 629 | + $this->route_admin_request(); |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 637 | + * |
|
| 638 | + * @return void |
|
| 639 | + * @throws EE_Error |
|
| 640 | + */ |
|
| 641 | + private function _do_other_page_hooks() |
|
| 642 | + { |
|
| 643 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []); |
|
| 644 | + foreach ($registered_pages as $page) { |
|
| 645 | + // now let's setup the file name and class that should be present |
|
| 646 | + $classname = str_replace('.class.php', '', $page); |
|
| 647 | + // autoloaders should take care of loading file |
|
| 648 | + if (! class_exists($classname)) { |
|
| 649 | + $error_msg[] = sprintf( |
|
| 650 | + esc_html__( |
|
| 651 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 652 | + 'event_espresso' |
|
| 653 | + ), |
|
| 654 | + $page |
|
| 655 | + ); |
|
| 656 | + $error_msg[] = $error_msg[0] |
|
| 657 | + . "\r\n" |
|
| 658 | + . sprintf( |
|
| 659 | + esc_html__( |
|
| 660 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 661 | + 'event_espresso' |
|
| 662 | + ), |
|
| 663 | + $page, |
|
| 664 | + '<br />', |
|
| 665 | + '<strong>' . $classname . '</strong>' |
|
| 666 | + ); |
|
| 667 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 668 | + } |
|
| 669 | + // notice we are passing the instance of this class to the hook object. |
|
| 670 | + $this->loader->getShared($classname, [$this]); |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * @throws ReflectionException |
|
| 677 | + * @throws EE_Error |
|
| 678 | + */ |
|
| 679 | + public function load_page_dependencies() |
|
| 680 | + { |
|
| 681 | + try { |
|
| 682 | + $this->_load_page_dependencies(); |
|
| 683 | + } catch (EE_Error $e) { |
|
| 684 | + $e->get_error(); |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * load_page_dependencies |
|
| 691 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 692 | + * |
|
| 693 | + * @return void |
|
| 694 | + * @throws DomainException |
|
| 695 | + * @throws EE_Error |
|
| 696 | + * @throws InvalidArgumentException |
|
| 697 | + * @throws InvalidDataTypeException |
|
| 698 | + * @throws InvalidInterfaceException |
|
| 699 | + */ |
|
| 700 | + protected function _load_page_dependencies() |
|
| 701 | + { |
|
| 702 | + // let's set the current_screen and screen options to override what WP set |
|
| 703 | + $this->_current_screen = get_current_screen(); |
|
| 704 | + // load admin_notices - global, page class, and view specific |
|
| 705 | + add_action('admin_notices', [$this, 'admin_notices_global'], 5); |
|
| 706 | + add_action('admin_notices', [$this, 'admin_notices'], 10); |
|
| 707 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 708 | + add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15); |
|
| 709 | + } |
|
| 710 | + // load network admin_notices - global, page class, and view specific |
|
| 711 | + add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5); |
|
| 712 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 713 | + add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]); |
|
| 714 | + } |
|
| 715 | + // this will save any per_page screen options if they are present |
|
| 716 | + $this->_set_per_page_screen_options(); |
|
| 717 | + // setup list table properties |
|
| 718 | + $this->_set_list_table(); |
|
| 719 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 720 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 721 | + $this->_add_registered_meta_boxes(); |
|
| 722 | + $this->_add_screen_columns(); |
|
| 723 | + // add screen options - global, page child class, and view specific |
|
| 724 | + $this->_add_global_screen_options(); |
|
| 725 | + $this->_add_screen_options(); |
|
| 726 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 727 | + if (method_exists($this, $add_screen_options)) { |
|
| 728 | + $this->{$add_screen_options}(); |
|
| 729 | + } |
|
| 730 | + // add help tab(s) and tours- set via page_config and qtips. |
|
| 731 | + // $this->_add_help_tour(); |
|
| 732 | + $this->_add_help_tabs(); |
|
| 733 | + $this->_add_qtips(); |
|
| 734 | + // add feature_pointers - global, page child class, and view specific |
|
| 735 | + $this->_add_feature_pointers(); |
|
| 736 | + $this->_add_global_feature_pointers(); |
|
| 737 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 738 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 739 | + $this->{$add_feature_pointer}(); |
|
| 740 | + } |
|
| 741 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 742 | + add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5); |
|
| 743 | + add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10); |
|
| 744 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 745 | + add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15); |
|
| 746 | + } |
|
| 747 | + add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100); |
|
| 748 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 749 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 750 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 751 | + // is a good use case. Notice the late priority we're giving these |
|
| 752 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99); |
|
| 753 | + add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100); |
|
| 754 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 755 | + add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101); |
|
| 756 | + } |
|
| 757 | + // admin footer scripts |
|
| 758 | + add_action('admin_footer', [$this, 'admin_footer_global'], 99); |
|
| 759 | + add_action('admin_footer', [$this, 'admin_footer'], 100); |
|
| 760 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 761 | + add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101); |
|
| 762 | + } |
|
| 763 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 764 | + // targeted hook |
|
| 765 | + do_action( |
|
| 766 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 767 | + ); |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * _set_defaults |
|
| 773 | + * This sets some global defaults for class properties. |
|
| 774 | + */ |
|
| 775 | + private function _set_defaults() |
|
| 776 | + { |
|
| 777 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 778 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 779 | + $this->_nav_tabs = $this->_views = $this->_page_routes = []; |
|
| 780 | + $this->_page_config = $this->_default_route_query_args = []; |
|
| 781 | + $this->_default_nav_tab_name = 'overview'; |
|
| 782 | + // init template args |
|
| 783 | + $this->_template_args = [ |
|
| 784 | + 'admin_page_header' => '', |
|
| 785 | + 'admin_page_content' => '', |
|
| 786 | + 'post_body_content' => '', |
|
| 787 | + 'before_list_table' => '', |
|
| 788 | + 'after_list_table' => '', |
|
| 789 | + ]; |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * route_admin_request |
|
| 795 | + * |
|
| 796 | + * @return void |
|
| 797 | + * @throws InvalidArgumentException |
|
| 798 | + * @throws InvalidInterfaceException |
|
| 799 | + * @throws InvalidDataTypeException |
|
| 800 | + * @throws EE_Error |
|
| 801 | + * @throws ReflectionException |
|
| 802 | + * @see _route_admin_request() |
|
| 803 | + */ |
|
| 804 | + public function route_admin_request() |
|
| 805 | + { |
|
| 806 | + try { |
|
| 807 | + $this->_route_admin_request(); |
|
| 808 | + } catch (EE_Error $e) { |
|
| 809 | + $e->get_error(); |
|
| 810 | + } |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + public function set_wp_page_slug($wp_page_slug) |
|
| 815 | + { |
|
| 816 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 817 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 818 | + if (is_network_admin()) { |
|
| 819 | + $this->_wp_page_slug .= '-network'; |
|
| 820 | + } |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * _verify_routes |
|
| 826 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 827 | + * we know if we need to drop out. |
|
| 828 | + * |
|
| 829 | + * @return bool |
|
| 830 | + * @throws EE_Error |
|
| 831 | + */ |
|
| 832 | + protected function _verify_routes() |
|
| 833 | + { |
|
| 834 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 835 | + if (! $this->_current_page && ! $this->request->isAjax()) { |
|
| 836 | + return false; |
|
| 837 | + } |
|
| 838 | + $this->_route = false; |
|
| 839 | + // check that the page_routes array is not empty |
|
| 840 | + if (empty($this->_page_routes)) { |
|
| 841 | + // user error msg |
|
| 842 | + $error_msg = sprintf( |
|
| 843 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 844 | + $this->_admin_page_title |
|
| 845 | + ); |
|
| 846 | + // developer error msg |
|
| 847 | + $error_msg .= '||' . $error_msg |
|
| 848 | + . esc_html__( |
|
| 849 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 850 | + 'event_espresso' |
|
| 851 | + ); |
|
| 852 | + throw new EE_Error($error_msg); |
|
| 853 | + } |
|
| 854 | + // and that the requested page route exists |
|
| 855 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 856 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 857 | + $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 858 | + ? $this->_page_config[ $this->_req_action ] |
|
| 859 | + : []; |
|
| 860 | + } else { |
|
| 861 | + // user error msg |
|
| 862 | + $error_msg = sprintf( |
|
| 863 | + esc_html__( |
|
| 864 | + 'The requested page route does not exist for the %s admin page.', |
|
| 865 | + 'event_espresso' |
|
| 866 | + ), |
|
| 867 | + $this->_admin_page_title |
|
| 868 | + ); |
|
| 869 | + // developer error msg |
|
| 870 | + $error_msg .= '||' . $error_msg |
|
| 871 | + . sprintf( |
|
| 872 | + esc_html__( |
|
| 873 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 874 | + 'event_espresso' |
|
| 875 | + ), |
|
| 876 | + $this->_req_action |
|
| 877 | + ); |
|
| 878 | + throw new EE_Error($error_msg); |
|
| 879 | + } |
|
| 880 | + // and that a default route exists |
|
| 881 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 882 | + // user error msg |
|
| 883 | + $error_msg = sprintf( |
|
| 884 | + esc_html__( |
|
| 885 | + 'A default page route has not been set for the % admin page.', |
|
| 886 | + 'event_espresso' |
|
| 887 | + ), |
|
| 888 | + $this->_admin_page_title |
|
| 889 | + ); |
|
| 890 | + // developer error msg |
|
| 891 | + $error_msg .= '||' . $error_msg |
|
| 892 | + . esc_html__( |
|
| 893 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 894 | + 'event_espresso' |
|
| 895 | + ); |
|
| 896 | + throw new EE_Error($error_msg); |
|
| 897 | + } |
|
| 898 | + // first lets' catch if the UI request has EVER been set. |
|
| 899 | + if ($this->_is_UI_request === null) { |
|
| 900 | + // lets set if this is a UI request or not. |
|
| 901 | + $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool'); |
|
| 902 | + // wait a minute... we might have a noheader in the route array |
|
| 903 | + $this->_is_UI_request = ! ( |
|
| 904 | + is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] |
|
| 905 | + ) |
|
| 906 | + ? $this->_is_UI_request |
|
| 907 | + : false; |
|
| 908 | + } |
|
| 909 | + $this->_set_current_labels(); |
|
| 910 | + return true; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + |
|
| 914 | + /** |
|
| 915 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 916 | + * |
|
| 917 | + * @param string $route the route name we're verifying |
|
| 918 | + * @return bool we'll throw an exception if this isn't a valid route. |
|
| 919 | + * @throws EE_Error |
|
| 920 | + */ |
|
| 921 | + protected function _verify_route($route) |
|
| 922 | + { |
|
| 923 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 924 | + return true; |
|
| 925 | + } |
|
| 926 | + // user error msg |
|
| 927 | + $error_msg = sprintf( |
|
| 928 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 929 | + $this->_admin_page_title |
|
| 930 | + ); |
|
| 931 | + // developer error msg |
|
| 932 | + $error_msg .= '||' . $error_msg |
|
| 933 | + . sprintf( |
|
| 934 | + esc_html__( |
|
| 935 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 936 | + 'event_espresso' |
|
| 937 | + ), |
|
| 938 | + $route |
|
| 939 | + ); |
|
| 940 | + throw new EE_Error($error_msg); |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + |
|
| 944 | + /** |
|
| 945 | + * perform nonce verification |
|
| 946 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 947 | + * using this method (and save retyping!) |
|
| 948 | + * |
|
| 949 | + * @param string $nonce The nonce sent |
|
| 950 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 951 | + * @return void |
|
| 952 | + * @throws EE_Error |
|
| 953 | + */ |
|
| 954 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 955 | + { |
|
| 956 | + // verify nonce against expected value |
|
| 957 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 958 | + // these are not the droids you are looking for !!! |
|
| 959 | + $msg = sprintf( |
|
| 960 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 961 | + '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 962 | + '</a>' |
|
| 963 | + ); |
|
| 964 | + if (WP_DEBUG) { |
|
| 965 | + $msg .= "\n "; |
|
| 966 | + $msg .= sprintf( |
|
| 967 | + esc_html__( |
|
| 968 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 969 | + 'event_espresso' |
|
| 970 | + ), |
|
| 971 | + __CLASS__ |
|
| 972 | + ); |
|
| 973 | + } |
|
| 974 | + if (! $this->request->isAjax()) { |
|
| 975 | + wp_die($msg); |
|
| 976 | + } |
|
| 977 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 978 | + $this->_return_json(); |
|
| 979 | + } |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + |
|
| 983 | + /** |
|
| 984 | + * _route_admin_request() |
|
| 985 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
| 986 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 987 | + * in the page routes and then will try to load the corresponding method. |
|
| 988 | + * |
|
| 989 | + * @return void |
|
| 990 | + * @throws EE_Error |
|
| 991 | + * @throws InvalidArgumentException |
|
| 992 | + * @throws InvalidDataTypeException |
|
| 993 | + * @throws InvalidInterfaceException |
|
| 994 | + * @throws ReflectionException |
|
| 995 | + */ |
|
| 996 | + protected function _route_admin_request() |
|
| 997 | + { |
|
| 998 | + if (! $this->_is_UI_request) { |
|
| 999 | + $this->_verify_routes(); |
|
| 1000 | + } |
|
| 1001 | + $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce']; |
|
| 1002 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1003 | + // set nonce from post data |
|
| 1004 | + $nonce = $this->request->getRequestParam($this->_req_nonce, ''); |
|
| 1005 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1006 | + } |
|
| 1007 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 1008 | + if ($this->_is_UI_request) { |
|
| 1009 | + $this->_set_nav_tabs(); |
|
| 1010 | + } |
|
| 1011 | + // grab callback function |
|
| 1012 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
| 1013 | + // check if callback has args |
|
| 1014 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : []; |
|
| 1015 | + $error_msg = ''; |
|
| 1016 | + // action right before calling route |
|
| 1017 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1018 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1019 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1020 | + } |
|
| 1021 | + // right before calling the route, let's clean the _wp_http_referer |
|
| 1022 | + $this->request->setServerParam( |
|
| 1023 | + 'REQUEST_URI', |
|
| 1024 | + remove_query_arg( |
|
| 1025 | + '_wp_http_referer', |
|
| 1026 | + wp_unslash($this->request->getServerParam('REQUEST_URI')) |
|
| 1027 | + ) |
|
| 1028 | + ); |
|
| 1029 | + if (! empty($func)) { |
|
| 1030 | + if (is_array($func)) { |
|
| 1031 | + list($class, $method) = $func; |
|
| 1032 | + } elseif (strpos($func, '::') !== false) { |
|
| 1033 | + list($class, $method) = explode('::', $func); |
|
| 1034 | + } else { |
|
| 1035 | + $class = $this; |
|
| 1036 | + $method = $func; |
|
| 1037 | + } |
|
| 1038 | + if (! (is_object($class) && $class === $this)) { |
|
| 1039 | + // send along this admin page object for access by addons. |
|
| 1040 | + $args['admin_page_object'] = $this; |
|
| 1041 | + } |
|
| 1042 | + if ( |
|
| 1043 | 1043 | // is it a method on a class that doesn't work? |
| 1044 | - ( |
|
| 1045 | - ( |
|
| 1046 | - method_exists($class, $method) |
|
| 1047 | - && call_user_func_array([$class, $method], $args) === false |
|
| 1048 | - ) |
|
| 1049 | - && ( |
|
| 1050 | - // is it a standalone function that doesn't work? |
|
| 1051 | - function_exists($method) |
|
| 1052 | - && call_user_func_array( |
|
| 1053 | - $func, |
|
| 1054 | - array_merge(['admin_page_object' => $this], $args) |
|
| 1055 | - ) === false |
|
| 1056 | - ) |
|
| 1057 | - ) |
|
| 1058 | - || ( |
|
| 1059 | - // is it neither a class method NOR a standalone function? |
|
| 1060 | - ! method_exists($class, $method) |
|
| 1061 | - && ! function_exists($method) |
|
| 1062 | - ) |
|
| 1063 | - ) { |
|
| 1064 | - // user error msg |
|
| 1065 | - $error_msg = esc_html__( |
|
| 1066 | - 'An error occurred. The requested page route could not be found.', |
|
| 1067 | - 'event_espresso' |
|
| 1068 | - ); |
|
| 1069 | - // developer error msg |
|
| 1070 | - $error_msg .= '||'; |
|
| 1071 | - $error_msg .= sprintf( |
|
| 1072 | - esc_html__( |
|
| 1073 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1074 | - 'event_espresso' |
|
| 1075 | - ), |
|
| 1076 | - $method |
|
| 1077 | - ); |
|
| 1078 | - } |
|
| 1079 | - if (! empty($error_msg)) { |
|
| 1080 | - throw new EE_Error($error_msg); |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1084 | - // then we need to reset the routing properties to the new route. |
|
| 1085 | - // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1086 | - if ( |
|
| 1087 | - $this->_is_UI_request === false |
|
| 1088 | - && is_array($this->_route) |
|
| 1089 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1090 | - ) { |
|
| 1091 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1092 | - } |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1098 | - * route redirects to a headers route in its route config. |
|
| 1099 | - * |
|
| 1100 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1101 | - * @return void |
|
| 1102 | - * @throws ReflectionException |
|
| 1103 | - * @throws InvalidArgumentException |
|
| 1104 | - * @throws InvalidInterfaceException |
|
| 1105 | - * @throws InvalidDataTypeException |
|
| 1106 | - * @throws EE_Error |
|
| 1107 | - * @since 4.3.0 |
|
| 1108 | - */ |
|
| 1109 | - protected function _reset_routing_properties($new_route) |
|
| 1110 | - { |
|
| 1111 | - $this->_is_UI_request = true; |
|
| 1112 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1113 | - $this->request->setRequestParam('action', $new_route); |
|
| 1114 | - // rerun page setup |
|
| 1115 | - $this->_page_setup(); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - |
|
| 1119 | - /** |
|
| 1120 | - * _add_query_arg |
|
| 1121 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1122 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1123 | - * |
|
| 1124 | - * @param array $args |
|
| 1125 | - * @param string $url |
|
| 1126 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1127 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1128 | - * Example usage: If the current page is: |
|
| 1129 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1130 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1131 | - * &_wpnonce=5467821 |
|
| 1132 | - * and you call: |
|
| 1133 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1134 | - * array( |
|
| 1135 | - * 'action' => 'resend_something', |
|
| 1136 | - * 'page=>espresso_registrations' |
|
| 1137 | - * ), |
|
| 1138 | - * $some_url, |
|
| 1139 | - * true |
|
| 1140 | - * ); |
|
| 1141 | - * It will produce a url in this structure: |
|
| 1142 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1143 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1144 | - * month_range]=March%202015 |
|
| 1145 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1146 | - * @return string |
|
| 1147 | - */ |
|
| 1148 | - public static function add_query_args_and_nonce( |
|
| 1149 | - $args = [], |
|
| 1150 | - $url = false, |
|
| 1151 | - $sticky = false, |
|
| 1152 | - $exclude_nonce = false |
|
| 1153 | - ) { |
|
| 1154 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1155 | - if ($sticky) { |
|
| 1156 | - /** @var RequestInterface $request */ |
|
| 1157 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1158 | - $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']); |
|
| 1159 | - foreach ($request->requestParams() as $key => $value) { |
|
| 1160 | - // do not add nonces |
|
| 1161 | - if (strpos($key, 'nonce') !== false) { |
|
| 1162 | - continue; |
|
| 1163 | - } |
|
| 1164 | - $args[ 'wp_referer[' . $key . ']' ] = htmlspecialchars($value); |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - |
|
| 1171 | - /** |
|
| 1172 | - * This returns a generated link that will load the related help tab. |
|
| 1173 | - * |
|
| 1174 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1175 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1176 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1177 | - * @return string generated link |
|
| 1178 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1179 | - */ |
|
| 1180 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1181 | - { |
|
| 1182 | - return EEH_Template::get_help_tab_link( |
|
| 1183 | - $help_tab_id, |
|
| 1184 | - $this->page_slug, |
|
| 1185 | - $this->_req_action, |
|
| 1186 | - $icon_style, |
|
| 1187 | - $help_text |
|
| 1188 | - ); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - /** |
|
| 1193 | - * _add_help_tabs |
|
| 1194 | - * Note child classes define their help tabs within the page_config array. |
|
| 1195 | - * |
|
| 1196 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1197 | - * @return void |
|
| 1198 | - * @throws DomainException |
|
| 1199 | - * @throws EE_Error |
|
| 1200 | - */ |
|
| 1201 | - protected function _add_help_tabs() |
|
| 1202 | - { |
|
| 1203 | - $tour_buttons = ''; |
|
| 1204 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1205 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1206 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1207 | - // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1208 | - // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1209 | - // $tb = array(); |
|
| 1210 | - // $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1211 | - // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1212 | - // // if this is the end tour then we don't need to setup a button |
|
| 1213 | - // if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1214 | - // continue; |
|
| 1215 | - // } |
|
| 1216 | - // $tb[] = '<button id="trigger-tour-' |
|
| 1217 | - // . $tour->get_slug() |
|
| 1218 | - // . '" class="button-primary trigger-ee-help-tour">' |
|
| 1219 | - // . $tour->get_label() |
|
| 1220 | - // . '</button>'; |
|
| 1221 | - // } |
|
| 1222 | - // $tour_buttons .= implode('<br />', $tb); |
|
| 1223 | - // $tour_buttons .= '</div></div>'; |
|
| 1224 | - // } |
|
| 1225 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1226 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1227 | - // check that the callback given is valid |
|
| 1228 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1229 | - throw new EE_Error( |
|
| 1230 | - sprintf( |
|
| 1231 | - esc_html__( |
|
| 1232 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1233 | - 'event_espresso' |
|
| 1234 | - ), |
|
| 1235 | - $config['help_sidebar'], |
|
| 1236 | - get_class($this) |
|
| 1237 | - ) |
|
| 1238 | - ); |
|
| 1239 | - } |
|
| 1240 | - $content = apply_filters( |
|
| 1241 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1242 | - $this->{$config['help_sidebar']}() |
|
| 1243 | - ); |
|
| 1244 | - $content .= $tour_buttons; // add help tour buttons. |
|
| 1245 | - // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1246 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1247 | - } |
|
| 1248 | - // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1249 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1250 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1251 | - } |
|
| 1252 | - // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1253 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1254 | - $_ht['id'] = $this->page_slug; |
|
| 1255 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1256 | - $_ht['content'] = '<p>' |
|
| 1257 | - . esc_html__( |
|
| 1258 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1259 | - 'event_espresso' |
|
| 1260 | - ) . '</p>'; |
|
| 1261 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1262 | - } |
|
| 1263 | - if (! isset($config['help_tabs'])) { |
|
| 1264 | - return; |
|
| 1265 | - } //no help tabs for this route |
|
| 1266 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1267 | - // we're here so there ARE help tabs! |
|
| 1268 | - // make sure we've got what we need |
|
| 1269 | - if (! isset($cfg['title'])) { |
|
| 1270 | - throw new EE_Error( |
|
| 1271 | - esc_html__( |
|
| 1272 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1273 | - 'event_espresso' |
|
| 1274 | - ) |
|
| 1275 | - ); |
|
| 1276 | - } |
|
| 1277 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1278 | - throw new EE_Error( |
|
| 1279 | - esc_html__( |
|
| 1280 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1281 | - 'event_espresso' |
|
| 1282 | - ) |
|
| 1283 | - ); |
|
| 1284 | - } |
|
| 1285 | - // first priority goes to content. |
|
| 1286 | - if (! empty($cfg['content'])) { |
|
| 1287 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1288 | - // second priority goes to filename |
|
| 1289 | - } elseif (! empty($cfg['filename'])) { |
|
| 1290 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1291 | - // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1292 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1293 | - . basename($this->_get_dir()) |
|
| 1294 | - . '/help_tabs/' |
|
| 1295 | - . $cfg['filename'] |
|
| 1296 | - . '.help_tab.php' : $file_path; |
|
| 1297 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1298 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1299 | - EE_Error::add_error( |
|
| 1300 | - sprintf( |
|
| 1301 | - esc_html__( |
|
| 1302 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1303 | - 'event_espresso' |
|
| 1304 | - ), |
|
| 1305 | - $tab_id, |
|
| 1306 | - key($config), |
|
| 1307 | - $file_path |
|
| 1308 | - ), |
|
| 1309 | - __FILE__, |
|
| 1310 | - __FUNCTION__, |
|
| 1311 | - __LINE__ |
|
| 1312 | - ); |
|
| 1313 | - return; |
|
| 1314 | - } |
|
| 1315 | - $template_args['admin_page_obj'] = $this; |
|
| 1316 | - $content = EEH_Template::display_template( |
|
| 1317 | - $file_path, |
|
| 1318 | - $template_args, |
|
| 1319 | - true |
|
| 1320 | - ); |
|
| 1321 | - } else { |
|
| 1322 | - $content = ''; |
|
| 1323 | - } |
|
| 1324 | - // check if callback is valid |
|
| 1325 | - if ( |
|
| 1326 | - empty($content) |
|
| 1327 | - && ( |
|
| 1328 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1329 | - ) |
|
| 1330 | - ) { |
|
| 1331 | - EE_Error::add_error( |
|
| 1332 | - sprintf( |
|
| 1333 | - esc_html__( |
|
| 1334 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1335 | - 'event_espresso' |
|
| 1336 | - ), |
|
| 1337 | - $cfg['title'] |
|
| 1338 | - ), |
|
| 1339 | - __FILE__, |
|
| 1340 | - __FUNCTION__, |
|
| 1341 | - __LINE__ |
|
| 1342 | - ); |
|
| 1343 | - return; |
|
| 1344 | - } |
|
| 1345 | - // setup config array for help tab method |
|
| 1346 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1347 | - $_ht = [ |
|
| 1348 | - 'id' => $id, |
|
| 1349 | - 'title' => $cfg['title'], |
|
| 1350 | - 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1351 | - 'content' => $content, |
|
| 1352 | - ]; |
|
| 1353 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1356 | - } |
|
| 1357 | - |
|
| 1358 | - |
|
| 1359 | - /** |
|
| 1360 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1361 | - * an array with properties for setting up usage of the joyride plugin |
|
| 1362 | - * |
|
| 1363 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1364 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1365 | - * _set_page_config() comments |
|
| 1366 | - * @return void |
|
| 1367 | - * @throws InvalidArgumentException |
|
| 1368 | - * @throws InvalidDataTypeException |
|
| 1369 | - * @throws InvalidInterfaceException |
|
| 1370 | - */ |
|
| 1371 | - protected function _add_help_tour() |
|
| 1372 | - { |
|
| 1373 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1374 | - // $tours = array(); |
|
| 1375 | - // $this->_help_tour = array(); |
|
| 1376 | - // // exit early if help tours are turned off globally |
|
| 1377 | - // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1378 | - // || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1379 | - // ) { |
|
| 1380 | - // return; |
|
| 1381 | - // } |
|
| 1382 | - // // loop through _page_config to find any help_tour defined |
|
| 1383 | - // foreach ($this->_page_config as $route => $config) { |
|
| 1384 | - // // we're only going to set things up for this route |
|
| 1385 | - // if ($route !== $this->_req_action) { |
|
| 1386 | - // continue; |
|
| 1387 | - // } |
|
| 1388 | - // if (isset($config['help_tour'])) { |
|
| 1389 | - // foreach ($config['help_tour'] as $tour) { |
|
| 1390 | - // $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1391 | - // // let's see if we can get that file... |
|
| 1392 | - // // if not its possible this is a decaf route not set in caffeinated |
|
| 1393 | - // // so lets try and get the caffeinated equivalent |
|
| 1394 | - // $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1395 | - // . basename($this->_get_dir()) |
|
| 1396 | - // . '/help_tours/' |
|
| 1397 | - // . $tour |
|
| 1398 | - // . '.class.php' : $file_path; |
|
| 1399 | - // // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1400 | - // if (! is_readable($file_path)) { |
|
| 1401 | - // EE_Error::add_error( |
|
| 1402 | - // sprintf( |
|
| 1403 | - // esc_html__( |
|
| 1404 | - // 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1405 | - // 'event_espresso' |
|
| 1406 | - // ), |
|
| 1407 | - // $file_path, |
|
| 1408 | - // $tour |
|
| 1409 | - // ), |
|
| 1410 | - // __FILE__, |
|
| 1411 | - // __FUNCTION__, |
|
| 1412 | - // __LINE__ |
|
| 1413 | - // ); |
|
| 1414 | - // return; |
|
| 1415 | - // } |
|
| 1416 | - // require_once $file_path; |
|
| 1417 | - // if (! class_exists($tour)) { |
|
| 1418 | - // $error_msg[] = sprintf( |
|
| 1419 | - // esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1420 | - // $tour |
|
| 1421 | - // ); |
|
| 1422 | - // $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1423 | - // . sprintf( |
|
| 1424 | - // esc_html__( |
|
| 1425 | - // 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1426 | - // 'event_espresso' |
|
| 1427 | - // ), |
|
| 1428 | - // $tour, |
|
| 1429 | - // '<br />', |
|
| 1430 | - // $tour, |
|
| 1431 | - // $this->_req_action, |
|
| 1432 | - // get_class($this) |
|
| 1433 | - // ); |
|
| 1434 | - // throw new EE_Error(implode('||', $error_msg)); |
|
| 1435 | - // } |
|
| 1436 | - // $tour_obj = new $tour($this->_is_caf); |
|
| 1437 | - // $tours[] = $tour_obj; |
|
| 1438 | - // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1439 | - // } |
|
| 1440 | - // // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1441 | - // $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1442 | - // $tours[] = $end_stop_tour; |
|
| 1443 | - // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1444 | - // } |
|
| 1445 | - // } |
|
| 1446 | - // |
|
| 1447 | - // if (! empty($tours)) { |
|
| 1448 | - // $this->_help_tour['tours'] = $tours; |
|
| 1449 | - // } |
|
| 1450 | - // // that's it! Now that the $_help_tours property is set (or not) |
|
| 1451 | - // // the scripts and html should be taken care of automatically. |
|
| 1452 | - // |
|
| 1453 | - // /** |
|
| 1454 | - // * Allow extending the help tours variable. |
|
| 1455 | - // * |
|
| 1456 | - // * @param Array $_help_tour The array containing all help tour information to be displayed. |
|
| 1457 | - // */ |
|
| 1458 | - // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour); |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - |
|
| 1462 | - /** |
|
| 1463 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1464 | - * |
|
| 1465 | - * @return void |
|
| 1466 | - */ |
|
| 1467 | - protected function _add_qtips() |
|
| 1468 | - { |
|
| 1469 | - if (isset($this->_route_config['qtips'])) { |
|
| 1470 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1471 | - // load qtip loader |
|
| 1472 | - $path = [ |
|
| 1473 | - $this->_get_dir() . '/qtips/', |
|
| 1474 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1475 | - ]; |
|
| 1476 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1477 | - } |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * _set_nav_tabs |
|
| 1483 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1484 | - * wish to add additional tabs or modify accordingly. |
|
| 1485 | - * |
|
| 1486 | - * @return void |
|
| 1487 | - * @throws InvalidArgumentException |
|
| 1488 | - * @throws InvalidInterfaceException |
|
| 1489 | - * @throws InvalidDataTypeException |
|
| 1490 | - */ |
|
| 1491 | - protected function _set_nav_tabs() |
|
| 1492 | - { |
|
| 1493 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1494 | - $i = 0; |
|
| 1495 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1496 | - if (! is_array($config) || empty($config['nav'])) { |
|
| 1497 | - continue; |
|
| 1498 | - } |
|
| 1499 | - // no nav tab for this config |
|
| 1500 | - // check for persistent flag |
|
| 1501 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1502 | - // nav tab is only to appear when route requested. |
|
| 1503 | - continue; |
|
| 1504 | - } |
|
| 1505 | - if (! $this->check_user_access($slug, true)) { |
|
| 1506 | - // no nav tab because current user does not have access. |
|
| 1507 | - continue; |
|
| 1508 | - } |
|
| 1509 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1510 | - $this->_nav_tabs[ $slug ] = [ |
|
| 1511 | - 'url' => isset($config['nav']['url']) |
|
| 1512 | - ? $config['nav']['url'] |
|
| 1513 | - : self::add_query_args_and_nonce( |
|
| 1514 | - ['action' => $slug], |
|
| 1515 | - $this->_admin_base_url |
|
| 1516 | - ), |
|
| 1517 | - 'link_text' => isset($config['nav']['label']) |
|
| 1518 | - ? $config['nav']['label'] |
|
| 1519 | - : ucwords( |
|
| 1520 | - str_replace('_', ' ', $slug) |
|
| 1521 | - ), |
|
| 1522 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1523 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1524 | - ]; |
|
| 1525 | - $i++; |
|
| 1526 | - } |
|
| 1527 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1528 | - if (empty($this->_nav_tabs)) { |
|
| 1529 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1530 | - 'url' => $this->_admin_base_url, |
|
| 1531 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1532 | - 'css_class' => 'nav-tab-active', |
|
| 1533 | - 'order' => 10, |
|
| 1534 | - ]; |
|
| 1535 | - } |
|
| 1536 | - // now let's sort the tabs according to order |
|
| 1537 | - usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - |
|
| 1541 | - /** |
|
| 1542 | - * _set_current_labels |
|
| 1543 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1544 | - * property array |
|
| 1545 | - * |
|
| 1546 | - * @return void |
|
| 1547 | - */ |
|
| 1548 | - private function _set_current_labels() |
|
| 1549 | - { |
|
| 1550 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1551 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1552 | - if (is_array($text)) { |
|
| 1553 | - foreach ($text as $sublabel => $subtext) { |
|
| 1554 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1555 | - } |
|
| 1556 | - } else { |
|
| 1557 | - $this->_labels[ $label ] = $text; |
|
| 1558 | - } |
|
| 1559 | - } |
|
| 1560 | - } |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - |
|
| 1564 | - /** |
|
| 1565 | - * verifies user access for this admin page |
|
| 1566 | - * |
|
| 1567 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1568 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1569 | - * return false if verify fail. |
|
| 1570 | - * @return bool |
|
| 1571 | - * @throws InvalidArgumentException |
|
| 1572 | - * @throws InvalidDataTypeException |
|
| 1573 | - * @throws InvalidInterfaceException |
|
| 1574 | - */ |
|
| 1575 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1576 | - { |
|
| 1577 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1578 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1579 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1580 | - && is_array( |
|
| 1581 | - $this->_page_routes[ $route_to_check ] |
|
| 1582 | - ) |
|
| 1583 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1584 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1585 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1586 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1587 | - : $this->_route['capability']; |
|
| 1588 | - } else { |
|
| 1589 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1590 | - } |
|
| 1591 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1592 | - if ( |
|
| 1593 | - ! $this->request->isAjax() |
|
| 1594 | - && ( |
|
| 1595 | - ! function_exists('is_admin') |
|
| 1596 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1597 | - $capability, |
|
| 1598 | - $this->page_slug |
|
| 1599 | - . '_' |
|
| 1600 | - . $route_to_check, |
|
| 1601 | - $id |
|
| 1602 | - ) |
|
| 1603 | - ) |
|
| 1604 | - ) { |
|
| 1605 | - if ($verify_only) { |
|
| 1606 | - return false; |
|
| 1607 | - } |
|
| 1608 | - if (is_user_logged_in()) { |
|
| 1609 | - wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1610 | - } else { |
|
| 1611 | - return false; |
|
| 1612 | - } |
|
| 1613 | - } |
|
| 1614 | - return true; |
|
| 1615 | - } |
|
| 1616 | - |
|
| 1617 | - |
|
| 1618 | - /** |
|
| 1619 | - * admin_init_global |
|
| 1620 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1621 | - * This method executes for ALL EE Admin pages. |
|
| 1622 | - * |
|
| 1623 | - * @return void |
|
| 1624 | - */ |
|
| 1625 | - public function admin_init_global() |
|
| 1626 | - { |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * wp_loaded_global |
|
| 1632 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1633 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1634 | - * |
|
| 1635 | - * @return void |
|
| 1636 | - */ |
|
| 1637 | - public function wp_loaded() |
|
| 1638 | - { |
|
| 1639 | - } |
|
| 1640 | - |
|
| 1641 | - |
|
| 1642 | - /** |
|
| 1643 | - * admin_notices |
|
| 1644 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1645 | - * ALL EE_Admin pages. |
|
| 1646 | - * |
|
| 1647 | - * @return void |
|
| 1648 | - */ |
|
| 1649 | - public function admin_notices_global() |
|
| 1650 | - { |
|
| 1651 | - $this->_display_no_javascript_warning(); |
|
| 1652 | - $this->_display_espresso_notices(); |
|
| 1653 | - } |
|
| 1654 | - |
|
| 1655 | - |
|
| 1656 | - public function network_admin_notices_global() |
|
| 1657 | - { |
|
| 1658 | - $this->_display_no_javascript_warning(); |
|
| 1659 | - $this->_display_espresso_notices(); |
|
| 1660 | - } |
|
| 1661 | - |
|
| 1662 | - |
|
| 1663 | - /** |
|
| 1664 | - * admin_footer_scripts_global |
|
| 1665 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1666 | - * will apply on ALL EE_Admin pages. |
|
| 1667 | - * |
|
| 1668 | - * @return void |
|
| 1669 | - */ |
|
| 1670 | - public function admin_footer_scripts_global() |
|
| 1671 | - { |
|
| 1672 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1673 | - $this->_add_admin_page_overlay(); |
|
| 1674 | - // if metaboxes are present we need to add the nonce field |
|
| 1675 | - if ( |
|
| 1676 | - isset($this->_route_config['metaboxes']) |
|
| 1677 | - || isset($this->_route_config['list_table']) |
|
| 1678 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1679 | - ) { |
|
| 1680 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1681 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1682 | - } |
|
| 1683 | - } |
|
| 1684 | - |
|
| 1685 | - |
|
| 1686 | - /** |
|
| 1687 | - * admin_footer_global |
|
| 1688 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1689 | - * ALL EE_Admin Pages. |
|
| 1690 | - * |
|
| 1691 | - * @return void |
|
| 1692 | - */ |
|
| 1693 | - public function admin_footer_global() |
|
| 1694 | - { |
|
| 1695 | - // dialog container for dialog helper |
|
| 1696 | - echo ' |
|
| 1044 | + ( |
|
| 1045 | + ( |
|
| 1046 | + method_exists($class, $method) |
|
| 1047 | + && call_user_func_array([$class, $method], $args) === false |
|
| 1048 | + ) |
|
| 1049 | + && ( |
|
| 1050 | + // is it a standalone function that doesn't work? |
|
| 1051 | + function_exists($method) |
|
| 1052 | + && call_user_func_array( |
|
| 1053 | + $func, |
|
| 1054 | + array_merge(['admin_page_object' => $this], $args) |
|
| 1055 | + ) === false |
|
| 1056 | + ) |
|
| 1057 | + ) |
|
| 1058 | + || ( |
|
| 1059 | + // is it neither a class method NOR a standalone function? |
|
| 1060 | + ! method_exists($class, $method) |
|
| 1061 | + && ! function_exists($method) |
|
| 1062 | + ) |
|
| 1063 | + ) { |
|
| 1064 | + // user error msg |
|
| 1065 | + $error_msg = esc_html__( |
|
| 1066 | + 'An error occurred. The requested page route could not be found.', |
|
| 1067 | + 'event_espresso' |
|
| 1068 | + ); |
|
| 1069 | + // developer error msg |
|
| 1070 | + $error_msg .= '||'; |
|
| 1071 | + $error_msg .= sprintf( |
|
| 1072 | + esc_html__( |
|
| 1073 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1074 | + 'event_espresso' |
|
| 1075 | + ), |
|
| 1076 | + $method |
|
| 1077 | + ); |
|
| 1078 | + } |
|
| 1079 | + if (! empty($error_msg)) { |
|
| 1080 | + throw new EE_Error($error_msg); |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1084 | + // then we need to reset the routing properties to the new route. |
|
| 1085 | + // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
| 1086 | + if ( |
|
| 1087 | + $this->_is_UI_request === false |
|
| 1088 | + && is_array($this->_route) |
|
| 1089 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1090 | + ) { |
|
| 1091 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1092 | + } |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1098 | + * route redirects to a headers route in its route config. |
|
| 1099 | + * |
|
| 1100 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1101 | + * @return void |
|
| 1102 | + * @throws ReflectionException |
|
| 1103 | + * @throws InvalidArgumentException |
|
| 1104 | + * @throws InvalidInterfaceException |
|
| 1105 | + * @throws InvalidDataTypeException |
|
| 1106 | + * @throws EE_Error |
|
| 1107 | + * @since 4.3.0 |
|
| 1108 | + */ |
|
| 1109 | + protected function _reset_routing_properties($new_route) |
|
| 1110 | + { |
|
| 1111 | + $this->_is_UI_request = true; |
|
| 1112 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1113 | + $this->request->setRequestParam('action', $new_route); |
|
| 1114 | + // rerun page setup |
|
| 1115 | + $this->_page_setup(); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + |
|
| 1119 | + /** |
|
| 1120 | + * _add_query_arg |
|
| 1121 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1122 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1123 | + * |
|
| 1124 | + * @param array $args |
|
| 1125 | + * @param string $url |
|
| 1126 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1127 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1128 | + * Example usage: If the current page is: |
|
| 1129 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1130 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1131 | + * &_wpnonce=5467821 |
|
| 1132 | + * and you call: |
|
| 1133 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1134 | + * array( |
|
| 1135 | + * 'action' => 'resend_something', |
|
| 1136 | + * 'page=>espresso_registrations' |
|
| 1137 | + * ), |
|
| 1138 | + * $some_url, |
|
| 1139 | + * true |
|
| 1140 | + * ); |
|
| 1141 | + * It will produce a url in this structure: |
|
| 1142 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1143 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1144 | + * month_range]=March%202015 |
|
| 1145 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1146 | + * @return string |
|
| 1147 | + */ |
|
| 1148 | + public static function add_query_args_and_nonce( |
|
| 1149 | + $args = [], |
|
| 1150 | + $url = false, |
|
| 1151 | + $sticky = false, |
|
| 1152 | + $exclude_nonce = false |
|
| 1153 | + ) { |
|
| 1154 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1155 | + if ($sticky) { |
|
| 1156 | + /** @var RequestInterface $request */ |
|
| 1157 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 1158 | + $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']); |
|
| 1159 | + foreach ($request->requestParams() as $key => $value) { |
|
| 1160 | + // do not add nonces |
|
| 1161 | + if (strpos($key, 'nonce') !== false) { |
|
| 1162 | + continue; |
|
| 1163 | + } |
|
| 1164 | + $args[ 'wp_referer[' . $key . ']' ] = htmlspecialchars($value); |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + |
|
| 1171 | + /** |
|
| 1172 | + * This returns a generated link that will load the related help tab. |
|
| 1173 | + * |
|
| 1174 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1175 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1176 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1177 | + * @return string generated link |
|
| 1178 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1179 | + */ |
|
| 1180 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1181 | + { |
|
| 1182 | + return EEH_Template::get_help_tab_link( |
|
| 1183 | + $help_tab_id, |
|
| 1184 | + $this->page_slug, |
|
| 1185 | + $this->_req_action, |
|
| 1186 | + $icon_style, |
|
| 1187 | + $help_text |
|
| 1188 | + ); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + /** |
|
| 1193 | + * _add_help_tabs |
|
| 1194 | + * Note child classes define their help tabs within the page_config array. |
|
| 1195 | + * |
|
| 1196 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1197 | + * @return void |
|
| 1198 | + * @throws DomainException |
|
| 1199 | + * @throws EE_Error |
|
| 1200 | + */ |
|
| 1201 | + protected function _add_help_tabs() |
|
| 1202 | + { |
|
| 1203 | + $tour_buttons = ''; |
|
| 1204 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1205 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1206 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1207 | + // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1208 | + // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1209 | + // $tb = array(); |
|
| 1210 | + // $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1211 | + // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1212 | + // // if this is the end tour then we don't need to setup a button |
|
| 1213 | + // if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1214 | + // continue; |
|
| 1215 | + // } |
|
| 1216 | + // $tb[] = '<button id="trigger-tour-' |
|
| 1217 | + // . $tour->get_slug() |
|
| 1218 | + // . '" class="button-primary trigger-ee-help-tour">' |
|
| 1219 | + // . $tour->get_label() |
|
| 1220 | + // . '</button>'; |
|
| 1221 | + // } |
|
| 1222 | + // $tour_buttons .= implode('<br />', $tb); |
|
| 1223 | + // $tour_buttons .= '</div></div>'; |
|
| 1224 | + // } |
|
| 1225 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1226 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1227 | + // check that the callback given is valid |
|
| 1228 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1229 | + throw new EE_Error( |
|
| 1230 | + sprintf( |
|
| 1231 | + esc_html__( |
|
| 1232 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
| 1233 | + 'event_espresso' |
|
| 1234 | + ), |
|
| 1235 | + $config['help_sidebar'], |
|
| 1236 | + get_class($this) |
|
| 1237 | + ) |
|
| 1238 | + ); |
|
| 1239 | + } |
|
| 1240 | + $content = apply_filters( |
|
| 1241 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1242 | + $this->{$config['help_sidebar']}() |
|
| 1243 | + ); |
|
| 1244 | + $content .= $tour_buttons; // add help tour buttons. |
|
| 1245 | + // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1246 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1247 | + } |
|
| 1248 | + // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
| 1249 | + if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
| 1250 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1251 | + } |
|
| 1252 | + // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1253 | + if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
| 1254 | + $_ht['id'] = $this->page_slug; |
|
| 1255 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1256 | + $_ht['content'] = '<p>' |
|
| 1257 | + . esc_html__( |
|
| 1258 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1259 | + 'event_espresso' |
|
| 1260 | + ) . '</p>'; |
|
| 1261 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1262 | + } |
|
| 1263 | + if (! isset($config['help_tabs'])) { |
|
| 1264 | + return; |
|
| 1265 | + } //no help tabs for this route |
|
| 1266 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1267 | + // we're here so there ARE help tabs! |
|
| 1268 | + // make sure we've got what we need |
|
| 1269 | + if (! isset($cfg['title'])) { |
|
| 1270 | + throw new EE_Error( |
|
| 1271 | + esc_html__( |
|
| 1272 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1273 | + 'event_espresso' |
|
| 1274 | + ) |
|
| 1275 | + ); |
|
| 1276 | + } |
|
| 1277 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1278 | + throw new EE_Error( |
|
| 1279 | + esc_html__( |
|
| 1280 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
| 1281 | + 'event_espresso' |
|
| 1282 | + ) |
|
| 1283 | + ); |
|
| 1284 | + } |
|
| 1285 | + // first priority goes to content. |
|
| 1286 | + if (! empty($cfg['content'])) { |
|
| 1287 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1288 | + // second priority goes to filename |
|
| 1289 | + } elseif (! empty($cfg['filename'])) { |
|
| 1290 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1291 | + // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
| 1292 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1293 | + . basename($this->_get_dir()) |
|
| 1294 | + . '/help_tabs/' |
|
| 1295 | + . $cfg['filename'] |
|
| 1296 | + . '.help_tab.php' : $file_path; |
|
| 1297 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1298 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1299 | + EE_Error::add_error( |
|
| 1300 | + sprintf( |
|
| 1301 | + esc_html__( |
|
| 1302 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
| 1303 | + 'event_espresso' |
|
| 1304 | + ), |
|
| 1305 | + $tab_id, |
|
| 1306 | + key($config), |
|
| 1307 | + $file_path |
|
| 1308 | + ), |
|
| 1309 | + __FILE__, |
|
| 1310 | + __FUNCTION__, |
|
| 1311 | + __LINE__ |
|
| 1312 | + ); |
|
| 1313 | + return; |
|
| 1314 | + } |
|
| 1315 | + $template_args['admin_page_obj'] = $this; |
|
| 1316 | + $content = EEH_Template::display_template( |
|
| 1317 | + $file_path, |
|
| 1318 | + $template_args, |
|
| 1319 | + true |
|
| 1320 | + ); |
|
| 1321 | + } else { |
|
| 1322 | + $content = ''; |
|
| 1323 | + } |
|
| 1324 | + // check if callback is valid |
|
| 1325 | + if ( |
|
| 1326 | + empty($content) |
|
| 1327 | + && ( |
|
| 1328 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1329 | + ) |
|
| 1330 | + ) { |
|
| 1331 | + EE_Error::add_error( |
|
| 1332 | + sprintf( |
|
| 1333 | + esc_html__( |
|
| 1334 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
| 1335 | + 'event_espresso' |
|
| 1336 | + ), |
|
| 1337 | + $cfg['title'] |
|
| 1338 | + ), |
|
| 1339 | + __FILE__, |
|
| 1340 | + __FUNCTION__, |
|
| 1341 | + __LINE__ |
|
| 1342 | + ); |
|
| 1343 | + return; |
|
| 1344 | + } |
|
| 1345 | + // setup config array for help tab method |
|
| 1346 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1347 | + $_ht = [ |
|
| 1348 | + 'id' => $id, |
|
| 1349 | + 'title' => $cfg['title'], |
|
| 1350 | + 'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null, |
|
| 1351 | + 'content' => $content, |
|
| 1352 | + ]; |
|
| 1353 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | + } |
|
| 1357 | + |
|
| 1358 | + |
|
| 1359 | + /** |
|
| 1360 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1361 | + * an array with properties for setting up usage of the joyride plugin |
|
| 1362 | + * |
|
| 1363 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1364 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1365 | + * _set_page_config() comments |
|
| 1366 | + * @return void |
|
| 1367 | + * @throws InvalidArgumentException |
|
| 1368 | + * @throws InvalidDataTypeException |
|
| 1369 | + * @throws InvalidInterfaceException |
|
| 1370 | + */ |
|
| 1371 | + protected function _add_help_tour() |
|
| 1372 | + { |
|
| 1373 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1374 | + // $tours = array(); |
|
| 1375 | + // $this->_help_tour = array(); |
|
| 1376 | + // // exit early if help tours are turned off globally |
|
| 1377 | + // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1378 | + // || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1379 | + // ) { |
|
| 1380 | + // return; |
|
| 1381 | + // } |
|
| 1382 | + // // loop through _page_config to find any help_tour defined |
|
| 1383 | + // foreach ($this->_page_config as $route => $config) { |
|
| 1384 | + // // we're only going to set things up for this route |
|
| 1385 | + // if ($route !== $this->_req_action) { |
|
| 1386 | + // continue; |
|
| 1387 | + // } |
|
| 1388 | + // if (isset($config['help_tour'])) { |
|
| 1389 | + // foreach ($config['help_tour'] as $tour) { |
|
| 1390 | + // $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1391 | + // // let's see if we can get that file... |
|
| 1392 | + // // if not its possible this is a decaf route not set in caffeinated |
|
| 1393 | + // // so lets try and get the caffeinated equivalent |
|
| 1394 | + // $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1395 | + // . basename($this->_get_dir()) |
|
| 1396 | + // . '/help_tours/' |
|
| 1397 | + // . $tour |
|
| 1398 | + // . '.class.php' : $file_path; |
|
| 1399 | + // // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1400 | + // if (! is_readable($file_path)) { |
|
| 1401 | + // EE_Error::add_error( |
|
| 1402 | + // sprintf( |
|
| 1403 | + // esc_html__( |
|
| 1404 | + // 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
| 1405 | + // 'event_espresso' |
|
| 1406 | + // ), |
|
| 1407 | + // $file_path, |
|
| 1408 | + // $tour |
|
| 1409 | + // ), |
|
| 1410 | + // __FILE__, |
|
| 1411 | + // __FUNCTION__, |
|
| 1412 | + // __LINE__ |
|
| 1413 | + // ); |
|
| 1414 | + // return; |
|
| 1415 | + // } |
|
| 1416 | + // require_once $file_path; |
|
| 1417 | + // if (! class_exists($tour)) { |
|
| 1418 | + // $error_msg[] = sprintf( |
|
| 1419 | + // esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1420 | + // $tour |
|
| 1421 | + // ); |
|
| 1422 | + // $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1423 | + // . sprintf( |
|
| 1424 | + // esc_html__( |
|
| 1425 | + // 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
| 1426 | + // 'event_espresso' |
|
| 1427 | + // ), |
|
| 1428 | + // $tour, |
|
| 1429 | + // '<br />', |
|
| 1430 | + // $tour, |
|
| 1431 | + // $this->_req_action, |
|
| 1432 | + // get_class($this) |
|
| 1433 | + // ); |
|
| 1434 | + // throw new EE_Error(implode('||', $error_msg)); |
|
| 1435 | + // } |
|
| 1436 | + // $tour_obj = new $tour($this->_is_caf); |
|
| 1437 | + // $tours[] = $tour_obj; |
|
| 1438 | + // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1439 | + // } |
|
| 1440 | + // // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1441 | + // $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1442 | + // $tours[] = $end_stop_tour; |
|
| 1443 | + // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1444 | + // } |
|
| 1445 | + // } |
|
| 1446 | + // |
|
| 1447 | + // if (! empty($tours)) { |
|
| 1448 | + // $this->_help_tour['tours'] = $tours; |
|
| 1449 | + // } |
|
| 1450 | + // // that's it! Now that the $_help_tours property is set (or not) |
|
| 1451 | + // // the scripts and html should be taken care of automatically. |
|
| 1452 | + // |
|
| 1453 | + // /** |
|
| 1454 | + // * Allow extending the help tours variable. |
|
| 1455 | + // * |
|
| 1456 | + // * @param Array $_help_tour The array containing all help tour information to be displayed. |
|
| 1457 | + // */ |
|
| 1458 | + // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour); |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + |
|
| 1462 | + /** |
|
| 1463 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1464 | + * |
|
| 1465 | + * @return void |
|
| 1466 | + */ |
|
| 1467 | + protected function _add_qtips() |
|
| 1468 | + { |
|
| 1469 | + if (isset($this->_route_config['qtips'])) { |
|
| 1470 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1471 | + // load qtip loader |
|
| 1472 | + $path = [ |
|
| 1473 | + $this->_get_dir() . '/qtips/', |
|
| 1474 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1475 | + ]; |
|
| 1476 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
| 1477 | + } |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * _set_nav_tabs |
|
| 1483 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1484 | + * wish to add additional tabs or modify accordingly. |
|
| 1485 | + * |
|
| 1486 | + * @return void |
|
| 1487 | + * @throws InvalidArgumentException |
|
| 1488 | + * @throws InvalidInterfaceException |
|
| 1489 | + * @throws InvalidDataTypeException |
|
| 1490 | + */ |
|
| 1491 | + protected function _set_nav_tabs() |
|
| 1492 | + { |
|
| 1493 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1494 | + $i = 0; |
|
| 1495 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1496 | + if (! is_array($config) || empty($config['nav'])) { |
|
| 1497 | + continue; |
|
| 1498 | + } |
|
| 1499 | + // no nav tab for this config |
|
| 1500 | + // check for persistent flag |
|
| 1501 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1502 | + // nav tab is only to appear when route requested. |
|
| 1503 | + continue; |
|
| 1504 | + } |
|
| 1505 | + if (! $this->check_user_access($slug, true)) { |
|
| 1506 | + // no nav tab because current user does not have access. |
|
| 1507 | + continue; |
|
| 1508 | + } |
|
| 1509 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1510 | + $this->_nav_tabs[ $slug ] = [ |
|
| 1511 | + 'url' => isset($config['nav']['url']) |
|
| 1512 | + ? $config['nav']['url'] |
|
| 1513 | + : self::add_query_args_and_nonce( |
|
| 1514 | + ['action' => $slug], |
|
| 1515 | + $this->_admin_base_url |
|
| 1516 | + ), |
|
| 1517 | + 'link_text' => isset($config['nav']['label']) |
|
| 1518 | + ? $config['nav']['label'] |
|
| 1519 | + : ucwords( |
|
| 1520 | + str_replace('_', ' ', $slug) |
|
| 1521 | + ), |
|
| 1522 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1523 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1524 | + ]; |
|
| 1525 | + $i++; |
|
| 1526 | + } |
|
| 1527 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1528 | + if (empty($this->_nav_tabs)) { |
|
| 1529 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = [ |
|
| 1530 | + 'url' => $this->_admin_base_url, |
|
| 1531 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1532 | + 'css_class' => 'nav-tab-active', |
|
| 1533 | + 'order' => 10, |
|
| 1534 | + ]; |
|
| 1535 | + } |
|
| 1536 | + // now let's sort the tabs according to order |
|
| 1537 | + usort($this->_nav_tabs, [$this, '_sort_nav_tabs']); |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + |
|
| 1541 | + /** |
|
| 1542 | + * _set_current_labels |
|
| 1543 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1544 | + * property array |
|
| 1545 | + * |
|
| 1546 | + * @return void |
|
| 1547 | + */ |
|
| 1548 | + private function _set_current_labels() |
|
| 1549 | + { |
|
| 1550 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1551 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1552 | + if (is_array($text)) { |
|
| 1553 | + foreach ($text as $sublabel => $subtext) { |
|
| 1554 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1555 | + } |
|
| 1556 | + } else { |
|
| 1557 | + $this->_labels[ $label ] = $text; |
|
| 1558 | + } |
|
| 1559 | + } |
|
| 1560 | + } |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + |
|
| 1564 | + /** |
|
| 1565 | + * verifies user access for this admin page |
|
| 1566 | + * |
|
| 1567 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1568 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1569 | + * return false if verify fail. |
|
| 1570 | + * @return bool |
|
| 1571 | + * @throws InvalidArgumentException |
|
| 1572 | + * @throws InvalidDataTypeException |
|
| 1573 | + * @throws InvalidInterfaceException |
|
| 1574 | + */ |
|
| 1575 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1576 | + { |
|
| 1577 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1578 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1579 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1580 | + && is_array( |
|
| 1581 | + $this->_page_routes[ $route_to_check ] |
|
| 1582 | + ) |
|
| 1583 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1584 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1585 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1586 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1587 | + : $this->_route['capability']; |
|
| 1588 | + } else { |
|
| 1589 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1590 | + } |
|
| 1591 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1592 | + if ( |
|
| 1593 | + ! $this->request->isAjax() |
|
| 1594 | + && ( |
|
| 1595 | + ! function_exists('is_admin') |
|
| 1596 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1597 | + $capability, |
|
| 1598 | + $this->page_slug |
|
| 1599 | + . '_' |
|
| 1600 | + . $route_to_check, |
|
| 1601 | + $id |
|
| 1602 | + ) |
|
| 1603 | + ) |
|
| 1604 | + ) { |
|
| 1605 | + if ($verify_only) { |
|
| 1606 | + return false; |
|
| 1607 | + } |
|
| 1608 | + if (is_user_logged_in()) { |
|
| 1609 | + wp_die(esc_html__('You do not have access to this route.', 'event_espresso')); |
|
| 1610 | + } else { |
|
| 1611 | + return false; |
|
| 1612 | + } |
|
| 1613 | + } |
|
| 1614 | + return true; |
|
| 1615 | + } |
|
| 1616 | + |
|
| 1617 | + |
|
| 1618 | + /** |
|
| 1619 | + * admin_init_global |
|
| 1620 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1621 | + * This method executes for ALL EE Admin pages. |
|
| 1622 | + * |
|
| 1623 | + * @return void |
|
| 1624 | + */ |
|
| 1625 | + public function admin_init_global() |
|
| 1626 | + { |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * wp_loaded_global |
|
| 1632 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1633 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1634 | + * |
|
| 1635 | + * @return void |
|
| 1636 | + */ |
|
| 1637 | + public function wp_loaded() |
|
| 1638 | + { |
|
| 1639 | + } |
|
| 1640 | + |
|
| 1641 | + |
|
| 1642 | + /** |
|
| 1643 | + * admin_notices |
|
| 1644 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1645 | + * ALL EE_Admin pages. |
|
| 1646 | + * |
|
| 1647 | + * @return void |
|
| 1648 | + */ |
|
| 1649 | + public function admin_notices_global() |
|
| 1650 | + { |
|
| 1651 | + $this->_display_no_javascript_warning(); |
|
| 1652 | + $this->_display_espresso_notices(); |
|
| 1653 | + } |
|
| 1654 | + |
|
| 1655 | + |
|
| 1656 | + public function network_admin_notices_global() |
|
| 1657 | + { |
|
| 1658 | + $this->_display_no_javascript_warning(); |
|
| 1659 | + $this->_display_espresso_notices(); |
|
| 1660 | + } |
|
| 1661 | + |
|
| 1662 | + |
|
| 1663 | + /** |
|
| 1664 | + * admin_footer_scripts_global |
|
| 1665 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1666 | + * will apply on ALL EE_Admin pages. |
|
| 1667 | + * |
|
| 1668 | + * @return void |
|
| 1669 | + */ |
|
| 1670 | + public function admin_footer_scripts_global() |
|
| 1671 | + { |
|
| 1672 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1673 | + $this->_add_admin_page_overlay(); |
|
| 1674 | + // if metaboxes are present we need to add the nonce field |
|
| 1675 | + if ( |
|
| 1676 | + isset($this->_route_config['metaboxes']) |
|
| 1677 | + || isset($this->_route_config['list_table']) |
|
| 1678 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1679 | + ) { |
|
| 1680 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1681 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1682 | + } |
|
| 1683 | + } |
|
| 1684 | + |
|
| 1685 | + |
|
| 1686 | + /** |
|
| 1687 | + * admin_footer_global |
|
| 1688 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
| 1689 | + * ALL EE_Admin Pages. |
|
| 1690 | + * |
|
| 1691 | + * @return void |
|
| 1692 | + */ |
|
| 1693 | + public function admin_footer_global() |
|
| 1694 | + { |
|
| 1695 | + // dialog container for dialog helper |
|
| 1696 | + echo ' |
|
| 1697 | 1697 | <div class="ee-admin-dialog-container auto-hide hidden"> |
| 1698 | 1698 | <div class="ee-notices"></div> |
| 1699 | 1699 | <div class="ee-admin-dialog-container-inner-content"></div> |
| 1700 | 1700 | </div> |
| 1701 | 1701 | '; |
| 1702 | 1702 | |
| 1703 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1704 | - // help tour stuff? |
|
| 1705 | - // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1706 | - // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1707 | - // } |
|
| 1708 | - // current set timezone for timezone js |
|
| 1709 | - echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - |
|
| 1713 | - /** |
|
| 1714 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1715 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1716 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1717 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1718 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1719 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1720 | - * for the |
|
| 1721 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1722 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1723 | - * 'help_trigger_id' => array( |
|
| 1724 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1725 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1726 | - * ) |
|
| 1727 | - * ); |
|
| 1728 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1729 | - * |
|
| 1730 | - * @param array $help_array |
|
| 1731 | - * @param bool $display |
|
| 1732 | - * @return string content |
|
| 1733 | - * @throws DomainException |
|
| 1734 | - * @throws EE_Error |
|
| 1735 | - */ |
|
| 1736 | - protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1737 | - { |
|
| 1738 | - $content = ''; |
|
| 1739 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1740 | - // loop through the array and setup content |
|
| 1741 | - foreach ($help_array as $trigger => $help) { |
|
| 1742 | - // make sure the array is setup properly |
|
| 1743 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1744 | - throw new EE_Error( |
|
| 1745 | - esc_html__( |
|
| 1746 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1747 | - 'event_espresso' |
|
| 1748 | - ) |
|
| 1749 | - ); |
|
| 1750 | - } |
|
| 1751 | - // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1752 | - $template_args = [ |
|
| 1753 | - 'help_popup_id' => $trigger, |
|
| 1754 | - 'help_popup_title' => $help['title'], |
|
| 1755 | - 'help_popup_content' => $help['content'], |
|
| 1756 | - ]; |
|
| 1757 | - $content .= EEH_Template::display_template( |
|
| 1758 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1759 | - $template_args, |
|
| 1760 | - true |
|
| 1761 | - ); |
|
| 1762 | - } |
|
| 1763 | - if ($display) { |
|
| 1764 | - echo $content; // already escaped |
|
| 1765 | - return ''; |
|
| 1766 | - } |
|
| 1767 | - return $content; |
|
| 1768 | - } |
|
| 1769 | - |
|
| 1770 | - |
|
| 1771 | - /** |
|
| 1772 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1773 | - * |
|
| 1774 | - * @return array properly formatted array for help popup content |
|
| 1775 | - * @throws EE_Error |
|
| 1776 | - */ |
|
| 1777 | - private function _get_help_content() |
|
| 1778 | - { |
|
| 1779 | - // what is the method we're looking for? |
|
| 1780 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1781 | - // if method doesn't exist let's get out. |
|
| 1782 | - if (! method_exists($this, $method_name)) { |
|
| 1783 | - return []; |
|
| 1784 | - } |
|
| 1785 | - // k we're good to go let's retrieve the help array |
|
| 1786 | - $help_array = call_user_func([$this, $method_name]); |
|
| 1787 | - // make sure we've got an array! |
|
| 1788 | - if (! is_array($help_array)) { |
|
| 1789 | - throw new EE_Error( |
|
| 1790 | - esc_html__( |
|
| 1791 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1792 | - 'event_espresso' |
|
| 1793 | - ) |
|
| 1794 | - ); |
|
| 1795 | - } |
|
| 1796 | - return $help_array; |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1802 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1803 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1804 | - * |
|
| 1805 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1806 | - * @param boolean $display if false then we return the trigger string |
|
| 1807 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1808 | - * @return string |
|
| 1809 | - * @throws DomainException |
|
| 1810 | - * @throws EE_Error |
|
| 1811 | - */ |
|
| 1812 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1813 | - { |
|
| 1814 | - if ($this->request->isAjax()) { |
|
| 1815 | - return ''; |
|
| 1816 | - } |
|
| 1817 | - // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1818 | - $help_array = $this->_get_help_content(); |
|
| 1819 | - $help_content = ''; |
|
| 1820 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1821 | - $help_array[ $trigger_id ] = [ |
|
| 1822 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1823 | - 'content' => esc_html__( |
|
| 1824 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1825 | - 'event_espresso' |
|
| 1826 | - ), |
|
| 1827 | - ]; |
|
| 1828 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1829 | - } |
|
| 1830 | - // let's setup the trigger |
|
| 1831 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1832 | - . esc_attr($dimensions[0]) |
|
| 1833 | - . '&width=' |
|
| 1834 | - . esc_attr($dimensions[1]) |
|
| 1835 | - . '&inlineId=' |
|
| 1836 | - . esc_attr($trigger_id) |
|
| 1837 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1838 | - $content .= $help_content; |
|
| 1839 | - if ($display) { |
|
| 1840 | - echo $content; // already escaped |
|
| 1841 | - return ''; |
|
| 1842 | - } |
|
| 1843 | - return $content; |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - |
|
| 1847 | - /** |
|
| 1848 | - * _add_global_screen_options |
|
| 1849 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1850 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1851 | - * |
|
| 1852 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1853 | - * see also WP_Screen object documents... |
|
| 1854 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1855 | - * @abstract |
|
| 1856 | - * @return void |
|
| 1857 | - */ |
|
| 1858 | - private function _add_global_screen_options() |
|
| 1859 | - { |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - /** |
|
| 1864 | - * _add_global_feature_pointers |
|
| 1865 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1866 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1867 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1868 | - * |
|
| 1869 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1870 | - * extended) also see: |
|
| 1871 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1872 | - * @abstract |
|
| 1873 | - * @return void |
|
| 1874 | - */ |
|
| 1875 | - private function _add_global_feature_pointers() |
|
| 1876 | - { |
|
| 1877 | - } |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * load_global_scripts_styles |
|
| 1882 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1883 | - * |
|
| 1884 | - * @return void |
|
| 1885 | - */ |
|
| 1886 | - public function load_global_scripts_styles() |
|
| 1887 | - { |
|
| 1888 | - /** STYLES **/ |
|
| 1889 | - // add debugging styles |
|
| 1890 | - if (WP_DEBUG) { |
|
| 1891 | - add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1892 | - } |
|
| 1893 | - // register all styles |
|
| 1894 | - wp_register_style( |
|
| 1895 | - 'espresso-ui-theme', |
|
| 1896 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1897 | - [], |
|
| 1898 | - EVENT_ESPRESSO_VERSION |
|
| 1899 | - ); |
|
| 1900 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1901 | - // helpers styles |
|
| 1902 | - wp_register_style( |
|
| 1903 | - 'ee-text-links', |
|
| 1904 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1905 | - [], |
|
| 1906 | - EVENT_ESPRESSO_VERSION |
|
| 1907 | - ); |
|
| 1908 | - /** SCRIPTS **/ |
|
| 1909 | - // register all scripts |
|
| 1910 | - wp_register_script( |
|
| 1911 | - 'ee-dialog', |
|
| 1912 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1913 | - ['jquery', 'jquery-ui-draggable'], |
|
| 1914 | - EVENT_ESPRESSO_VERSION, |
|
| 1915 | - true |
|
| 1916 | - ); |
|
| 1917 | - wp_register_script( |
|
| 1918 | - 'ee_admin_js', |
|
| 1919 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1920 | - ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
|
| 1921 | - EVENT_ESPRESSO_VERSION, |
|
| 1922 | - true |
|
| 1923 | - ); |
|
| 1924 | - wp_register_script( |
|
| 1925 | - 'jquery-ui-timepicker-addon', |
|
| 1926 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1927 | - ['jquery-ui-datepicker', 'jquery-ui-slider'], |
|
| 1928 | - EVENT_ESPRESSO_VERSION, |
|
| 1929 | - true |
|
| 1930 | - ); |
|
| 1931 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1932 | - // if (EE_Registry::instance()->CFG->admin->help_tour_activation) { |
|
| 1933 | - // add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1934 | - // } |
|
| 1935 | - // script for sorting tables |
|
| 1936 | - wp_register_script( |
|
| 1937 | - 'espresso_ajax_table_sorting', |
|
| 1938 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1939 | - ['ee_admin_js', 'jquery-ui-sortable'], |
|
| 1940 | - EVENT_ESPRESSO_VERSION, |
|
| 1941 | - true |
|
| 1942 | - ); |
|
| 1943 | - // script for parsing uri's |
|
| 1944 | - wp_register_script( |
|
| 1945 | - 'ee-parse-uri', |
|
| 1946 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1947 | - [], |
|
| 1948 | - EVENT_ESPRESSO_VERSION, |
|
| 1949 | - true |
|
| 1950 | - ); |
|
| 1951 | - // and parsing associative serialized form elements |
|
| 1952 | - wp_register_script( |
|
| 1953 | - 'ee-serialize-full-array', |
|
| 1954 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1955 | - ['jquery'], |
|
| 1956 | - EVENT_ESPRESSO_VERSION, |
|
| 1957 | - true |
|
| 1958 | - ); |
|
| 1959 | - // helpers scripts |
|
| 1960 | - wp_register_script( |
|
| 1961 | - 'ee-text-links', |
|
| 1962 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1963 | - ['jquery'], |
|
| 1964 | - EVENT_ESPRESSO_VERSION, |
|
| 1965 | - true |
|
| 1966 | - ); |
|
| 1967 | - wp_register_script( |
|
| 1968 | - 'ee-moment-core', |
|
| 1969 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1970 | - [], |
|
| 1971 | - EVENT_ESPRESSO_VERSION, |
|
| 1972 | - true |
|
| 1973 | - ); |
|
| 1974 | - wp_register_script( |
|
| 1975 | - 'ee-moment', |
|
| 1976 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1977 | - ['ee-moment-core'], |
|
| 1978 | - EVENT_ESPRESSO_VERSION, |
|
| 1979 | - true |
|
| 1980 | - ); |
|
| 1981 | - wp_register_script( |
|
| 1982 | - 'ee-datepicker', |
|
| 1983 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1984 | - ['jquery-ui-timepicker-addon', 'ee-moment'], |
|
| 1985 | - EVENT_ESPRESSO_VERSION, |
|
| 1986 | - true |
|
| 1987 | - ); |
|
| 1988 | - // google charts |
|
| 1989 | - wp_register_script( |
|
| 1990 | - 'google-charts', |
|
| 1991 | - 'https://www.gstatic.com/charts/loader.js', |
|
| 1992 | - [], |
|
| 1993 | - EVENT_ESPRESSO_VERSION, |
|
| 1994 | - false |
|
| 1995 | - ); |
|
| 1996 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1997 | - wp_enqueue_style('ee-admin-css'); |
|
| 1998 | - wp_enqueue_script('ee_admin_js'); |
|
| 1999 | - wp_enqueue_script('ee-accounting'); |
|
| 2000 | - wp_enqueue_script('jquery-validate'); |
|
| 2001 | - // taking care of metaboxes |
|
| 2002 | - if ( |
|
| 2003 | - empty($this->_cpt_route) |
|
| 2004 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2005 | - ) { |
|
| 2006 | - wp_enqueue_script('dashboard'); |
|
| 2007 | - } |
|
| 2008 | - // LOCALIZED DATA |
|
| 2009 | - // localize script for ajax lazy loading |
|
| 2010 | - $lazy_loader_container_ids = apply_filters( |
|
| 2011 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2012 | - ['espresso_news_post_box_content'] |
|
| 2013 | - ); |
|
| 2014 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 2015 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 2016 | - // /** |
|
| 2017 | - // * help tour stuff |
|
| 2018 | - // */ |
|
| 2019 | - // if (! empty($this->_help_tour)) { |
|
| 2020 | - // // register the js for kicking things off |
|
| 2021 | - // wp_enqueue_script( |
|
| 2022 | - // 'ee-help-tour', |
|
| 2023 | - // EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2024 | - // array('jquery-joyride'), |
|
| 2025 | - // EVENT_ESPRESSO_VERSION, |
|
| 2026 | - // true |
|
| 2027 | - // ); |
|
| 2028 | - // $tours = array(); |
|
| 2029 | - // // setup tours for the js tour object |
|
| 2030 | - // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2031 | - // if ($tour instanceof EE_Help_Tour) { |
|
| 2032 | - // $tours[] = array( |
|
| 2033 | - // 'id' => $tour->get_slug(), |
|
| 2034 | - // 'options' => $tour->get_options(), |
|
| 2035 | - // ); |
|
| 2036 | - // } |
|
| 2037 | - // } |
|
| 2038 | - // wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2039 | - // // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2040 | - // } |
|
| 2041 | - |
|
| 2042 | - add_filter( |
|
| 2043 | - 'admin_body_class', |
|
| 2044 | - function ($classes) { |
|
| 2045 | - if (strpos($classes, 'espresso-admin') === false) { |
|
| 2046 | - $classes .= ' espresso-admin'; |
|
| 2047 | - } |
|
| 2048 | - return $classes; |
|
| 2049 | - } |
|
| 2050 | - ); |
|
| 2051 | - } |
|
| 2052 | - |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * admin_footer_scripts_eei18n_js_strings |
|
| 2056 | - * |
|
| 2057 | - * @return void |
|
| 2058 | - */ |
|
| 2059 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 2060 | - { |
|
| 2061 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2062 | - EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 2063 | - __( |
|
| 2064 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2065 | - 'event_espresso' |
|
| 2066 | - ) |
|
| 2067 | - ); |
|
| 2068 | - EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 2069 | - EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 2070 | - EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 2071 | - EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 2072 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 2073 | - EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 2074 | - EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 2075 | - EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 2076 | - EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 2077 | - EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 2078 | - EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 2079 | - EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 2080 | - EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 2081 | - EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 2082 | - EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 2083 | - EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 2084 | - EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 2085 | - EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 2086 | - EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 2087 | - EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 2088 | - EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 2089 | - EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 2090 | - EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 2091 | - EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 2092 | - EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 2093 | - EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 2094 | - EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 2095 | - EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 2096 | - EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 2097 | - EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 2098 | - EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 2099 | - EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 2100 | - EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 2101 | - EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 2102 | - EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 2103 | - EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 2104 | - EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 2105 | - EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 2106 | - } |
|
| 2107 | - |
|
| 2108 | - |
|
| 2109 | - /** |
|
| 2110 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2111 | - * |
|
| 2112 | - * @return void |
|
| 2113 | - */ |
|
| 2114 | - public function add_xdebug_style() |
|
| 2115 | - { |
|
| 2116 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - |
|
| 2120 | - /************************/ |
|
| 2121 | - /** LIST TABLE METHODS **/ |
|
| 2122 | - /************************/ |
|
| 2123 | - /** |
|
| 2124 | - * this sets up the list table if the current view requires it. |
|
| 2125 | - * |
|
| 2126 | - * @return void |
|
| 2127 | - * @throws EE_Error |
|
| 2128 | - */ |
|
| 2129 | - protected function _set_list_table() |
|
| 2130 | - { |
|
| 2131 | - // first is this a list_table view? |
|
| 2132 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2133 | - return; |
|
| 2134 | - } //not a list_table view so get out. |
|
| 2135 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2136 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2137 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2138 | - // user error msg |
|
| 2139 | - $error_msg = esc_html__( |
|
| 2140 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2141 | - 'event_espresso' |
|
| 2142 | - ); |
|
| 2143 | - // developer error msg |
|
| 2144 | - $error_msg .= '||' |
|
| 2145 | - . sprintf( |
|
| 2146 | - esc_html__( |
|
| 2147 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2148 | - 'event_espresso' |
|
| 2149 | - ), |
|
| 2150 | - $this->_req_action, |
|
| 2151 | - $list_table_view |
|
| 2152 | - ); |
|
| 2153 | - throw new EE_Error($error_msg); |
|
| 2154 | - } |
|
| 2155 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2156 | - $this->_views = apply_filters( |
|
| 2157 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2158 | - $this->_views |
|
| 2159 | - ); |
|
| 2160 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2161 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2162 | - $this->_set_list_table_view(); |
|
| 2163 | - $this->_set_list_table_object(); |
|
| 2164 | - } |
|
| 2165 | - |
|
| 2166 | - |
|
| 2167 | - /** |
|
| 2168 | - * set current view for List Table |
|
| 2169 | - * |
|
| 2170 | - * @return void |
|
| 2171 | - */ |
|
| 2172 | - protected function _set_list_table_view() |
|
| 2173 | - { |
|
| 2174 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2175 | - $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 2176 | - $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 2177 | - ? $status |
|
| 2178 | - : $this->_view; |
|
| 2179 | - } |
|
| 2180 | - |
|
| 2181 | - |
|
| 2182 | - /** |
|
| 2183 | - * _set_list_table_object |
|
| 2184 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2185 | - * |
|
| 2186 | - * @throws InvalidInterfaceException |
|
| 2187 | - * @throws InvalidArgumentException |
|
| 2188 | - * @throws InvalidDataTypeException |
|
| 2189 | - * @throws EE_Error |
|
| 2190 | - * @throws InvalidInterfaceException |
|
| 2191 | - */ |
|
| 2192 | - protected function _set_list_table_object() |
|
| 2193 | - { |
|
| 2194 | - if (isset($this->_route_config['list_table'])) { |
|
| 2195 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2196 | - throw new EE_Error( |
|
| 2197 | - sprintf( |
|
| 2198 | - esc_html__( |
|
| 2199 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2200 | - 'event_espresso' |
|
| 2201 | - ), |
|
| 2202 | - $this->_route_config['list_table'], |
|
| 2203 | - get_class($this) |
|
| 2204 | - ) |
|
| 2205 | - ); |
|
| 2206 | - } |
|
| 2207 | - $this->_list_table_object = $this->loader->getShared( |
|
| 2208 | - $this->_route_config['list_table'], |
|
| 2209 | - [$this] |
|
| 2210 | - ); |
|
| 2211 | - } |
|
| 2212 | - } |
|
| 2213 | - |
|
| 2214 | - |
|
| 2215 | - /** |
|
| 2216 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2217 | - * |
|
| 2218 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2219 | - * urls. The array should be indexed by the view it is being |
|
| 2220 | - * added to. |
|
| 2221 | - * @return array |
|
| 2222 | - */ |
|
| 2223 | - public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2224 | - { |
|
| 2225 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2226 | - if (empty($this->_views)) { |
|
| 2227 | - $this->_views = []; |
|
| 2228 | - } |
|
| 2229 | - // cycle thru views |
|
| 2230 | - foreach ($this->_views as $key => $view) { |
|
| 2231 | - $query_args = []; |
|
| 2232 | - // check for current view |
|
| 2233 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2234 | - $query_args['action'] = $this->_req_action; |
|
| 2235 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2236 | - $query_args['status'] = $view['slug']; |
|
| 2237 | - // merge any other arguments sent in. |
|
| 2238 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2239 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2240 | - } |
|
| 2241 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2242 | - } |
|
| 2243 | - return $this->_views; |
|
| 2244 | - } |
|
| 2245 | - |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * _entries_per_page_dropdown |
|
| 2249 | - * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2250 | - * |
|
| 2251 | - * @param int $max_entries total number of rows in the table |
|
| 2252 | - * @return string |
|
| 2253 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2254 | - * WP does it. |
|
| 2255 | - */ |
|
| 2256 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2257 | - { |
|
| 2258 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2259 | - $values = [10, 25, 50, 100]; |
|
| 2260 | - $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2261 | - if ($max_entries) { |
|
| 2262 | - $values[] = $max_entries; |
|
| 2263 | - sort($values); |
|
| 2264 | - } |
|
| 2265 | - $entries_per_page_dropdown = ' |
|
| 1703 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1704 | + // help tour stuff? |
|
| 1705 | + // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1706 | + // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1707 | + // } |
|
| 1708 | + // current set timezone for timezone js |
|
| 1709 | + echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>'; |
|
| 1710 | + } |
|
| 1711 | + |
|
| 1712 | + |
|
| 1713 | + /** |
|
| 1714 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1715 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1716 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1717 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1718 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1719 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1720 | + * for the |
|
| 1721 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1722 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1723 | + * 'help_trigger_id' => array( |
|
| 1724 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1725 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1726 | + * ) |
|
| 1727 | + * ); |
|
| 1728 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1729 | + * |
|
| 1730 | + * @param array $help_array |
|
| 1731 | + * @param bool $display |
|
| 1732 | + * @return string content |
|
| 1733 | + * @throws DomainException |
|
| 1734 | + * @throws EE_Error |
|
| 1735 | + */ |
|
| 1736 | + protected function _set_help_popup_content($help_array = [], $display = false) |
|
| 1737 | + { |
|
| 1738 | + $content = ''; |
|
| 1739 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1740 | + // loop through the array and setup content |
|
| 1741 | + foreach ($help_array as $trigger => $help) { |
|
| 1742 | + // make sure the array is setup properly |
|
| 1743 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
| 1744 | + throw new EE_Error( |
|
| 1745 | + esc_html__( |
|
| 1746 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
| 1747 | + 'event_espresso' |
|
| 1748 | + ) |
|
| 1749 | + ); |
|
| 1750 | + } |
|
| 1751 | + // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1752 | + $template_args = [ |
|
| 1753 | + 'help_popup_id' => $trigger, |
|
| 1754 | + 'help_popup_title' => $help['title'], |
|
| 1755 | + 'help_popup_content' => $help['content'], |
|
| 1756 | + ]; |
|
| 1757 | + $content .= EEH_Template::display_template( |
|
| 1758 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1759 | + $template_args, |
|
| 1760 | + true |
|
| 1761 | + ); |
|
| 1762 | + } |
|
| 1763 | + if ($display) { |
|
| 1764 | + echo $content; // already escaped |
|
| 1765 | + return ''; |
|
| 1766 | + } |
|
| 1767 | + return $content; |
|
| 1768 | + } |
|
| 1769 | + |
|
| 1770 | + |
|
| 1771 | + /** |
|
| 1772 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1773 | + * |
|
| 1774 | + * @return array properly formatted array for help popup content |
|
| 1775 | + * @throws EE_Error |
|
| 1776 | + */ |
|
| 1777 | + private function _get_help_content() |
|
| 1778 | + { |
|
| 1779 | + // what is the method we're looking for? |
|
| 1780 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1781 | + // if method doesn't exist let's get out. |
|
| 1782 | + if (! method_exists($this, $method_name)) { |
|
| 1783 | + return []; |
|
| 1784 | + } |
|
| 1785 | + // k we're good to go let's retrieve the help array |
|
| 1786 | + $help_array = call_user_func([$this, $method_name]); |
|
| 1787 | + // make sure we've got an array! |
|
| 1788 | + if (! is_array($help_array)) { |
|
| 1789 | + throw new EE_Error( |
|
| 1790 | + esc_html__( |
|
| 1791 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1792 | + 'event_espresso' |
|
| 1793 | + ) |
|
| 1794 | + ); |
|
| 1795 | + } |
|
| 1796 | + return $help_array; |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1802 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1803 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1804 | + * |
|
| 1805 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1806 | + * @param boolean $display if false then we return the trigger string |
|
| 1807 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1808 | + * @return string |
|
| 1809 | + * @throws DomainException |
|
| 1810 | + * @throws EE_Error |
|
| 1811 | + */ |
|
| 1812 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640']) |
|
| 1813 | + { |
|
| 1814 | + if ($this->request->isAjax()) { |
|
| 1815 | + return ''; |
|
| 1816 | + } |
|
| 1817 | + // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
| 1818 | + $help_array = $this->_get_help_content(); |
|
| 1819 | + $help_content = ''; |
|
| 1820 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1821 | + $help_array[ $trigger_id ] = [ |
|
| 1822 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1823 | + 'content' => esc_html__( |
|
| 1824 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
| 1825 | + 'event_espresso' |
|
| 1826 | + ), |
|
| 1827 | + ]; |
|
| 1828 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
| 1829 | + } |
|
| 1830 | + // let's setup the trigger |
|
| 1831 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1832 | + . esc_attr($dimensions[0]) |
|
| 1833 | + . '&width=' |
|
| 1834 | + . esc_attr($dimensions[1]) |
|
| 1835 | + . '&inlineId=' |
|
| 1836 | + . esc_attr($trigger_id) |
|
| 1837 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1838 | + $content .= $help_content; |
|
| 1839 | + if ($display) { |
|
| 1840 | + echo $content; // already escaped |
|
| 1841 | + return ''; |
|
| 1842 | + } |
|
| 1843 | + return $content; |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + |
|
| 1847 | + /** |
|
| 1848 | + * _add_global_screen_options |
|
| 1849 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1850 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1851 | + * |
|
| 1852 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1853 | + * see also WP_Screen object documents... |
|
| 1854 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1855 | + * @abstract |
|
| 1856 | + * @return void |
|
| 1857 | + */ |
|
| 1858 | + private function _add_global_screen_options() |
|
| 1859 | + { |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + /** |
|
| 1864 | + * _add_global_feature_pointers |
|
| 1865 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1866 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1867 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1868 | + * |
|
| 1869 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1870 | + * extended) also see: |
|
| 1871 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1872 | + * @abstract |
|
| 1873 | + * @return void |
|
| 1874 | + */ |
|
| 1875 | + private function _add_global_feature_pointers() |
|
| 1876 | + { |
|
| 1877 | + } |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * load_global_scripts_styles |
|
| 1882 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1883 | + * |
|
| 1884 | + * @return void |
|
| 1885 | + */ |
|
| 1886 | + public function load_global_scripts_styles() |
|
| 1887 | + { |
|
| 1888 | + /** STYLES **/ |
|
| 1889 | + // add debugging styles |
|
| 1890 | + if (WP_DEBUG) { |
|
| 1891 | + add_action('admin_head', [$this, 'add_xdebug_style']); |
|
| 1892 | + } |
|
| 1893 | + // register all styles |
|
| 1894 | + wp_register_style( |
|
| 1895 | + 'espresso-ui-theme', |
|
| 1896 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
| 1897 | + [], |
|
| 1898 | + EVENT_ESPRESSO_VERSION |
|
| 1899 | + ); |
|
| 1900 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION); |
|
| 1901 | + // helpers styles |
|
| 1902 | + wp_register_style( |
|
| 1903 | + 'ee-text-links', |
|
| 1904 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
| 1905 | + [], |
|
| 1906 | + EVENT_ESPRESSO_VERSION |
|
| 1907 | + ); |
|
| 1908 | + /** SCRIPTS **/ |
|
| 1909 | + // register all scripts |
|
| 1910 | + wp_register_script( |
|
| 1911 | + 'ee-dialog', |
|
| 1912 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
| 1913 | + ['jquery', 'jquery-ui-draggable'], |
|
| 1914 | + EVENT_ESPRESSO_VERSION, |
|
| 1915 | + true |
|
| 1916 | + ); |
|
| 1917 | + wp_register_script( |
|
| 1918 | + 'ee_admin_js', |
|
| 1919 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
| 1920 | + ['espresso_core', 'ee-parse-uri', 'ee-dialog'], |
|
| 1921 | + EVENT_ESPRESSO_VERSION, |
|
| 1922 | + true |
|
| 1923 | + ); |
|
| 1924 | + wp_register_script( |
|
| 1925 | + 'jquery-ui-timepicker-addon', |
|
| 1926 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
| 1927 | + ['jquery-ui-datepicker', 'jquery-ui-slider'], |
|
| 1928 | + EVENT_ESPRESSO_VERSION, |
|
| 1929 | + true |
|
| 1930 | + ); |
|
| 1931 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1932 | + // if (EE_Registry::instance()->CFG->admin->help_tour_activation) { |
|
| 1933 | + // add_filter('FHEE_load_joyride', '__return_true'); |
|
| 1934 | + // } |
|
| 1935 | + // script for sorting tables |
|
| 1936 | + wp_register_script( |
|
| 1937 | + 'espresso_ajax_table_sorting', |
|
| 1938 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
| 1939 | + ['ee_admin_js', 'jquery-ui-sortable'], |
|
| 1940 | + EVENT_ESPRESSO_VERSION, |
|
| 1941 | + true |
|
| 1942 | + ); |
|
| 1943 | + // script for parsing uri's |
|
| 1944 | + wp_register_script( |
|
| 1945 | + 'ee-parse-uri', |
|
| 1946 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
| 1947 | + [], |
|
| 1948 | + EVENT_ESPRESSO_VERSION, |
|
| 1949 | + true |
|
| 1950 | + ); |
|
| 1951 | + // and parsing associative serialized form elements |
|
| 1952 | + wp_register_script( |
|
| 1953 | + 'ee-serialize-full-array', |
|
| 1954 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
| 1955 | + ['jquery'], |
|
| 1956 | + EVENT_ESPRESSO_VERSION, |
|
| 1957 | + true |
|
| 1958 | + ); |
|
| 1959 | + // helpers scripts |
|
| 1960 | + wp_register_script( |
|
| 1961 | + 'ee-text-links', |
|
| 1962 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
| 1963 | + ['jquery'], |
|
| 1964 | + EVENT_ESPRESSO_VERSION, |
|
| 1965 | + true |
|
| 1966 | + ); |
|
| 1967 | + wp_register_script( |
|
| 1968 | + 'ee-moment-core', |
|
| 1969 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
| 1970 | + [], |
|
| 1971 | + EVENT_ESPRESSO_VERSION, |
|
| 1972 | + true |
|
| 1973 | + ); |
|
| 1974 | + wp_register_script( |
|
| 1975 | + 'ee-moment', |
|
| 1976 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
| 1977 | + ['ee-moment-core'], |
|
| 1978 | + EVENT_ESPRESSO_VERSION, |
|
| 1979 | + true |
|
| 1980 | + ); |
|
| 1981 | + wp_register_script( |
|
| 1982 | + 'ee-datepicker', |
|
| 1983 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
| 1984 | + ['jquery-ui-timepicker-addon', 'ee-moment'], |
|
| 1985 | + EVENT_ESPRESSO_VERSION, |
|
| 1986 | + true |
|
| 1987 | + ); |
|
| 1988 | + // google charts |
|
| 1989 | + wp_register_script( |
|
| 1990 | + 'google-charts', |
|
| 1991 | + 'https://www.gstatic.com/charts/loader.js', |
|
| 1992 | + [], |
|
| 1993 | + EVENT_ESPRESSO_VERSION, |
|
| 1994 | + false |
|
| 1995 | + ); |
|
| 1996 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
| 1997 | + wp_enqueue_style('ee-admin-css'); |
|
| 1998 | + wp_enqueue_script('ee_admin_js'); |
|
| 1999 | + wp_enqueue_script('ee-accounting'); |
|
| 2000 | + wp_enqueue_script('jquery-validate'); |
|
| 2001 | + // taking care of metaboxes |
|
| 2002 | + if ( |
|
| 2003 | + empty($this->_cpt_route) |
|
| 2004 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 2005 | + ) { |
|
| 2006 | + wp_enqueue_script('dashboard'); |
|
| 2007 | + } |
|
| 2008 | + // LOCALIZED DATA |
|
| 2009 | + // localize script for ajax lazy loading |
|
| 2010 | + $lazy_loader_container_ids = apply_filters( |
|
| 2011 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 2012 | + ['espresso_news_post_box_content'] |
|
| 2013 | + ); |
|
| 2014 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
| 2015 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 2016 | + // /** |
|
| 2017 | + // * help tour stuff |
|
| 2018 | + // */ |
|
| 2019 | + // if (! empty($this->_help_tour)) { |
|
| 2020 | + // // register the js for kicking things off |
|
| 2021 | + // wp_enqueue_script( |
|
| 2022 | + // 'ee-help-tour', |
|
| 2023 | + // EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 2024 | + // array('jquery-joyride'), |
|
| 2025 | + // EVENT_ESPRESSO_VERSION, |
|
| 2026 | + // true |
|
| 2027 | + // ); |
|
| 2028 | + // $tours = array(); |
|
| 2029 | + // // setup tours for the js tour object |
|
| 2030 | + // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 2031 | + // if ($tour instanceof EE_Help_Tour) { |
|
| 2032 | + // $tours[] = array( |
|
| 2033 | + // 'id' => $tour->get_slug(), |
|
| 2034 | + // 'options' => $tour->get_options(), |
|
| 2035 | + // ); |
|
| 2036 | + // } |
|
| 2037 | + // } |
|
| 2038 | + // wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 2039 | + // // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 2040 | + // } |
|
| 2041 | + |
|
| 2042 | + add_filter( |
|
| 2043 | + 'admin_body_class', |
|
| 2044 | + function ($classes) { |
|
| 2045 | + if (strpos($classes, 'espresso-admin') === false) { |
|
| 2046 | + $classes .= ' espresso-admin'; |
|
| 2047 | + } |
|
| 2048 | + return $classes; |
|
| 2049 | + } |
|
| 2050 | + ); |
|
| 2051 | + } |
|
| 2052 | + |
|
| 2053 | + |
|
| 2054 | + /** |
|
| 2055 | + * admin_footer_scripts_eei18n_js_strings |
|
| 2056 | + * |
|
| 2057 | + * @return void |
|
| 2058 | + */ |
|
| 2059 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 2060 | + { |
|
| 2061 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2062 | + EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags( |
|
| 2063 | + __( |
|
| 2064 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
| 2065 | + 'event_espresso' |
|
| 2066 | + ) |
|
| 2067 | + ); |
|
| 2068 | + EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso')); |
|
| 2069 | + EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso')); |
|
| 2070 | + EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso')); |
|
| 2071 | + EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso')); |
|
| 2072 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 2073 | + EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso')); |
|
| 2074 | + EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso')); |
|
| 2075 | + EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso')); |
|
| 2076 | + EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso')); |
|
| 2077 | + EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso')); |
|
| 2078 | + EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso')); |
|
| 2079 | + EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso')); |
|
| 2080 | + EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso')); |
|
| 2081 | + EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso')); |
|
| 2082 | + EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso')); |
|
| 2083 | + EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso')); |
|
| 2084 | + EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso')); |
|
| 2085 | + EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso')); |
|
| 2086 | + EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso')); |
|
| 2087 | + EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso')); |
|
| 2088 | + EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso')); |
|
| 2089 | + EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso')); |
|
| 2090 | + EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso')); |
|
| 2091 | + EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso')); |
|
| 2092 | + EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso')); |
|
| 2093 | + EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso')); |
|
| 2094 | + EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso')); |
|
| 2095 | + EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso')); |
|
| 2096 | + EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso')); |
|
| 2097 | + EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso')); |
|
| 2098 | + EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso')); |
|
| 2099 | + EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso')); |
|
| 2100 | + EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso')); |
|
| 2101 | + EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso')); |
|
| 2102 | + EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso')); |
|
| 2103 | + EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso')); |
|
| 2104 | + EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso')); |
|
| 2105 | + EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso')); |
|
| 2106 | + } |
|
| 2107 | + |
|
| 2108 | + |
|
| 2109 | + /** |
|
| 2110 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2111 | + * |
|
| 2112 | + * @return void |
|
| 2113 | + */ |
|
| 2114 | + public function add_xdebug_style() |
|
| 2115 | + { |
|
| 2116 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2117 | + } |
|
| 2118 | + |
|
| 2119 | + |
|
| 2120 | + /************************/ |
|
| 2121 | + /** LIST TABLE METHODS **/ |
|
| 2122 | + /************************/ |
|
| 2123 | + /** |
|
| 2124 | + * this sets up the list table if the current view requires it. |
|
| 2125 | + * |
|
| 2126 | + * @return void |
|
| 2127 | + * @throws EE_Error |
|
| 2128 | + */ |
|
| 2129 | + protected function _set_list_table() |
|
| 2130 | + { |
|
| 2131 | + // first is this a list_table view? |
|
| 2132 | + if (! isset($this->_route_config['list_table'])) { |
|
| 2133 | + return; |
|
| 2134 | + } //not a list_table view so get out. |
|
| 2135 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2136 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2137 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2138 | + // user error msg |
|
| 2139 | + $error_msg = esc_html__( |
|
| 2140 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2141 | + 'event_espresso' |
|
| 2142 | + ); |
|
| 2143 | + // developer error msg |
|
| 2144 | + $error_msg .= '||' |
|
| 2145 | + . sprintf( |
|
| 2146 | + esc_html__( |
|
| 2147 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
| 2148 | + 'event_espresso' |
|
| 2149 | + ), |
|
| 2150 | + $this->_req_action, |
|
| 2151 | + $list_table_view |
|
| 2152 | + ); |
|
| 2153 | + throw new EE_Error($error_msg); |
|
| 2154 | + } |
|
| 2155 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2156 | + $this->_views = apply_filters( |
|
| 2157 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2158 | + $this->_views |
|
| 2159 | + ); |
|
| 2160 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2161 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2162 | + $this->_set_list_table_view(); |
|
| 2163 | + $this->_set_list_table_object(); |
|
| 2164 | + } |
|
| 2165 | + |
|
| 2166 | + |
|
| 2167 | + /** |
|
| 2168 | + * set current view for List Table |
|
| 2169 | + * |
|
| 2170 | + * @return void |
|
| 2171 | + */ |
|
| 2172 | + protected function _set_list_table_view() |
|
| 2173 | + { |
|
| 2174 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2175 | + $status = $this->request->getRequestParam('status', null, 'key'); |
|
| 2176 | + $this->_view = $status && array_key_exists($status, $this->_views) |
|
| 2177 | + ? $status |
|
| 2178 | + : $this->_view; |
|
| 2179 | + } |
|
| 2180 | + |
|
| 2181 | + |
|
| 2182 | + /** |
|
| 2183 | + * _set_list_table_object |
|
| 2184 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2185 | + * |
|
| 2186 | + * @throws InvalidInterfaceException |
|
| 2187 | + * @throws InvalidArgumentException |
|
| 2188 | + * @throws InvalidDataTypeException |
|
| 2189 | + * @throws EE_Error |
|
| 2190 | + * @throws InvalidInterfaceException |
|
| 2191 | + */ |
|
| 2192 | + protected function _set_list_table_object() |
|
| 2193 | + { |
|
| 2194 | + if (isset($this->_route_config['list_table'])) { |
|
| 2195 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2196 | + throw new EE_Error( |
|
| 2197 | + sprintf( |
|
| 2198 | + esc_html__( |
|
| 2199 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
| 2200 | + 'event_espresso' |
|
| 2201 | + ), |
|
| 2202 | + $this->_route_config['list_table'], |
|
| 2203 | + get_class($this) |
|
| 2204 | + ) |
|
| 2205 | + ); |
|
| 2206 | + } |
|
| 2207 | + $this->_list_table_object = $this->loader->getShared( |
|
| 2208 | + $this->_route_config['list_table'], |
|
| 2209 | + [$this] |
|
| 2210 | + ); |
|
| 2211 | + } |
|
| 2212 | + } |
|
| 2213 | + |
|
| 2214 | + |
|
| 2215 | + /** |
|
| 2216 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2217 | + * |
|
| 2218 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2219 | + * urls. The array should be indexed by the view it is being |
|
| 2220 | + * added to. |
|
| 2221 | + * @return array |
|
| 2222 | + */ |
|
| 2223 | + public function get_list_table_view_RLs($extra_query_args = []) |
|
| 2224 | + { |
|
| 2225 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2226 | + if (empty($this->_views)) { |
|
| 2227 | + $this->_views = []; |
|
| 2228 | + } |
|
| 2229 | + // cycle thru views |
|
| 2230 | + foreach ($this->_views as $key => $view) { |
|
| 2231 | + $query_args = []; |
|
| 2232 | + // check for current view |
|
| 2233 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2234 | + $query_args['action'] = $this->_req_action; |
|
| 2235 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2236 | + $query_args['status'] = $view['slug']; |
|
| 2237 | + // merge any other arguments sent in. |
|
| 2238 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2239 | + $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
| 2240 | + } |
|
| 2241 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2242 | + } |
|
| 2243 | + return $this->_views; |
|
| 2244 | + } |
|
| 2245 | + |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * _entries_per_page_dropdown |
|
| 2249 | + * generates a dropdown box for selecting the number of visible rows in an admin page list table |
|
| 2250 | + * |
|
| 2251 | + * @param int $max_entries total number of rows in the table |
|
| 2252 | + * @return string |
|
| 2253 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2254 | + * WP does it. |
|
| 2255 | + */ |
|
| 2256 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2257 | + { |
|
| 2258 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2259 | + $values = [10, 25, 50, 100]; |
|
| 2260 | + $per_page = $this->request->getRequestParam('per_page', 10, 'int'); |
|
| 2261 | + if ($max_entries) { |
|
| 2262 | + $values[] = $max_entries; |
|
| 2263 | + sort($values); |
|
| 2264 | + } |
|
| 2265 | + $entries_per_page_dropdown = ' |
|
| 2266 | 2266 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2267 | 2267 | <label class="hide-if-no-js"> |
| 2268 | 2268 | Show |
| 2269 | 2269 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2270 | - foreach ($values as $value) { |
|
| 2271 | - if ($value < $max_entries) { |
|
| 2272 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2273 | - $entries_per_page_dropdown .= ' |
|
| 2270 | + foreach ($values as $value) { |
|
| 2271 | + if ($value < $max_entries) { |
|
| 2272 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2273 | + $entries_per_page_dropdown .= ' |
|
| 2274 | 2274 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2275 | - } |
|
| 2276 | - } |
|
| 2277 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2278 | - $entries_per_page_dropdown .= ' |
|
| 2275 | + } |
|
| 2276 | + } |
|
| 2277 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2278 | + $entries_per_page_dropdown .= ' |
|
| 2279 | 2279 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2280 | - $entries_per_page_dropdown .= ' |
|
| 2280 | + $entries_per_page_dropdown .= ' |
|
| 2281 | 2281 | </select> |
| 2282 | 2282 | entries |
| 2283 | 2283 | </label> |
| 2284 | 2284 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2285 | 2285 | </div> |
| 2286 | 2286 | '; |
| 2287 | - return $entries_per_page_dropdown; |
|
| 2288 | - } |
|
| 2289 | - |
|
| 2290 | - |
|
| 2291 | - /** |
|
| 2292 | - * _set_search_attributes |
|
| 2293 | - * |
|
| 2294 | - * @return void |
|
| 2295 | - */ |
|
| 2296 | - public function _set_search_attributes() |
|
| 2297 | - { |
|
| 2298 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2299 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2300 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2301 | - : $this->_search_btn_label |
|
| 2302 | - ); |
|
| 2303 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2304 | - } |
|
| 2305 | - |
|
| 2306 | - |
|
| 2307 | - |
|
| 2308 | - /*** END LIST TABLE METHODS **/ |
|
| 2309 | - |
|
| 2310 | - |
|
| 2311 | - /** |
|
| 2312 | - * _add_registered_metaboxes |
|
| 2313 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2314 | - * |
|
| 2315 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2316 | - * @return void |
|
| 2317 | - * @throws EE_Error |
|
| 2318 | - */ |
|
| 2319 | - private function _add_registered_meta_boxes() |
|
| 2320 | - { |
|
| 2321 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2322 | - // we only add meta boxes if the page_route calls for it |
|
| 2323 | - if ( |
|
| 2324 | - is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2325 | - && is_array( |
|
| 2326 | - $this->_route_config['metaboxes'] |
|
| 2327 | - ) |
|
| 2328 | - ) { |
|
| 2329 | - // this simply loops through the callbacks provided |
|
| 2330 | - // and checks if there is a corresponding callback registered by the child |
|
| 2331 | - // if there is then we go ahead and process the metabox loader. |
|
| 2332 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2333 | - // first check for Closures |
|
| 2334 | - if ($metabox_callback instanceof Closure) { |
|
| 2335 | - $result = $metabox_callback(); |
|
| 2336 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2337 | - $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2338 | - } else { |
|
| 2339 | - $result = call_user_func([$this, &$metabox_callback]); |
|
| 2340 | - } |
|
| 2341 | - if ($result === false) { |
|
| 2342 | - // user error msg |
|
| 2343 | - $error_msg = esc_html__( |
|
| 2344 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2345 | - 'event_espresso' |
|
| 2346 | - ); |
|
| 2347 | - // developer error msg |
|
| 2348 | - $error_msg .= '||' |
|
| 2349 | - . sprintf( |
|
| 2350 | - esc_html__( |
|
| 2351 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2352 | - 'event_espresso' |
|
| 2353 | - ), |
|
| 2354 | - $metabox_callback |
|
| 2355 | - ); |
|
| 2356 | - throw new EE_Error($error_msg); |
|
| 2357 | - } |
|
| 2358 | - } |
|
| 2359 | - } |
|
| 2360 | - } |
|
| 2361 | - |
|
| 2362 | - |
|
| 2363 | - /** |
|
| 2364 | - * _add_screen_columns |
|
| 2365 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2366 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2367 | - * |
|
| 2368 | - * @return void |
|
| 2369 | - */ |
|
| 2370 | - private function _add_screen_columns() |
|
| 2371 | - { |
|
| 2372 | - if ( |
|
| 2373 | - is_array($this->_route_config) |
|
| 2374 | - && isset($this->_route_config['columns']) |
|
| 2375 | - && is_array($this->_route_config['columns']) |
|
| 2376 | - && count($this->_route_config['columns']) === 2 |
|
| 2377 | - ) { |
|
| 2378 | - add_screen_option( |
|
| 2379 | - 'layout_columns', |
|
| 2380 | - [ |
|
| 2381 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2382 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2383 | - ] |
|
| 2384 | - ); |
|
| 2385 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2386 | - $screen_id = $this->_current_screen->id; |
|
| 2387 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2388 | - $total_columns = ! empty($screen_columns) |
|
| 2389 | - ? $screen_columns |
|
| 2390 | - : $this->_route_config['columns'][1]; |
|
| 2391 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2392 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2393 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2394 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2395 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2396 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2397 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2398 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2399 | - } |
|
| 2400 | - } |
|
| 2401 | - |
|
| 2402 | - |
|
| 2403 | - |
|
| 2404 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2405 | - |
|
| 2406 | - |
|
| 2407 | - /** |
|
| 2408 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2409 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2410 | - * these get loaded on. |
|
| 2411 | - */ |
|
| 2412 | - private function _espresso_news_post_box() |
|
| 2413 | - { |
|
| 2414 | - $news_box_title = apply_filters( |
|
| 2415 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2416 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2417 | - ); |
|
| 2418 | - add_meta_box( |
|
| 2419 | - 'espresso_news_post_box', |
|
| 2420 | - $news_box_title, |
|
| 2421 | - [ |
|
| 2422 | - $this, |
|
| 2423 | - 'espresso_news_post_box', |
|
| 2424 | - ], |
|
| 2425 | - $this->_wp_page_slug, |
|
| 2426 | - 'side' |
|
| 2427 | - ); |
|
| 2428 | - } |
|
| 2429 | - |
|
| 2430 | - |
|
| 2431 | - /** |
|
| 2432 | - * Code for setting up espresso ratings request metabox. |
|
| 2433 | - */ |
|
| 2434 | - protected function _espresso_ratings_request() |
|
| 2435 | - { |
|
| 2436 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2437 | - return; |
|
| 2438 | - } |
|
| 2439 | - $ratings_box_title = apply_filters( |
|
| 2440 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2441 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2442 | - ); |
|
| 2443 | - add_meta_box( |
|
| 2444 | - 'espresso_ratings_request', |
|
| 2445 | - $ratings_box_title, |
|
| 2446 | - [ |
|
| 2447 | - $this, |
|
| 2448 | - 'espresso_ratings_request', |
|
| 2449 | - ], |
|
| 2450 | - $this->_wp_page_slug, |
|
| 2451 | - 'side' |
|
| 2452 | - ); |
|
| 2453 | - } |
|
| 2454 | - |
|
| 2455 | - |
|
| 2456 | - /** |
|
| 2457 | - * Code for setting up espresso ratings request metabox content. |
|
| 2458 | - * |
|
| 2459 | - * @throws DomainException |
|
| 2460 | - */ |
|
| 2461 | - public function espresso_ratings_request() |
|
| 2462 | - { |
|
| 2463 | - EEH_Template::display_template( |
|
| 2464 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2465 | - [] |
|
| 2466 | - ); |
|
| 2467 | - } |
|
| 2468 | - |
|
| 2469 | - |
|
| 2470 | - public static function cached_rss_display($rss_id, $url) |
|
| 2471 | - { |
|
| 2472 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2473 | - . esc_html__('Loading…', 'event_espresso') |
|
| 2474 | - . '</p><p class="hide-if-js">' |
|
| 2475 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2476 | - . '</p>'; |
|
| 2477 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2478 | - $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2479 | - $post = '</div>' . "\n"; |
|
| 2480 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2481 | - $output = get_transient($cache_key); |
|
| 2482 | - if ($output !== false) { |
|
| 2483 | - echo $pre . $output . $post; // already escaped |
|
| 2484 | - return true; |
|
| 2485 | - } |
|
| 2486 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2487 | - echo $pre . $loading . $post; // already escaped |
|
| 2488 | - return false; |
|
| 2489 | - } |
|
| 2490 | - ob_start(); |
|
| 2491 | - wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2492 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2493 | - return true; |
|
| 2494 | - } |
|
| 2495 | - |
|
| 2496 | - |
|
| 2497 | - public function espresso_news_post_box() |
|
| 2498 | - { |
|
| 2499 | - ?> |
|
| 2287 | + return $entries_per_page_dropdown; |
|
| 2288 | + } |
|
| 2289 | + |
|
| 2290 | + |
|
| 2291 | + /** |
|
| 2292 | + * _set_search_attributes |
|
| 2293 | + * |
|
| 2294 | + * @return void |
|
| 2295 | + */ |
|
| 2296 | + public function _set_search_attributes() |
|
| 2297 | + { |
|
| 2298 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2299 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2300 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2301 | + : $this->_search_btn_label |
|
| 2302 | + ); |
|
| 2303 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2304 | + } |
|
| 2305 | + |
|
| 2306 | + |
|
| 2307 | + |
|
| 2308 | + /*** END LIST TABLE METHODS **/ |
|
| 2309 | + |
|
| 2310 | + |
|
| 2311 | + /** |
|
| 2312 | + * _add_registered_metaboxes |
|
| 2313 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2314 | + * |
|
| 2315 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2316 | + * @return void |
|
| 2317 | + * @throws EE_Error |
|
| 2318 | + */ |
|
| 2319 | + private function _add_registered_meta_boxes() |
|
| 2320 | + { |
|
| 2321 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2322 | + // we only add meta boxes if the page_route calls for it |
|
| 2323 | + if ( |
|
| 2324 | + is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2325 | + && is_array( |
|
| 2326 | + $this->_route_config['metaboxes'] |
|
| 2327 | + ) |
|
| 2328 | + ) { |
|
| 2329 | + // this simply loops through the callbacks provided |
|
| 2330 | + // and checks if there is a corresponding callback registered by the child |
|
| 2331 | + // if there is then we go ahead and process the metabox loader. |
|
| 2332 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2333 | + // first check for Closures |
|
| 2334 | + if ($metabox_callback instanceof Closure) { |
|
| 2335 | + $result = $metabox_callback(); |
|
| 2336 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2337 | + $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]); |
|
| 2338 | + } else { |
|
| 2339 | + $result = call_user_func([$this, &$metabox_callback]); |
|
| 2340 | + } |
|
| 2341 | + if ($result === false) { |
|
| 2342 | + // user error msg |
|
| 2343 | + $error_msg = esc_html__( |
|
| 2344 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2345 | + 'event_espresso' |
|
| 2346 | + ); |
|
| 2347 | + // developer error msg |
|
| 2348 | + $error_msg .= '||' |
|
| 2349 | + . sprintf( |
|
| 2350 | + esc_html__( |
|
| 2351 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
| 2352 | + 'event_espresso' |
|
| 2353 | + ), |
|
| 2354 | + $metabox_callback |
|
| 2355 | + ); |
|
| 2356 | + throw new EE_Error($error_msg); |
|
| 2357 | + } |
|
| 2358 | + } |
|
| 2359 | + } |
|
| 2360 | + } |
|
| 2361 | + |
|
| 2362 | + |
|
| 2363 | + /** |
|
| 2364 | + * _add_screen_columns |
|
| 2365 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2366 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2367 | + * |
|
| 2368 | + * @return void |
|
| 2369 | + */ |
|
| 2370 | + private function _add_screen_columns() |
|
| 2371 | + { |
|
| 2372 | + if ( |
|
| 2373 | + is_array($this->_route_config) |
|
| 2374 | + && isset($this->_route_config['columns']) |
|
| 2375 | + && is_array($this->_route_config['columns']) |
|
| 2376 | + && count($this->_route_config['columns']) === 2 |
|
| 2377 | + ) { |
|
| 2378 | + add_screen_option( |
|
| 2379 | + 'layout_columns', |
|
| 2380 | + [ |
|
| 2381 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2382 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2383 | + ] |
|
| 2384 | + ); |
|
| 2385 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2386 | + $screen_id = $this->_current_screen->id; |
|
| 2387 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2388 | + $total_columns = ! empty($screen_columns) |
|
| 2389 | + ? $screen_columns |
|
| 2390 | + : $this->_route_config['columns'][1]; |
|
| 2391 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2392 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2393 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2394 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2395 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2396 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2397 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2398 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2399 | + } |
|
| 2400 | + } |
|
| 2401 | + |
|
| 2402 | + |
|
| 2403 | + |
|
| 2404 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2405 | + |
|
| 2406 | + |
|
| 2407 | + /** |
|
| 2408 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2409 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2410 | + * these get loaded on. |
|
| 2411 | + */ |
|
| 2412 | + private function _espresso_news_post_box() |
|
| 2413 | + { |
|
| 2414 | + $news_box_title = apply_filters( |
|
| 2415 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2416 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2417 | + ); |
|
| 2418 | + add_meta_box( |
|
| 2419 | + 'espresso_news_post_box', |
|
| 2420 | + $news_box_title, |
|
| 2421 | + [ |
|
| 2422 | + $this, |
|
| 2423 | + 'espresso_news_post_box', |
|
| 2424 | + ], |
|
| 2425 | + $this->_wp_page_slug, |
|
| 2426 | + 'side' |
|
| 2427 | + ); |
|
| 2428 | + } |
|
| 2429 | + |
|
| 2430 | + |
|
| 2431 | + /** |
|
| 2432 | + * Code for setting up espresso ratings request metabox. |
|
| 2433 | + */ |
|
| 2434 | + protected function _espresso_ratings_request() |
|
| 2435 | + { |
|
| 2436 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2437 | + return; |
|
| 2438 | + } |
|
| 2439 | + $ratings_box_title = apply_filters( |
|
| 2440 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2441 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2442 | + ); |
|
| 2443 | + add_meta_box( |
|
| 2444 | + 'espresso_ratings_request', |
|
| 2445 | + $ratings_box_title, |
|
| 2446 | + [ |
|
| 2447 | + $this, |
|
| 2448 | + 'espresso_ratings_request', |
|
| 2449 | + ], |
|
| 2450 | + $this->_wp_page_slug, |
|
| 2451 | + 'side' |
|
| 2452 | + ); |
|
| 2453 | + } |
|
| 2454 | + |
|
| 2455 | + |
|
| 2456 | + /** |
|
| 2457 | + * Code for setting up espresso ratings request metabox content. |
|
| 2458 | + * |
|
| 2459 | + * @throws DomainException |
|
| 2460 | + */ |
|
| 2461 | + public function espresso_ratings_request() |
|
| 2462 | + { |
|
| 2463 | + EEH_Template::display_template( |
|
| 2464 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
| 2465 | + [] |
|
| 2466 | + ); |
|
| 2467 | + } |
|
| 2468 | + |
|
| 2469 | + |
|
| 2470 | + public static function cached_rss_display($rss_id, $url) |
|
| 2471 | + { |
|
| 2472 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2473 | + . esc_html__('Loading…', 'event_espresso') |
|
| 2474 | + . '</p><p class="hide-if-js">' |
|
| 2475 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2476 | + . '</p>'; |
|
| 2477 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2478 | + $pre .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>'; |
|
| 2479 | + $post = '</div>' . "\n"; |
|
| 2480 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2481 | + $output = get_transient($cache_key); |
|
| 2482 | + if ($output !== false) { |
|
| 2483 | + echo $pre . $output . $post; // already escaped |
|
| 2484 | + return true; |
|
| 2485 | + } |
|
| 2486 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2487 | + echo $pre . $loading . $post; // already escaped |
|
| 2488 | + return false; |
|
| 2489 | + } |
|
| 2490 | + ob_start(); |
|
| 2491 | + wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]); |
|
| 2492 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2493 | + return true; |
|
| 2494 | + } |
|
| 2495 | + |
|
| 2496 | + |
|
| 2497 | + public function espresso_news_post_box() |
|
| 2498 | + { |
|
| 2499 | + ?> |
|
| 2500 | 2500 | <div class="padding"> |
| 2501 | 2501 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2502 | 2502 | <?php |
| 2503 | - // Get RSS Feed(s) |
|
| 2504 | - self::cached_rss_display( |
|
| 2505 | - 'espresso_news_post_box_content', |
|
| 2506 | - esc_url_raw( |
|
| 2507 | - apply_filters( |
|
| 2508 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2509 | - 'https://eventespresso.com/feed/' |
|
| 2510 | - ) |
|
| 2511 | - ) |
|
| 2512 | - ); |
|
| 2513 | - ?> |
|
| 2503 | + // Get RSS Feed(s) |
|
| 2504 | + self::cached_rss_display( |
|
| 2505 | + 'espresso_news_post_box_content', |
|
| 2506 | + esc_url_raw( |
|
| 2507 | + apply_filters( |
|
| 2508 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2509 | + 'https://eventespresso.com/feed/' |
|
| 2510 | + ) |
|
| 2511 | + ) |
|
| 2512 | + ); |
|
| 2513 | + ?> |
|
| 2514 | 2514 | </div> |
| 2515 | 2515 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2516 | 2516 | </div> |
| 2517 | 2517 | <?php |
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - |
|
| 2521 | - private function _espresso_links_post_box() |
|
| 2522 | - { |
|
| 2523 | - // Hiding until we actually have content to put in here... |
|
| 2524 | - // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2525 | - } |
|
| 2526 | - |
|
| 2527 | - |
|
| 2528 | - public function espresso_links_post_box() |
|
| 2529 | - { |
|
| 2530 | - // Hiding until we actually have content to put in here... |
|
| 2531 | - // EEH_Template::display_template( |
|
| 2532 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2533 | - // ); |
|
| 2534 | - } |
|
| 2535 | - |
|
| 2536 | - |
|
| 2537 | - protected function _espresso_sponsors_post_box() |
|
| 2538 | - { |
|
| 2539 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2540 | - add_meta_box( |
|
| 2541 | - 'espresso_sponsors_post_box', |
|
| 2542 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2543 | - [$this, 'espresso_sponsors_post_box'], |
|
| 2544 | - $this->_wp_page_slug, |
|
| 2545 | - 'side' |
|
| 2546 | - ); |
|
| 2547 | - } |
|
| 2548 | - } |
|
| 2549 | - |
|
| 2550 | - |
|
| 2551 | - public function espresso_sponsors_post_box() |
|
| 2552 | - { |
|
| 2553 | - EEH_Template::display_template( |
|
| 2554 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2555 | - ); |
|
| 2556 | - } |
|
| 2557 | - |
|
| 2558 | - |
|
| 2559 | - private function _publish_post_box() |
|
| 2560 | - { |
|
| 2561 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2562 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2563 | - // then we'll use that for the metabox label. |
|
| 2564 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2565 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2566 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2567 | - : $this->_labels['publishbox']; |
|
| 2568 | - } else { |
|
| 2569 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2570 | - } |
|
| 2571 | - $box_label = apply_filters( |
|
| 2572 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2573 | - $box_label, |
|
| 2574 | - $this->_req_action, |
|
| 2575 | - $this |
|
| 2576 | - ); |
|
| 2577 | - add_meta_box( |
|
| 2578 | - $meta_box_ref, |
|
| 2579 | - $box_label, |
|
| 2580 | - [$this, 'editor_overview'], |
|
| 2581 | - $this->_current_screen->id, |
|
| 2582 | - 'side', |
|
| 2583 | - 'high' |
|
| 2584 | - ); |
|
| 2585 | - } |
|
| 2586 | - |
|
| 2587 | - |
|
| 2588 | - public function editor_overview() |
|
| 2589 | - { |
|
| 2590 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2591 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2592 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2593 | - : ''; |
|
| 2594 | - echo EEH_Template::display_template( |
|
| 2595 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2596 | - $this->_template_args, |
|
| 2597 | - true |
|
| 2598 | - ); |
|
| 2599 | - } |
|
| 2600 | - |
|
| 2601 | - |
|
| 2602 | - /** end of globally available metaboxes section **/ |
|
| 2603 | - |
|
| 2604 | - |
|
| 2605 | - /** |
|
| 2606 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2607 | - * protected method. |
|
| 2608 | - * |
|
| 2609 | - * @param string $name |
|
| 2610 | - * @param int $id |
|
| 2611 | - * @param bool $delete |
|
| 2612 | - * @param string $save_close_redirect_URL |
|
| 2613 | - * @param bool $both_btns |
|
| 2614 | - * @throws EE_Error |
|
| 2615 | - * @throws InvalidArgumentException |
|
| 2616 | - * @throws InvalidDataTypeException |
|
| 2617 | - * @throws InvalidInterfaceException |
|
| 2618 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2619 | - * @since 4.6.0 |
|
| 2620 | - */ |
|
| 2621 | - public function set_publish_post_box_vars( |
|
| 2622 | - $name = '', |
|
| 2623 | - $id = 0, |
|
| 2624 | - $delete = false, |
|
| 2625 | - $save_close_redirect_URL = '', |
|
| 2626 | - $both_btns = true |
|
| 2627 | - ) { |
|
| 2628 | - $this->_set_publish_post_box_vars( |
|
| 2629 | - $name, |
|
| 2630 | - $id, |
|
| 2631 | - $delete, |
|
| 2632 | - $save_close_redirect_URL, |
|
| 2633 | - $both_btns |
|
| 2634 | - ); |
|
| 2635 | - } |
|
| 2636 | - |
|
| 2637 | - |
|
| 2638 | - /** |
|
| 2639 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2640 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2641 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2642 | - * values for the name and id arguments. |
|
| 2643 | - * |
|
| 2644 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2645 | - * @param int $id id attached to the item published |
|
| 2646 | - * @param string $delete page route callback for the delete action |
|
| 2647 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2648 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2649 | - * the Save button |
|
| 2650 | - * @throws EE_Error |
|
| 2651 | - * @throws InvalidArgumentException |
|
| 2652 | - * @throws InvalidDataTypeException |
|
| 2653 | - * @throws InvalidInterfaceException |
|
| 2654 | - * @todo Add in validation for name/id arguments. |
|
| 2655 | - */ |
|
| 2656 | - protected function _set_publish_post_box_vars( |
|
| 2657 | - $name = '', |
|
| 2658 | - $id = 0, |
|
| 2659 | - $delete = '', |
|
| 2660 | - $save_close_redirect_URL = '', |
|
| 2661 | - $both_btns = true |
|
| 2662 | - ) { |
|
| 2663 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2664 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2665 | - ? $save_close_redirect_URL |
|
| 2666 | - : $this->_admin_base_url; |
|
| 2667 | - // create the Save & Close and Save buttons |
|
| 2668 | - $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2669 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2670 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2671 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2672 | - : ''; |
|
| 2673 | - if ($delete && ! empty($id)) { |
|
| 2674 | - // make sure we have a default if just true is sent. |
|
| 2675 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2676 | - $delete_link_args = [$name => $id]; |
|
| 2677 | - $delete = $this->get_action_link_or_button( |
|
| 2678 | - $delete, |
|
| 2679 | - $delete, |
|
| 2680 | - $delete_link_args, |
|
| 2681 | - 'submitdelete deletion', |
|
| 2682 | - '', |
|
| 2683 | - false |
|
| 2684 | - ); |
|
| 2685 | - } |
|
| 2686 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2687 | - if (! empty($name) && ! empty($id)) { |
|
| 2688 | - $hidden_field_arr[ $name ] = [ |
|
| 2689 | - 'type' => 'hidden', |
|
| 2690 | - 'value' => $id, |
|
| 2691 | - ]; |
|
| 2692 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2693 | - } else { |
|
| 2694 | - $hf = ''; |
|
| 2695 | - } |
|
| 2696 | - // add hidden field |
|
| 2697 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2698 | - ? $hf[ $name ]['field'] |
|
| 2699 | - : $hf; |
|
| 2700 | - } |
|
| 2701 | - |
|
| 2702 | - |
|
| 2703 | - /** |
|
| 2704 | - * displays an error message to ppl who have javascript disabled |
|
| 2705 | - * |
|
| 2706 | - * @return void |
|
| 2707 | - */ |
|
| 2708 | - private function _display_no_javascript_warning() |
|
| 2709 | - { |
|
| 2710 | - ?> |
|
| 2518 | + } |
|
| 2519 | + |
|
| 2520 | + |
|
| 2521 | + private function _espresso_links_post_box() |
|
| 2522 | + { |
|
| 2523 | + // Hiding until we actually have content to put in here... |
|
| 2524 | + // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
| 2525 | + } |
|
| 2526 | + |
|
| 2527 | + |
|
| 2528 | + public function espresso_links_post_box() |
|
| 2529 | + { |
|
| 2530 | + // Hiding until we actually have content to put in here... |
|
| 2531 | + // EEH_Template::display_template( |
|
| 2532 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2533 | + // ); |
|
| 2534 | + } |
|
| 2535 | + |
|
| 2536 | + |
|
| 2537 | + protected function _espresso_sponsors_post_box() |
|
| 2538 | + { |
|
| 2539 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2540 | + add_meta_box( |
|
| 2541 | + 'espresso_sponsors_post_box', |
|
| 2542 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2543 | + [$this, 'espresso_sponsors_post_box'], |
|
| 2544 | + $this->_wp_page_slug, |
|
| 2545 | + 'side' |
|
| 2546 | + ); |
|
| 2547 | + } |
|
| 2548 | + } |
|
| 2549 | + |
|
| 2550 | + |
|
| 2551 | + public function espresso_sponsors_post_box() |
|
| 2552 | + { |
|
| 2553 | + EEH_Template::display_template( |
|
| 2554 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2555 | + ); |
|
| 2556 | + } |
|
| 2557 | + |
|
| 2558 | + |
|
| 2559 | + private function _publish_post_box() |
|
| 2560 | + { |
|
| 2561 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2562 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2563 | + // then we'll use that for the metabox label. |
|
| 2564 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2565 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2566 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2567 | + : $this->_labels['publishbox']; |
|
| 2568 | + } else { |
|
| 2569 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2570 | + } |
|
| 2571 | + $box_label = apply_filters( |
|
| 2572 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2573 | + $box_label, |
|
| 2574 | + $this->_req_action, |
|
| 2575 | + $this |
|
| 2576 | + ); |
|
| 2577 | + add_meta_box( |
|
| 2578 | + $meta_box_ref, |
|
| 2579 | + $box_label, |
|
| 2580 | + [$this, 'editor_overview'], |
|
| 2581 | + $this->_current_screen->id, |
|
| 2582 | + 'side', |
|
| 2583 | + 'high' |
|
| 2584 | + ); |
|
| 2585 | + } |
|
| 2586 | + |
|
| 2587 | + |
|
| 2588 | + public function editor_overview() |
|
| 2589 | + { |
|
| 2590 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2591 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2592 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2593 | + : ''; |
|
| 2594 | + echo EEH_Template::display_template( |
|
| 2595 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2596 | + $this->_template_args, |
|
| 2597 | + true |
|
| 2598 | + ); |
|
| 2599 | + } |
|
| 2600 | + |
|
| 2601 | + |
|
| 2602 | + /** end of globally available metaboxes section **/ |
|
| 2603 | + |
|
| 2604 | + |
|
| 2605 | + /** |
|
| 2606 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2607 | + * protected method. |
|
| 2608 | + * |
|
| 2609 | + * @param string $name |
|
| 2610 | + * @param int $id |
|
| 2611 | + * @param bool $delete |
|
| 2612 | + * @param string $save_close_redirect_URL |
|
| 2613 | + * @param bool $both_btns |
|
| 2614 | + * @throws EE_Error |
|
| 2615 | + * @throws InvalidArgumentException |
|
| 2616 | + * @throws InvalidDataTypeException |
|
| 2617 | + * @throws InvalidInterfaceException |
|
| 2618 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2619 | + * @since 4.6.0 |
|
| 2620 | + */ |
|
| 2621 | + public function set_publish_post_box_vars( |
|
| 2622 | + $name = '', |
|
| 2623 | + $id = 0, |
|
| 2624 | + $delete = false, |
|
| 2625 | + $save_close_redirect_URL = '', |
|
| 2626 | + $both_btns = true |
|
| 2627 | + ) { |
|
| 2628 | + $this->_set_publish_post_box_vars( |
|
| 2629 | + $name, |
|
| 2630 | + $id, |
|
| 2631 | + $delete, |
|
| 2632 | + $save_close_redirect_URL, |
|
| 2633 | + $both_btns |
|
| 2634 | + ); |
|
| 2635 | + } |
|
| 2636 | + |
|
| 2637 | + |
|
| 2638 | + /** |
|
| 2639 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2640 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2641 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2642 | + * values for the name and id arguments. |
|
| 2643 | + * |
|
| 2644 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2645 | + * @param int $id id attached to the item published |
|
| 2646 | + * @param string $delete page route callback for the delete action |
|
| 2647 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2648 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2649 | + * the Save button |
|
| 2650 | + * @throws EE_Error |
|
| 2651 | + * @throws InvalidArgumentException |
|
| 2652 | + * @throws InvalidDataTypeException |
|
| 2653 | + * @throws InvalidInterfaceException |
|
| 2654 | + * @todo Add in validation for name/id arguments. |
|
| 2655 | + */ |
|
| 2656 | + protected function _set_publish_post_box_vars( |
|
| 2657 | + $name = '', |
|
| 2658 | + $id = 0, |
|
| 2659 | + $delete = '', |
|
| 2660 | + $save_close_redirect_URL = '', |
|
| 2661 | + $both_btns = true |
|
| 2662 | + ) { |
|
| 2663 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2664 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2665 | + ? $save_close_redirect_URL |
|
| 2666 | + : $this->_admin_base_url; |
|
| 2667 | + // create the Save & Close and Save buttons |
|
| 2668 | + $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL); |
|
| 2669 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2670 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2671 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2672 | + : ''; |
|
| 2673 | + if ($delete && ! empty($id)) { |
|
| 2674 | + // make sure we have a default if just true is sent. |
|
| 2675 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2676 | + $delete_link_args = [$name => $id]; |
|
| 2677 | + $delete = $this->get_action_link_or_button( |
|
| 2678 | + $delete, |
|
| 2679 | + $delete, |
|
| 2680 | + $delete_link_args, |
|
| 2681 | + 'submitdelete deletion', |
|
| 2682 | + '', |
|
| 2683 | + false |
|
| 2684 | + ); |
|
| 2685 | + } |
|
| 2686 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2687 | + if (! empty($name) && ! empty($id)) { |
|
| 2688 | + $hidden_field_arr[ $name ] = [ |
|
| 2689 | + 'type' => 'hidden', |
|
| 2690 | + 'value' => $id, |
|
| 2691 | + ]; |
|
| 2692 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2693 | + } else { |
|
| 2694 | + $hf = ''; |
|
| 2695 | + } |
|
| 2696 | + // add hidden field |
|
| 2697 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2698 | + ? $hf[ $name ]['field'] |
|
| 2699 | + : $hf; |
|
| 2700 | + } |
|
| 2701 | + |
|
| 2702 | + |
|
| 2703 | + /** |
|
| 2704 | + * displays an error message to ppl who have javascript disabled |
|
| 2705 | + * |
|
| 2706 | + * @return void |
|
| 2707 | + */ |
|
| 2708 | + private function _display_no_javascript_warning() |
|
| 2709 | + { |
|
| 2710 | + ?> |
|
| 2711 | 2711 | <noscript> |
| 2712 | 2712 | <div id="no-js-message" class="error"> |
| 2713 | 2713 | <p style="font-size:1.3em;"> |
| 2714 | 2714 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2715 | 2715 | <?php esc_html_e( |
| 2716 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2717 | - 'event_espresso' |
|
| 2718 | - ); ?> |
|
| 2716 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
| 2717 | + 'event_espresso' |
|
| 2718 | + ); ?> |
|
| 2719 | 2719 | </p> |
| 2720 | 2720 | </div> |
| 2721 | 2721 | </noscript> |
| 2722 | 2722 | <?php |
| 2723 | - } |
|
| 2724 | - |
|
| 2725 | - |
|
| 2726 | - /** |
|
| 2727 | - * displays espresso success and/or error notices |
|
| 2728 | - * |
|
| 2729 | - * @return void |
|
| 2730 | - */ |
|
| 2731 | - protected function _display_espresso_notices() |
|
| 2732 | - { |
|
| 2733 | - $notices = $this->_get_transient(true); |
|
| 2734 | - echo stripslashes($notices); |
|
| 2735 | - } |
|
| 2736 | - |
|
| 2737 | - |
|
| 2738 | - /** |
|
| 2739 | - * spinny things pacify the masses |
|
| 2740 | - * |
|
| 2741 | - * @return void |
|
| 2742 | - */ |
|
| 2743 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2744 | - { |
|
| 2745 | - ?> |
|
| 2723 | + } |
|
| 2724 | + |
|
| 2725 | + |
|
| 2726 | + /** |
|
| 2727 | + * displays espresso success and/or error notices |
|
| 2728 | + * |
|
| 2729 | + * @return void |
|
| 2730 | + */ |
|
| 2731 | + protected function _display_espresso_notices() |
|
| 2732 | + { |
|
| 2733 | + $notices = $this->_get_transient(true); |
|
| 2734 | + echo stripslashes($notices); |
|
| 2735 | + } |
|
| 2736 | + |
|
| 2737 | + |
|
| 2738 | + /** |
|
| 2739 | + * spinny things pacify the masses |
|
| 2740 | + * |
|
| 2741 | + * @return void |
|
| 2742 | + */ |
|
| 2743 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2744 | + { |
|
| 2745 | + ?> |
|
| 2746 | 2746 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2747 | 2747 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2748 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2748 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2749 | 2749 | </div> |
| 2750 | 2750 | <?php |
| 2751 | - } |
|
| 2751 | + } |
|
| 2752 | 2752 | |
| 2753 | 2753 | |
| 2754 | - /** |
|
| 2755 | - * add admin page overlay for modal boxes |
|
| 2756 | - * |
|
| 2757 | - * @return void |
|
| 2758 | - */ |
|
| 2759 | - protected function _add_admin_page_overlay() |
|
| 2760 | - { |
|
| 2761 | - ?> |
|
| 2754 | + /** |
|
| 2755 | + * add admin page overlay for modal boxes |
|
| 2756 | + * |
|
| 2757 | + * @return void |
|
| 2758 | + */ |
|
| 2759 | + protected function _add_admin_page_overlay() |
|
| 2760 | + { |
|
| 2761 | + ?> |
|
| 2762 | 2762 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2763 | 2763 | <?php |
| 2764 | - } |
|
| 2765 | - |
|
| 2766 | - |
|
| 2767 | - /** |
|
| 2768 | - * facade for add_meta_box |
|
| 2769 | - * |
|
| 2770 | - * @param string $action where the metabox get's displayed |
|
| 2771 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2772 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2773 | - * instead of the one created in here. |
|
| 2774 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2775 | - * @param string $column what metabox column |
|
| 2776 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2777 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2778 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2779 | - * @throws DomainException |
|
| 2780 | - */ |
|
| 2781 | - public function _add_admin_page_meta_box( |
|
| 2782 | - $action, |
|
| 2783 | - $title, |
|
| 2784 | - $callback, |
|
| 2785 | - $callback_args, |
|
| 2786 | - $column = 'normal', |
|
| 2787 | - $priority = 'high', |
|
| 2788 | - $create_func = true |
|
| 2789 | - ) { |
|
| 2790 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2791 | - // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2792 | - if (empty($callback_args) && $create_func) { |
|
| 2793 | - $callback_args = [ |
|
| 2794 | - 'template_path' => $this->_template_path, |
|
| 2795 | - 'template_args' => $this->_template_args, |
|
| 2796 | - ]; |
|
| 2797 | - } |
|
| 2798 | - // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2799 | - $call_back_func = $create_func |
|
| 2800 | - ? function ($post, $metabox) { |
|
| 2801 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2802 | - echo EEH_Template::display_template( |
|
| 2803 | - $metabox['args']['template_path'], |
|
| 2804 | - $metabox['args']['template_args'], |
|
| 2805 | - true |
|
| 2806 | - ); |
|
| 2807 | - } |
|
| 2808 | - : $callback; |
|
| 2809 | - add_meta_box( |
|
| 2810 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2811 | - $title, |
|
| 2812 | - $call_back_func, |
|
| 2813 | - $this->_wp_page_slug, |
|
| 2814 | - $column, |
|
| 2815 | - $priority, |
|
| 2816 | - $callback_args |
|
| 2817 | - ); |
|
| 2818 | - } |
|
| 2819 | - |
|
| 2820 | - |
|
| 2821 | - /** |
|
| 2822 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2823 | - * |
|
| 2824 | - * @throws DomainException |
|
| 2825 | - * @throws EE_Error |
|
| 2826 | - */ |
|
| 2827 | - public function display_admin_page_with_metabox_columns() |
|
| 2828 | - { |
|
| 2829 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2830 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2831 | - $this->_column_template_path, |
|
| 2832 | - $this->_template_args, |
|
| 2833 | - true |
|
| 2834 | - ); |
|
| 2835 | - // the final wrapper |
|
| 2836 | - $this->admin_page_wrapper(); |
|
| 2837 | - } |
|
| 2838 | - |
|
| 2839 | - |
|
| 2840 | - /** |
|
| 2841 | - * generates HTML wrapper for an admin details page |
|
| 2842 | - * |
|
| 2843 | - * @return void |
|
| 2844 | - * @throws EE_Error |
|
| 2845 | - * @throws DomainException |
|
| 2846 | - */ |
|
| 2847 | - public function display_admin_page_with_sidebar() |
|
| 2848 | - { |
|
| 2849 | - $this->_display_admin_page(true); |
|
| 2850 | - } |
|
| 2851 | - |
|
| 2852 | - |
|
| 2853 | - /** |
|
| 2854 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2855 | - * |
|
| 2856 | - * @return void |
|
| 2857 | - * @throws EE_Error |
|
| 2858 | - * @throws DomainException |
|
| 2859 | - */ |
|
| 2860 | - public function display_admin_page_with_no_sidebar() |
|
| 2861 | - { |
|
| 2862 | - $this->_display_admin_page(); |
|
| 2863 | - } |
|
| 2864 | - |
|
| 2865 | - |
|
| 2866 | - /** |
|
| 2867 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2868 | - * |
|
| 2869 | - * @return void |
|
| 2870 | - * @throws EE_Error |
|
| 2871 | - * @throws DomainException |
|
| 2872 | - */ |
|
| 2873 | - public function display_about_admin_page() |
|
| 2874 | - { |
|
| 2875 | - $this->_display_admin_page(false, true); |
|
| 2876 | - } |
|
| 2877 | - |
|
| 2878 | - |
|
| 2879 | - /** |
|
| 2880 | - * display_admin_page |
|
| 2881 | - * contains the code for actually displaying an admin page |
|
| 2882 | - * |
|
| 2883 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2884 | - * @param boolean $about use the about_admin_wrapper instead of the default. |
|
| 2885 | - * @return void |
|
| 2886 | - * @throws DomainException |
|
| 2887 | - * @throws EE_Error |
|
| 2888 | - */ |
|
| 2889 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2890 | - { |
|
| 2891 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2892 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2893 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2894 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2895 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2896 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2897 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2898 | - ? 'poststuff' |
|
| 2899 | - : 'espresso-default-admin'; |
|
| 2900 | - $template_path = $sidebar |
|
| 2901 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2902 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2903 | - if ($this->request->isAjax()) { |
|
| 2904 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2905 | - } |
|
| 2906 | - $template_path = ! empty($this->_column_template_path) |
|
| 2907 | - ? $this->_column_template_path : $template_path; |
|
| 2908 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2909 | - ? $this->_template_args['admin_page_content'] |
|
| 2910 | - : ''; |
|
| 2911 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2912 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2913 | - : ''; |
|
| 2914 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2915 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2916 | - : ''; |
|
| 2917 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2918 | - $template_path, |
|
| 2919 | - $this->_template_args, |
|
| 2920 | - true |
|
| 2921 | - ); |
|
| 2922 | - // the final template wrapper |
|
| 2923 | - $this->admin_page_wrapper($about); |
|
| 2924 | - } |
|
| 2925 | - |
|
| 2926 | - |
|
| 2927 | - /** |
|
| 2928 | - * This is used to display caf preview pages. |
|
| 2929 | - * |
|
| 2930 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2931 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2932 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2933 | - * @return void |
|
| 2934 | - * @throws DomainException |
|
| 2935 | - * @throws EE_Error |
|
| 2936 | - * @throws InvalidArgumentException |
|
| 2937 | - * @throws InvalidDataTypeException |
|
| 2938 | - * @throws InvalidInterfaceException |
|
| 2939 | - * @since 4.3.2 |
|
| 2940 | - */ |
|
| 2941 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2942 | - { |
|
| 2943 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2944 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2945 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2946 | - 'event_espresso' |
|
| 2947 | - ); |
|
| 2948 | - $buy_now_url = add_query_arg( |
|
| 2949 | - [ |
|
| 2950 | - 'ee_ver' => 'ee4', |
|
| 2951 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2952 | - 'utm_medium' => 'link', |
|
| 2953 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2954 | - 'utm_content' => 'buy_now_button', |
|
| 2955 | - ], |
|
| 2956 | - 'https://eventespresso.com/pricing/' |
|
| 2957 | - ); |
|
| 2958 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2959 | - ? $this->get_action_link_or_button( |
|
| 2960 | - '', |
|
| 2961 | - 'buy_now', |
|
| 2962 | - [], |
|
| 2963 | - 'button-primary button-large', |
|
| 2964 | - esc_url_raw($buy_now_url), |
|
| 2965 | - true |
|
| 2966 | - ) |
|
| 2967 | - : $this->_template_args['preview_action_button']; |
|
| 2968 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2969 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2970 | - $this->_template_args, |
|
| 2971 | - true |
|
| 2972 | - ); |
|
| 2973 | - $this->_display_admin_page($display_sidebar); |
|
| 2974 | - } |
|
| 2975 | - |
|
| 2976 | - |
|
| 2977 | - /** |
|
| 2978 | - * display_admin_list_table_page_with_sidebar |
|
| 2979 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2980 | - * |
|
| 2981 | - * @return void |
|
| 2982 | - * @throws EE_Error |
|
| 2983 | - * @throws DomainException |
|
| 2984 | - */ |
|
| 2985 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2986 | - { |
|
| 2987 | - $this->_display_admin_list_table_page(true); |
|
| 2988 | - } |
|
| 2989 | - |
|
| 2990 | - |
|
| 2991 | - /** |
|
| 2992 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2993 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2994 | - * |
|
| 2995 | - * @return void |
|
| 2996 | - * @throws EE_Error |
|
| 2997 | - * @throws DomainException |
|
| 2998 | - */ |
|
| 2999 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 3000 | - { |
|
| 3001 | - $this->_display_admin_list_table_page(); |
|
| 3002 | - } |
|
| 3003 | - |
|
| 3004 | - |
|
| 3005 | - /** |
|
| 3006 | - * generates html wrapper for an admin_list_table page |
|
| 3007 | - * |
|
| 3008 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3009 | - * @return void |
|
| 3010 | - * @throws DomainException |
|
| 3011 | - * @throws EE_Error |
|
| 3012 | - */ |
|
| 3013 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 3014 | - { |
|
| 3015 | - // setup search attributes |
|
| 3016 | - $this->_set_search_attributes(); |
|
| 3017 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3018 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3019 | - $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 3020 | - ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 3021 | - : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 3022 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3023 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 3024 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3025 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3026 | - if (! empty($ajax_sorting_callback)) { |
|
| 3027 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3028 | - $ajax_sorting_callback . '_nonce', |
|
| 3029 | - $ajax_sorting_callback . '_nonce', |
|
| 3030 | - false, |
|
| 3031 | - false |
|
| 3032 | - ); |
|
| 3033 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3034 | - . $this->page_slug |
|
| 3035 | - . '" />'; |
|
| 3036 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3037 | - . $ajax_sorting_callback |
|
| 3038 | - . '" />'; |
|
| 3039 | - } else { |
|
| 3040 | - $sortable_list_table_form_fields = ''; |
|
| 3041 | - } |
|
| 3042 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3043 | - $hidden_form_fields = |
|
| 3044 | - isset($this->_template_args['list_table_hidden_fields']) |
|
| 3045 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 3046 | - : ''; |
|
| 3047 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3048 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3049 | - . $nonce_ref |
|
| 3050 | - . '" value="' |
|
| 3051 | - . wp_create_nonce($nonce_ref) |
|
| 3052 | - . '">'; |
|
| 3053 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3054 | - // display message about search results? |
|
| 3055 | - $search = $this->request->getRequestParam('s'); |
|
| 3056 | - $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 3057 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3058 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3059 | - trim($search, '%') |
|
| 3060 | - ) . '</p>' |
|
| 3061 | - : ''; |
|
| 3062 | - // filter before_list_table template arg |
|
| 3063 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 3064 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3065 | - $this->_template_args['before_list_table'], |
|
| 3066 | - $this->page_slug, |
|
| 3067 | - $this->request->requestParams(), |
|
| 3068 | - $this->_req_action |
|
| 3069 | - ); |
|
| 3070 | - // convert to array and filter again |
|
| 3071 | - // arrays are easier to inject new items in a specific location, |
|
| 3072 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3073 | - $this->_template_args['before_list_table'] = implode( |
|
| 3074 | - " \n", |
|
| 3075 | - (array) apply_filters( |
|
| 3076 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3077 | - (array) $this->_template_args['before_list_table'], |
|
| 3078 | - $this->page_slug, |
|
| 3079 | - $this->request->requestParams(), |
|
| 3080 | - $this->_req_action |
|
| 3081 | - ) |
|
| 3082 | - ); |
|
| 3083 | - // filter after_list_table template arg |
|
| 3084 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3085 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3086 | - $this->_template_args['after_list_table'], |
|
| 3087 | - $this->page_slug, |
|
| 3088 | - $this->request->requestParams(), |
|
| 3089 | - $this->_req_action |
|
| 3090 | - ); |
|
| 3091 | - // convert to array and filter again |
|
| 3092 | - // arrays are easier to inject new items in a specific location, |
|
| 3093 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3094 | - $this->_template_args['after_list_table'] = implode( |
|
| 3095 | - " \n", |
|
| 3096 | - (array) apply_filters( |
|
| 3097 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3098 | - (array) $this->_template_args['after_list_table'], |
|
| 3099 | - $this->page_slug, |
|
| 3100 | - $this->request->requestParams(), |
|
| 3101 | - $this->_req_action |
|
| 3102 | - ) |
|
| 3103 | - ); |
|
| 3104 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3105 | - $template_path, |
|
| 3106 | - $this->_template_args, |
|
| 3107 | - true |
|
| 3108 | - ); |
|
| 3109 | - // the final template wrapper |
|
| 3110 | - if ($sidebar) { |
|
| 3111 | - $this->display_admin_page_with_sidebar(); |
|
| 3112 | - } else { |
|
| 3113 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3114 | - } |
|
| 3115 | - } |
|
| 3116 | - |
|
| 3117 | - |
|
| 3118 | - /** |
|
| 3119 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3120 | - * html string for the legend. |
|
| 3121 | - * $items are expected in an array in the following format: |
|
| 3122 | - * $legend_items = array( |
|
| 3123 | - * 'item_id' => array( |
|
| 3124 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3125 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3126 | - * ) |
|
| 3127 | - * ); |
|
| 3128 | - * |
|
| 3129 | - * @param array $items see above for format of array |
|
| 3130 | - * @return string html string of legend |
|
| 3131 | - * @throws DomainException |
|
| 3132 | - */ |
|
| 3133 | - protected function _display_legend($items) |
|
| 3134 | - { |
|
| 3135 | - $this->_template_args['items'] = apply_filters( |
|
| 3136 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3137 | - (array) $items, |
|
| 3138 | - $this |
|
| 3139 | - ); |
|
| 3140 | - return EEH_Template::display_template( |
|
| 3141 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3142 | - $this->_template_args, |
|
| 3143 | - true |
|
| 3144 | - ); |
|
| 3145 | - } |
|
| 3146 | - |
|
| 3147 | - |
|
| 3148 | - /** |
|
| 3149 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3150 | - * The returned json object is created from an array in the following format: |
|
| 3151 | - * array( |
|
| 3152 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3153 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3154 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3155 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3156 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3157 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3158 | - * that might be included in here) |
|
| 3159 | - * ) |
|
| 3160 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3161 | - * |
|
| 3162 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3163 | - * instead of displayed. |
|
| 3164 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3165 | - * @return void |
|
| 3166 | - * @throws EE_Error |
|
| 3167 | - */ |
|
| 3168 | - protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 3169 | - { |
|
| 3170 | - // make sure any EE_Error notices have been handled. |
|
| 3171 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3172 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 3173 | - unset($this->_template_args['data']); |
|
| 3174 | - $json = [ |
|
| 3175 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3176 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3177 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3178 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3179 | - 'notices' => EE_Error::get_notices(), |
|
| 3180 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3181 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3182 | - 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 3183 | - 'isEEajax' => true |
|
| 3184 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3185 | - ]; |
|
| 3186 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3187 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3188 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3189 | - } |
|
| 3190 | - echo wp_json_encode($json); |
|
| 3191 | - exit(); |
|
| 3192 | - } |
|
| 3193 | - |
|
| 3194 | - |
|
| 3195 | - /** |
|
| 3196 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3197 | - * |
|
| 3198 | - * @return void |
|
| 3199 | - * @throws EE_Error |
|
| 3200 | - */ |
|
| 3201 | - public function return_json() |
|
| 3202 | - { |
|
| 3203 | - if ($this->request->isAjax()) { |
|
| 3204 | - $this->_return_json(); |
|
| 3205 | - } else { |
|
| 3206 | - throw new EE_Error( |
|
| 3207 | - sprintf( |
|
| 3208 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3209 | - __FUNCTION__ |
|
| 3210 | - ) |
|
| 3211 | - ); |
|
| 3212 | - } |
|
| 3213 | - } |
|
| 3214 | - |
|
| 3215 | - |
|
| 3216 | - /** |
|
| 3217 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3218 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3219 | - * |
|
| 3220 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3221 | - */ |
|
| 3222 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3223 | - { |
|
| 3224 | - $this->_hook_obj = $hook_obj; |
|
| 3225 | - } |
|
| 3226 | - |
|
| 3227 | - |
|
| 3228 | - /** |
|
| 3229 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3230 | - * |
|
| 3231 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3232 | - * @return void |
|
| 3233 | - * @throws DomainException |
|
| 3234 | - * @throws EE_Error |
|
| 3235 | - */ |
|
| 3236 | - public function admin_page_wrapper($about = false) |
|
| 3237 | - { |
|
| 3238 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3239 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3240 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3241 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3242 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3243 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3244 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3245 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3246 | - : '' |
|
| 3247 | - ); |
|
| 3248 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3249 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3250 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3251 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3252 | - : '' |
|
| 3253 | - ); |
|
| 3254 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3255 | - // load settings page wrapper template |
|
| 3256 | - $template_path = ! $this->request->isAjax() |
|
| 3257 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3258 | - : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 3259 | - // about page? |
|
| 3260 | - $template_path = $about |
|
| 3261 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3262 | - : $template_path; |
|
| 3263 | - if ($this->request->isAjax()) { |
|
| 3264 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3265 | - $template_path, |
|
| 3266 | - $this->_template_args, |
|
| 3267 | - true |
|
| 3268 | - ); |
|
| 3269 | - $this->_return_json(); |
|
| 3270 | - } else { |
|
| 3271 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3272 | - } |
|
| 3273 | - } |
|
| 3274 | - |
|
| 3275 | - |
|
| 3276 | - /** |
|
| 3277 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3278 | - * |
|
| 3279 | - * @return string html |
|
| 3280 | - * @throws EE_Error |
|
| 3281 | - */ |
|
| 3282 | - protected function _get_main_nav_tabs() |
|
| 3283 | - { |
|
| 3284 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3285 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3286 | - // (rather than setting in the page_routes array) |
|
| 3287 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3288 | - } |
|
| 3289 | - |
|
| 3290 | - |
|
| 3291 | - /** |
|
| 3292 | - * sort nav tabs |
|
| 3293 | - * |
|
| 3294 | - * @param $a |
|
| 3295 | - * @param $b |
|
| 3296 | - * @return int |
|
| 3297 | - */ |
|
| 3298 | - private function _sort_nav_tabs($a, $b) |
|
| 3299 | - { |
|
| 3300 | - if ($a['order'] === $b['order']) { |
|
| 3301 | - return 0; |
|
| 3302 | - } |
|
| 3303 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3304 | - } |
|
| 3305 | - |
|
| 3306 | - |
|
| 3307 | - /** |
|
| 3308 | - * generates HTML for the forms used on admin pages |
|
| 3309 | - * |
|
| 3310 | - * @param array $input_vars - array of input field details |
|
| 3311 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3312 | - * use) |
|
| 3313 | - * @param bool $id |
|
| 3314 | - * @return array|string |
|
| 3315 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3316 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3317 | - */ |
|
| 3318 | - protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3319 | - { |
|
| 3320 | - return $generator === 'string' |
|
| 3321 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3322 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3323 | - } |
|
| 3324 | - |
|
| 3325 | - |
|
| 3326 | - /** |
|
| 3327 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3328 | - * |
|
| 3329 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3330 | - * Close" button. |
|
| 3331 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3332 | - * 'Save', [1] => 'save & close') |
|
| 3333 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3334 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3335 | - * default actions by submitting some other value. |
|
| 3336 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3337 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3338 | - * close (normal form handling). |
|
| 3339 | - */ |
|
| 3340 | - protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3341 | - { |
|
| 3342 | - // make sure $text and $actions are in an array |
|
| 3343 | - $text = (array) $text; |
|
| 3344 | - $actions = (array) $actions; |
|
| 3345 | - $referrer_url = empty($referrer) |
|
| 3346 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3347 | - . $this->request->getServerParam('REQUEST_URI') |
|
| 3348 | - . '" />' |
|
| 3349 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3350 | - . $referrer |
|
| 3351 | - . '" />'; |
|
| 3352 | - $button_text = ! empty($text) |
|
| 3353 | - ? $text |
|
| 3354 | - : [ |
|
| 3355 | - esc_html__('Save', 'event_espresso'), |
|
| 3356 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3357 | - ]; |
|
| 3358 | - $default_names = ['save', 'save_and_close']; |
|
| 3359 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3360 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3361 | - foreach ($button_text as $key => $button) { |
|
| 3362 | - $ref = $default_names[ $key ]; |
|
| 3363 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3364 | - . $ref |
|
| 3365 | - . '" value="' |
|
| 3366 | - . $button |
|
| 3367 | - . '" name="' |
|
| 3368 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3369 | - . '" id="' |
|
| 3370 | - . $this->_current_view . '_' . $ref |
|
| 3371 | - . '" />'; |
|
| 3372 | - if (! $both) { |
|
| 3373 | - break; |
|
| 3374 | - } |
|
| 3375 | - } |
|
| 3376 | - } |
|
| 3377 | - |
|
| 3378 | - |
|
| 3379 | - /** |
|
| 3380 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3381 | - * |
|
| 3382 | - * @param string $route |
|
| 3383 | - * @param array $additional_hidden_fields |
|
| 3384 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3385 | - * @since 4.6.0 |
|
| 3386 | - */ |
|
| 3387 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3388 | - { |
|
| 3389 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3390 | - } |
|
| 3391 | - |
|
| 3392 | - |
|
| 3393 | - /** |
|
| 3394 | - * set form open and close tags on add/edit pages. |
|
| 3395 | - * |
|
| 3396 | - * @param string $route the route you want the form to direct to |
|
| 3397 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3398 | - * @return void |
|
| 3399 | - */ |
|
| 3400 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3401 | - { |
|
| 3402 | - if (empty($route)) { |
|
| 3403 | - $user_msg = esc_html__( |
|
| 3404 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3405 | - 'event_espresso' |
|
| 3406 | - ); |
|
| 3407 | - $dev_msg = $user_msg . "\n" |
|
| 3408 | - . sprintf( |
|
| 3409 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3410 | - __FUNCTION__, |
|
| 3411 | - __CLASS__ |
|
| 3412 | - ); |
|
| 3413 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3414 | - } |
|
| 3415 | - // open form |
|
| 3416 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3417 | - . $this->_admin_base_url |
|
| 3418 | - . '" id="' |
|
| 3419 | - . $route |
|
| 3420 | - . '_event_form" >'; |
|
| 3421 | - // add nonce |
|
| 3422 | - $nonce = |
|
| 3423 | - wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3424 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3425 | - // add REQUIRED form action |
|
| 3426 | - $hidden_fields = [ |
|
| 3427 | - 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3428 | - ]; |
|
| 3429 | - // merge arrays |
|
| 3430 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3431 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3432 | - : $hidden_fields; |
|
| 3433 | - // generate form fields |
|
| 3434 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3435 | - // add fields to form |
|
| 3436 | - foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3437 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3438 | - } |
|
| 3439 | - // close form |
|
| 3440 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3441 | - } |
|
| 3442 | - |
|
| 3443 | - |
|
| 3444 | - /** |
|
| 3445 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3446 | - * discovered it would be useful for external code to have access. |
|
| 3447 | - * |
|
| 3448 | - * @param bool $success |
|
| 3449 | - * @param string $what |
|
| 3450 | - * @param string $action_desc |
|
| 3451 | - * @param array $query_args |
|
| 3452 | - * @param bool $override_overwrite |
|
| 3453 | - * @throws EE_Error |
|
| 3454 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3455 | - * @since 4.5.0 |
|
| 3456 | - */ |
|
| 3457 | - public function redirect_after_action( |
|
| 3458 | - $success = false, |
|
| 3459 | - $what = 'item', |
|
| 3460 | - $action_desc = 'processed', |
|
| 3461 | - $query_args = [], |
|
| 3462 | - $override_overwrite = false |
|
| 3463 | - ) { |
|
| 3464 | - $this->_redirect_after_action( |
|
| 3465 | - $success, |
|
| 3466 | - $what, |
|
| 3467 | - $action_desc, |
|
| 3468 | - $query_args, |
|
| 3469 | - $override_overwrite |
|
| 3470 | - ); |
|
| 3471 | - } |
|
| 3472 | - |
|
| 3473 | - |
|
| 3474 | - /** |
|
| 3475 | - * Helper method for merging existing request data with the returned redirect url. |
|
| 3476 | - * |
|
| 3477 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3478 | - * filters are still applied. |
|
| 3479 | - * |
|
| 3480 | - * @param array $new_route_data |
|
| 3481 | - * @return array |
|
| 3482 | - */ |
|
| 3483 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3484 | - { |
|
| 3485 | - foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3486 | - // unset nonces |
|
| 3487 | - if (strpos($ref, 'nonce') !== false) { |
|
| 3488 | - $this->request->unSetRequestParam($ref); |
|
| 3489 | - continue; |
|
| 3490 | - } |
|
| 3491 | - // urlencode values. |
|
| 3492 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3493 | - $this->request->setRequestParam($ref, $value); |
|
| 3494 | - } |
|
| 3495 | - return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3496 | - } |
|
| 3497 | - |
|
| 3498 | - |
|
| 3499 | - /** |
|
| 3500 | - * _redirect_after_action |
|
| 3501 | - * |
|
| 3502 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3503 | - * @param string $what - what the action was performed on |
|
| 3504 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3505 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3506 | - * action is completed |
|
| 3507 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3508 | - * override this so that they show. |
|
| 3509 | - * @return void |
|
| 3510 | - * @throws EE_Error |
|
| 3511 | - */ |
|
| 3512 | - protected function _redirect_after_action( |
|
| 3513 | - $success = 0, |
|
| 3514 | - $what = 'item', |
|
| 3515 | - $action_desc = 'processed', |
|
| 3516 | - $query_args = [], |
|
| 3517 | - $override_overwrite = false |
|
| 3518 | - ) { |
|
| 3519 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3520 | - // class name for actions/filters. |
|
| 3521 | - $classname = get_class($this); |
|
| 3522 | - // set redirect url. |
|
| 3523 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3524 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3525 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3526 | - $notices = EE_Error::get_notices(false); |
|
| 3527 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3528 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3529 | - EE_Error::overwrite_success(); |
|
| 3530 | - } |
|
| 3531 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3532 | - // how many records affected ? more than one record ? or just one ? |
|
| 3533 | - if ($success > 1) { |
|
| 3534 | - // set plural msg |
|
| 3535 | - EE_Error::add_success( |
|
| 3536 | - sprintf( |
|
| 3537 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3538 | - $what, |
|
| 3539 | - $action_desc |
|
| 3540 | - ), |
|
| 3541 | - __FILE__, |
|
| 3542 | - __FUNCTION__, |
|
| 3543 | - __LINE__ |
|
| 3544 | - ); |
|
| 3545 | - } elseif ($success === 1) { |
|
| 3546 | - // set singular msg |
|
| 3547 | - EE_Error::add_success( |
|
| 3548 | - sprintf( |
|
| 3549 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3550 | - $what, |
|
| 3551 | - $action_desc |
|
| 3552 | - ), |
|
| 3553 | - __FILE__, |
|
| 3554 | - __FUNCTION__, |
|
| 3555 | - __LINE__ |
|
| 3556 | - ); |
|
| 3557 | - } |
|
| 3558 | - } |
|
| 3559 | - // check that $query_args isn't something crazy |
|
| 3560 | - if (! is_array($query_args)) { |
|
| 3561 | - $query_args = []; |
|
| 3562 | - } |
|
| 3563 | - /** |
|
| 3564 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3565 | - * redirections on save and close actions |
|
| 3566 | - * |
|
| 3567 | - * @param array $query_args The original query_args array coming into the |
|
| 3568 | - * method. |
|
| 3569 | - * @since 4.2.0 |
|
| 3570 | - */ |
|
| 3571 | - do_action( |
|
| 3572 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3573 | - $query_args |
|
| 3574 | - ); |
|
| 3575 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3576 | - |
|
| 3577 | - if ( |
|
| 3578 | - $this->request->requestParamIsSet('save_and_close') |
|
| 3579 | - && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3580 | - ) { |
|
| 3581 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3582 | - $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3583 | - // regenerate query args array from referrer URL |
|
| 3584 | - parse_str($parsed_url['query'], $query_args); |
|
| 3585 | - // correct page and action will be in the query args now |
|
| 3586 | - $redirect_url = admin_url('admin.php'); |
|
| 3587 | - } |
|
| 3588 | - // merge any default query_args set in _default_route_query_args property |
|
| 3589 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3590 | - $args_to_merge = []; |
|
| 3591 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3592 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3593 | - if ($query_param === 'wp_referer') { |
|
| 3594 | - $query_value = (array) $query_value; |
|
| 3595 | - foreach ($query_value as $reference => $value) { |
|
| 3596 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3597 | - continue; |
|
| 3598 | - } |
|
| 3599 | - // finally we will override any arguments in the referer with |
|
| 3600 | - // what might be set on the _default_route_query_args array. |
|
| 3601 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3602 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3603 | - } else { |
|
| 3604 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3605 | - } |
|
| 3606 | - } |
|
| 3607 | - continue; |
|
| 3608 | - } |
|
| 3609 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3610 | - } |
|
| 3611 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3612 | - // redirect. |
|
| 3613 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3614 | - } |
|
| 3615 | - $this->_process_notices($query_args); |
|
| 3616 | - // generate redirect url |
|
| 3617 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3618 | - if (isset($query_args['action'])) { |
|
| 3619 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3620 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3621 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3622 | - } |
|
| 3623 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3624 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3625 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3626 | - $redirect_url = apply_filters( |
|
| 3627 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3628 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3629 | - $query_args |
|
| 3630 | - ); |
|
| 3631 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3632 | - if ($this->request->isAjax()) { |
|
| 3633 | - $default_data = [ |
|
| 3634 | - 'close' => true, |
|
| 3635 | - 'redirect_url' => $redirect_url, |
|
| 3636 | - 'where' => 'main', |
|
| 3637 | - 'what' => 'append', |
|
| 3638 | - ]; |
|
| 3639 | - $this->_template_args['success'] = $success; |
|
| 3640 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3641 | - $default_data, |
|
| 3642 | - $this->_template_args['data'] |
|
| 3643 | - ) : $default_data; |
|
| 3644 | - $this->_return_json(); |
|
| 3645 | - } |
|
| 3646 | - wp_safe_redirect($redirect_url); |
|
| 3647 | - exit(); |
|
| 3648 | - } |
|
| 3649 | - |
|
| 3650 | - |
|
| 3651 | - /** |
|
| 3652 | - * process any notices before redirecting (or returning ajax request) |
|
| 3653 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3654 | - * |
|
| 3655 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3656 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3657 | - * page_routes haven't been defined yet. |
|
| 3658 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3659 | - * still save a transient for the notice. |
|
| 3660 | - * @return void |
|
| 3661 | - * @throws EE_Error |
|
| 3662 | - */ |
|
| 3663 | - protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3664 | - { |
|
| 3665 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3666 | - if ($this->request->isAjax()) { |
|
| 3667 | - $notices = EE_Error::get_notices(false); |
|
| 3668 | - if (empty($this->_template_args['success'])) { |
|
| 3669 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3670 | - } |
|
| 3671 | - if (empty($this->_template_args['errors'])) { |
|
| 3672 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3673 | - } |
|
| 3674 | - if (empty($this->_template_args['attention'])) { |
|
| 3675 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3676 | - } |
|
| 3677 | - } |
|
| 3678 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3679 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3680 | - if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3681 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3682 | - $this->_add_transient( |
|
| 3683 | - $route, |
|
| 3684 | - $this->_template_args['notices'], |
|
| 3685 | - true, |
|
| 3686 | - $skip_route_verify |
|
| 3687 | - ); |
|
| 3688 | - } |
|
| 3689 | - } |
|
| 3690 | - |
|
| 3691 | - |
|
| 3692 | - /** |
|
| 3693 | - * get_action_link_or_button |
|
| 3694 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3695 | - * |
|
| 3696 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3697 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3698 | - * property. |
|
| 3699 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3700 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3701 | - * @param string $base_url If this is not provided |
|
| 3702 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3703 | - * Otherwise this value will be used. |
|
| 3704 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3705 | - * @return string |
|
| 3706 | - * @throws InvalidArgumentException |
|
| 3707 | - * @throws InvalidInterfaceException |
|
| 3708 | - * @throws InvalidDataTypeException |
|
| 3709 | - * @throws EE_Error |
|
| 3710 | - */ |
|
| 3711 | - public function get_action_link_or_button( |
|
| 3712 | - $action, |
|
| 3713 | - $type = 'add', |
|
| 3714 | - $extra_request = [], |
|
| 3715 | - $class = 'button-primary', |
|
| 3716 | - $base_url = '', |
|
| 3717 | - $exclude_nonce = false |
|
| 3718 | - ) { |
|
| 3719 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3720 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3721 | - throw new EE_Error( |
|
| 3722 | - sprintf( |
|
| 3723 | - esc_html__( |
|
| 3724 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3725 | - 'event_espresso' |
|
| 3726 | - ), |
|
| 3727 | - $action |
|
| 3728 | - ) |
|
| 3729 | - ); |
|
| 3730 | - } |
|
| 3731 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3732 | - throw new EE_Error( |
|
| 3733 | - sprintf( |
|
| 3734 | - esc_html__( |
|
| 3735 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3736 | - 'event_espresso' |
|
| 3737 | - ), |
|
| 3738 | - $type |
|
| 3739 | - ) |
|
| 3740 | - ); |
|
| 3741 | - } |
|
| 3742 | - // finally check user access for this button. |
|
| 3743 | - $has_access = $this->check_user_access($action, true); |
|
| 3744 | - if (! $has_access) { |
|
| 3745 | - return ''; |
|
| 3746 | - } |
|
| 3747 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3748 | - $query_args = [ |
|
| 3749 | - 'action' => $action, |
|
| 3750 | - ]; |
|
| 3751 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3752 | - if (! empty($extra_request)) { |
|
| 3753 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3754 | - } |
|
| 3755 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3756 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3757 | - } |
|
| 3758 | - |
|
| 3759 | - |
|
| 3760 | - /** |
|
| 3761 | - * _per_page_screen_option |
|
| 3762 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3763 | - * |
|
| 3764 | - * @return void |
|
| 3765 | - * @throws InvalidArgumentException |
|
| 3766 | - * @throws InvalidInterfaceException |
|
| 3767 | - * @throws InvalidDataTypeException |
|
| 3768 | - */ |
|
| 3769 | - protected function _per_page_screen_option() |
|
| 3770 | - { |
|
| 3771 | - $option = 'per_page'; |
|
| 3772 | - $args = [ |
|
| 3773 | - 'label' => apply_filters( |
|
| 3774 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3775 | - $this->_admin_page_title, |
|
| 3776 | - $this |
|
| 3777 | - ), |
|
| 3778 | - 'default' => (int) apply_filters( |
|
| 3779 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3780 | - 20 |
|
| 3781 | - ), |
|
| 3782 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3783 | - ]; |
|
| 3784 | - // ONLY add the screen option if the user has access to it. |
|
| 3785 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3786 | - add_screen_option($option, $args); |
|
| 3787 | - } |
|
| 3788 | - } |
|
| 3789 | - |
|
| 3790 | - |
|
| 3791 | - /** |
|
| 3792 | - * set_per_page_screen_option |
|
| 3793 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3794 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3795 | - * admin_menu. |
|
| 3796 | - * |
|
| 3797 | - * @return void |
|
| 3798 | - */ |
|
| 3799 | - private function _set_per_page_screen_options() |
|
| 3800 | - { |
|
| 3801 | - if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3802 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3803 | - if (! $user = wp_get_current_user()) { |
|
| 3804 | - return; |
|
| 3805 | - } |
|
| 3806 | - $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3807 | - if (! $option) { |
|
| 3808 | - return; |
|
| 3809 | - } |
|
| 3810 | - $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3811 | - $map_option = $option; |
|
| 3812 | - $option = str_replace('-', '_', $option); |
|
| 3813 | - switch ($map_option) { |
|
| 3814 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3815 | - $max_value = apply_filters( |
|
| 3816 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3817 | - 999, |
|
| 3818 | - $this->_current_page, |
|
| 3819 | - $this->_current_view |
|
| 3820 | - ); |
|
| 3821 | - if ($value < 1) { |
|
| 3822 | - return; |
|
| 3823 | - } |
|
| 3824 | - $value = min($value, $max_value); |
|
| 3825 | - break; |
|
| 3826 | - default: |
|
| 3827 | - $value = apply_filters( |
|
| 3828 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3829 | - false, |
|
| 3830 | - $option, |
|
| 3831 | - $value |
|
| 3832 | - ); |
|
| 3833 | - if (false === $value) { |
|
| 3834 | - return; |
|
| 3835 | - } |
|
| 3836 | - break; |
|
| 3837 | - } |
|
| 3838 | - update_user_meta($user->ID, $option, $value); |
|
| 3839 | - wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3840 | - exit; |
|
| 3841 | - } |
|
| 3842 | - } |
|
| 3843 | - |
|
| 3844 | - |
|
| 3845 | - /** |
|
| 3846 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3847 | - * |
|
| 3848 | - * @param array $data array that will be assigned to template args. |
|
| 3849 | - */ |
|
| 3850 | - public function set_template_args($data) |
|
| 3851 | - { |
|
| 3852 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3853 | - } |
|
| 3854 | - |
|
| 3855 | - |
|
| 3856 | - /** |
|
| 3857 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3858 | - * |
|
| 3859 | - * @param string $route the route that should receive the transient |
|
| 3860 | - * @param array $data the data that gets sent |
|
| 3861 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3862 | - * normal route transient. |
|
| 3863 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3864 | - * when we are adding a transient before page_routes have been defined. |
|
| 3865 | - * @return void |
|
| 3866 | - * @throws EE_Error |
|
| 3867 | - */ |
|
| 3868 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3869 | - { |
|
| 3870 | - $user_id = get_current_user_id(); |
|
| 3871 | - if (! $skip_route_verify) { |
|
| 3872 | - $this->_verify_route($route); |
|
| 3873 | - } |
|
| 3874 | - // now let's set the string for what kind of transient we're setting |
|
| 3875 | - $transient = $notices |
|
| 3876 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3877 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3878 | - $data = $notices ? ['notices' => $data] : $data; |
|
| 3879 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3880 | - $existing = is_multisite() && is_network_admin() |
|
| 3881 | - ? get_site_transient($transient) |
|
| 3882 | - : get_transient($transient); |
|
| 3883 | - if ($existing) { |
|
| 3884 | - $data = array_merge((array) $data, (array) $existing); |
|
| 3885 | - } |
|
| 3886 | - if (is_multisite() && is_network_admin()) { |
|
| 3887 | - set_site_transient($transient, $data, 8); |
|
| 3888 | - } else { |
|
| 3889 | - set_transient($transient, $data, 8); |
|
| 3890 | - } |
|
| 3891 | - } |
|
| 3892 | - |
|
| 3893 | - |
|
| 3894 | - /** |
|
| 3895 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3896 | - * |
|
| 3897 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3898 | - * @param string $route |
|
| 3899 | - * @return mixed data |
|
| 3900 | - */ |
|
| 3901 | - protected function _get_transient($notices = false, $route = '') |
|
| 3902 | - { |
|
| 3903 | - $user_id = get_current_user_id(); |
|
| 3904 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3905 | - $transient = $notices |
|
| 3906 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3907 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3908 | - $data = is_multisite() && is_network_admin() |
|
| 3909 | - ? get_site_transient($transient) |
|
| 3910 | - : get_transient($transient); |
|
| 3911 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3912 | - if (is_multisite() && is_network_admin()) { |
|
| 3913 | - delete_site_transient($transient); |
|
| 3914 | - } else { |
|
| 3915 | - delete_transient($transient); |
|
| 3916 | - } |
|
| 3917 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3918 | - } |
|
| 3919 | - |
|
| 3920 | - |
|
| 3921 | - /** |
|
| 3922 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3923 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3924 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3925 | - * |
|
| 3926 | - * @return void |
|
| 3927 | - */ |
|
| 3928 | - protected function _transient_garbage_collection() |
|
| 3929 | - { |
|
| 3930 | - global $wpdb; |
|
| 3931 | - // retrieve all existing transients |
|
| 3932 | - $query = |
|
| 3933 | - "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3934 | - if ($results = $wpdb->get_results($query)) { |
|
| 3935 | - foreach ($results as $result) { |
|
| 3936 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3937 | - get_transient($transient); |
|
| 3938 | - if (is_multisite() && is_network_admin()) { |
|
| 3939 | - get_site_transient($transient); |
|
| 3940 | - } |
|
| 3941 | - } |
|
| 3942 | - } |
|
| 3943 | - } |
|
| 3944 | - |
|
| 3945 | - |
|
| 3946 | - /** |
|
| 3947 | - * get_view |
|
| 3948 | - * |
|
| 3949 | - * @return string content of _view property |
|
| 3950 | - */ |
|
| 3951 | - public function get_view() |
|
| 3952 | - { |
|
| 3953 | - return $this->_view; |
|
| 3954 | - } |
|
| 3955 | - |
|
| 3956 | - |
|
| 3957 | - /** |
|
| 3958 | - * getter for the protected $_views property |
|
| 3959 | - * |
|
| 3960 | - * @return array |
|
| 3961 | - */ |
|
| 3962 | - public function get_views() |
|
| 3963 | - { |
|
| 3964 | - return $this->_views; |
|
| 3965 | - } |
|
| 3966 | - |
|
| 3967 | - |
|
| 3968 | - /** |
|
| 3969 | - * get_current_page |
|
| 3970 | - * |
|
| 3971 | - * @return string _current_page property value |
|
| 3972 | - */ |
|
| 3973 | - public function get_current_page() |
|
| 3974 | - { |
|
| 3975 | - return $this->_current_page; |
|
| 3976 | - } |
|
| 3977 | - |
|
| 3978 | - |
|
| 3979 | - /** |
|
| 3980 | - * get_current_view |
|
| 3981 | - * |
|
| 3982 | - * @return string _current_view property value |
|
| 3983 | - */ |
|
| 3984 | - public function get_current_view() |
|
| 3985 | - { |
|
| 3986 | - return $this->_current_view; |
|
| 3987 | - } |
|
| 3988 | - |
|
| 3989 | - |
|
| 3990 | - /** |
|
| 3991 | - * get_current_screen |
|
| 3992 | - * |
|
| 3993 | - * @return object The current WP_Screen object |
|
| 3994 | - */ |
|
| 3995 | - public function get_current_screen() |
|
| 3996 | - { |
|
| 3997 | - return $this->_current_screen; |
|
| 3998 | - } |
|
| 3999 | - |
|
| 4000 | - |
|
| 4001 | - /** |
|
| 4002 | - * get_current_page_view_url |
|
| 4003 | - * |
|
| 4004 | - * @return string This returns the url for the current_page_view. |
|
| 4005 | - */ |
|
| 4006 | - public function get_current_page_view_url() |
|
| 4007 | - { |
|
| 4008 | - return $this->_current_page_view_url; |
|
| 4009 | - } |
|
| 4010 | - |
|
| 4011 | - |
|
| 4012 | - /** |
|
| 4013 | - * just returns the Request |
|
| 4014 | - * |
|
| 4015 | - * @return RequestInterface |
|
| 4016 | - */ |
|
| 4017 | - public function get_request() |
|
| 4018 | - { |
|
| 4019 | - return $this->request; |
|
| 4020 | - } |
|
| 4021 | - |
|
| 4022 | - |
|
| 4023 | - /** |
|
| 4024 | - * just returns the _req_data property |
|
| 4025 | - * |
|
| 4026 | - * @return array |
|
| 4027 | - */ |
|
| 4028 | - public function get_request_data() |
|
| 4029 | - { |
|
| 4030 | - return $this->request->requestParams(); |
|
| 4031 | - } |
|
| 4032 | - |
|
| 4033 | - |
|
| 4034 | - /** |
|
| 4035 | - * returns the _req_data protected property |
|
| 4036 | - * |
|
| 4037 | - * @return string |
|
| 4038 | - */ |
|
| 4039 | - public function get_req_action() |
|
| 4040 | - { |
|
| 4041 | - return $this->_req_action; |
|
| 4042 | - } |
|
| 4043 | - |
|
| 4044 | - |
|
| 4045 | - /** |
|
| 4046 | - * @return bool value of $_is_caf property |
|
| 4047 | - */ |
|
| 4048 | - public function is_caf() |
|
| 4049 | - { |
|
| 4050 | - return $this->_is_caf; |
|
| 4051 | - } |
|
| 4052 | - |
|
| 4053 | - |
|
| 4054 | - /** |
|
| 4055 | - * @return mixed |
|
| 4056 | - */ |
|
| 4057 | - public function default_espresso_metaboxes() |
|
| 4058 | - { |
|
| 4059 | - return $this->_default_espresso_metaboxes; |
|
| 4060 | - } |
|
| 4061 | - |
|
| 4062 | - |
|
| 4063 | - /** |
|
| 4064 | - * @return mixed |
|
| 4065 | - */ |
|
| 4066 | - public function admin_base_url() |
|
| 4067 | - { |
|
| 4068 | - return $this->_admin_base_url; |
|
| 4069 | - } |
|
| 4070 | - |
|
| 4071 | - |
|
| 4072 | - /** |
|
| 4073 | - * @return mixed |
|
| 4074 | - */ |
|
| 4075 | - public function wp_page_slug() |
|
| 4076 | - { |
|
| 4077 | - return $this->_wp_page_slug; |
|
| 4078 | - } |
|
| 4079 | - |
|
| 4080 | - |
|
| 4081 | - /** |
|
| 4082 | - * updates espresso configuration settings |
|
| 4083 | - * |
|
| 4084 | - * @param string $tab |
|
| 4085 | - * @param EE_Config_Base|EE_Config $config |
|
| 4086 | - * @param string $file file where error occurred |
|
| 4087 | - * @param string $func function where error occurred |
|
| 4088 | - * @param string $line line no where error occurred |
|
| 4089 | - * @return boolean |
|
| 4090 | - */ |
|
| 4091 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4092 | - { |
|
| 4093 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 4094 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 4095 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4096 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4097 | - update_option('ee_ueip_has_notified', true); |
|
| 4098 | - } |
|
| 4099 | - // and save it (note we're also doing the network save here) |
|
| 4100 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4101 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4102 | - if ($config_saved && $net_saved) { |
|
| 4103 | - EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4104 | - return true; |
|
| 4105 | - } |
|
| 4106 | - EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4107 | - return false; |
|
| 4108 | - } |
|
| 4109 | - |
|
| 4110 | - |
|
| 4111 | - /** |
|
| 4112 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4113 | - * |
|
| 4114 | - * @return array |
|
| 4115 | - */ |
|
| 4116 | - public function get_yes_no_values() |
|
| 4117 | - { |
|
| 4118 | - return $this->_yes_no_values; |
|
| 4119 | - } |
|
| 4120 | - |
|
| 4121 | - |
|
| 4122 | - protected function _get_dir() |
|
| 4123 | - { |
|
| 4124 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 4125 | - return dirname($reflector->getFileName()); |
|
| 4126 | - } |
|
| 4127 | - |
|
| 4128 | - |
|
| 4129 | - /** |
|
| 4130 | - * A helper for getting a "next link". |
|
| 4131 | - * |
|
| 4132 | - * @param string $url The url to link to |
|
| 4133 | - * @param string $class The class to use. |
|
| 4134 | - * @return string |
|
| 4135 | - */ |
|
| 4136 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4137 | - { |
|
| 4138 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4139 | - } |
|
| 4140 | - |
|
| 4141 | - |
|
| 4142 | - /** |
|
| 4143 | - * A helper for getting a "previous link". |
|
| 4144 | - * |
|
| 4145 | - * @param string $url The url to link to |
|
| 4146 | - * @param string $class The class to use. |
|
| 4147 | - * @return string |
|
| 4148 | - */ |
|
| 4149 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4150 | - { |
|
| 4151 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4152 | - } |
|
| 4153 | - |
|
| 4154 | - |
|
| 4155 | - |
|
| 4156 | - |
|
| 4157 | - |
|
| 4158 | - |
|
| 4159 | - |
|
| 4160 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4161 | - |
|
| 4162 | - |
|
| 4163 | - /** |
|
| 4164 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4165 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4166 | - * _req_data array. |
|
| 4167 | - * |
|
| 4168 | - * @return bool success/fail |
|
| 4169 | - * @throws EE_Error |
|
| 4170 | - * @throws InvalidArgumentException |
|
| 4171 | - * @throws ReflectionException |
|
| 4172 | - * @throws InvalidDataTypeException |
|
| 4173 | - * @throws InvalidInterfaceException |
|
| 4174 | - */ |
|
| 4175 | - protected function _process_resend_registration() |
|
| 4176 | - { |
|
| 4177 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4178 | - do_action( |
|
| 4179 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4180 | - $this->_template_args['success'], |
|
| 4181 | - $this->request->requestParams() |
|
| 4182 | - ); |
|
| 4183 | - return $this->_template_args['success']; |
|
| 4184 | - } |
|
| 4185 | - |
|
| 4186 | - |
|
| 4187 | - /** |
|
| 4188 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4189 | - * |
|
| 4190 | - * @param EE_Payment $payment |
|
| 4191 | - * @return bool success/fail |
|
| 4192 | - */ |
|
| 4193 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4194 | - { |
|
| 4195 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4196 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4197 | - $this->_template_args['success'] = apply_filters( |
|
| 4198 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4199 | - false, |
|
| 4200 | - $payment |
|
| 4201 | - ); |
|
| 4202 | - return $this->_template_args['success']; |
|
| 4203 | - } |
|
| 2764 | + } |
|
| 2765 | + |
|
| 2766 | + |
|
| 2767 | + /** |
|
| 2768 | + * facade for add_meta_box |
|
| 2769 | + * |
|
| 2770 | + * @param string $action where the metabox get's displayed |
|
| 2771 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2772 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2773 | + * instead of the one created in here. |
|
| 2774 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2775 | + * @param string $column what metabox column |
|
| 2776 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2777 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2778 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2779 | + * @throws DomainException |
|
| 2780 | + */ |
|
| 2781 | + public function _add_admin_page_meta_box( |
|
| 2782 | + $action, |
|
| 2783 | + $title, |
|
| 2784 | + $callback, |
|
| 2785 | + $callback_args, |
|
| 2786 | + $column = 'normal', |
|
| 2787 | + $priority = 'high', |
|
| 2788 | + $create_func = true |
|
| 2789 | + ) { |
|
| 2790 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2791 | + // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
| 2792 | + if (empty($callback_args) && $create_func) { |
|
| 2793 | + $callback_args = [ |
|
| 2794 | + 'template_path' => $this->_template_path, |
|
| 2795 | + 'template_args' => $this->_template_args, |
|
| 2796 | + ]; |
|
| 2797 | + } |
|
| 2798 | + // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
| 2799 | + $call_back_func = $create_func |
|
| 2800 | + ? function ($post, $metabox) { |
|
| 2801 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2802 | + echo EEH_Template::display_template( |
|
| 2803 | + $metabox['args']['template_path'], |
|
| 2804 | + $metabox['args']['template_args'], |
|
| 2805 | + true |
|
| 2806 | + ); |
|
| 2807 | + } |
|
| 2808 | + : $callback; |
|
| 2809 | + add_meta_box( |
|
| 2810 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2811 | + $title, |
|
| 2812 | + $call_back_func, |
|
| 2813 | + $this->_wp_page_slug, |
|
| 2814 | + $column, |
|
| 2815 | + $priority, |
|
| 2816 | + $callback_args |
|
| 2817 | + ); |
|
| 2818 | + } |
|
| 2819 | + |
|
| 2820 | + |
|
| 2821 | + /** |
|
| 2822 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2823 | + * |
|
| 2824 | + * @throws DomainException |
|
| 2825 | + * @throws EE_Error |
|
| 2826 | + */ |
|
| 2827 | + public function display_admin_page_with_metabox_columns() |
|
| 2828 | + { |
|
| 2829 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2830 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2831 | + $this->_column_template_path, |
|
| 2832 | + $this->_template_args, |
|
| 2833 | + true |
|
| 2834 | + ); |
|
| 2835 | + // the final wrapper |
|
| 2836 | + $this->admin_page_wrapper(); |
|
| 2837 | + } |
|
| 2838 | + |
|
| 2839 | + |
|
| 2840 | + /** |
|
| 2841 | + * generates HTML wrapper for an admin details page |
|
| 2842 | + * |
|
| 2843 | + * @return void |
|
| 2844 | + * @throws EE_Error |
|
| 2845 | + * @throws DomainException |
|
| 2846 | + */ |
|
| 2847 | + public function display_admin_page_with_sidebar() |
|
| 2848 | + { |
|
| 2849 | + $this->_display_admin_page(true); |
|
| 2850 | + } |
|
| 2851 | + |
|
| 2852 | + |
|
| 2853 | + /** |
|
| 2854 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2855 | + * |
|
| 2856 | + * @return void |
|
| 2857 | + * @throws EE_Error |
|
| 2858 | + * @throws DomainException |
|
| 2859 | + */ |
|
| 2860 | + public function display_admin_page_with_no_sidebar() |
|
| 2861 | + { |
|
| 2862 | + $this->_display_admin_page(); |
|
| 2863 | + } |
|
| 2864 | + |
|
| 2865 | + |
|
| 2866 | + /** |
|
| 2867 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2868 | + * |
|
| 2869 | + * @return void |
|
| 2870 | + * @throws EE_Error |
|
| 2871 | + * @throws DomainException |
|
| 2872 | + */ |
|
| 2873 | + public function display_about_admin_page() |
|
| 2874 | + { |
|
| 2875 | + $this->_display_admin_page(false, true); |
|
| 2876 | + } |
|
| 2877 | + |
|
| 2878 | + |
|
| 2879 | + /** |
|
| 2880 | + * display_admin_page |
|
| 2881 | + * contains the code for actually displaying an admin page |
|
| 2882 | + * |
|
| 2883 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2884 | + * @param boolean $about use the about_admin_wrapper instead of the default. |
|
| 2885 | + * @return void |
|
| 2886 | + * @throws DomainException |
|
| 2887 | + * @throws EE_Error |
|
| 2888 | + */ |
|
| 2889 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2890 | + { |
|
| 2891 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2892 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2893 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2894 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2895 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2896 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2897 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2898 | + ? 'poststuff' |
|
| 2899 | + : 'espresso-default-admin'; |
|
| 2900 | + $template_path = $sidebar |
|
| 2901 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2902 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2903 | + if ($this->request->isAjax()) { |
|
| 2904 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2905 | + } |
|
| 2906 | + $template_path = ! empty($this->_column_template_path) |
|
| 2907 | + ? $this->_column_template_path : $template_path; |
|
| 2908 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2909 | + ? $this->_template_args['admin_page_content'] |
|
| 2910 | + : ''; |
|
| 2911 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2912 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2913 | + : ''; |
|
| 2914 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2915 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2916 | + : ''; |
|
| 2917 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2918 | + $template_path, |
|
| 2919 | + $this->_template_args, |
|
| 2920 | + true |
|
| 2921 | + ); |
|
| 2922 | + // the final template wrapper |
|
| 2923 | + $this->admin_page_wrapper($about); |
|
| 2924 | + } |
|
| 2925 | + |
|
| 2926 | + |
|
| 2927 | + /** |
|
| 2928 | + * This is used to display caf preview pages. |
|
| 2929 | + * |
|
| 2930 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2931 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2932 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2933 | + * @return void |
|
| 2934 | + * @throws DomainException |
|
| 2935 | + * @throws EE_Error |
|
| 2936 | + * @throws InvalidArgumentException |
|
| 2937 | + * @throws InvalidDataTypeException |
|
| 2938 | + * @throws InvalidInterfaceException |
|
| 2939 | + * @since 4.3.2 |
|
| 2940 | + */ |
|
| 2941 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2942 | + { |
|
| 2943 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2944 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2945 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2946 | + 'event_espresso' |
|
| 2947 | + ); |
|
| 2948 | + $buy_now_url = add_query_arg( |
|
| 2949 | + [ |
|
| 2950 | + 'ee_ver' => 'ee4', |
|
| 2951 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2952 | + 'utm_medium' => 'link', |
|
| 2953 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2954 | + 'utm_content' => 'buy_now_button', |
|
| 2955 | + ], |
|
| 2956 | + 'https://eventespresso.com/pricing/' |
|
| 2957 | + ); |
|
| 2958 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2959 | + ? $this->get_action_link_or_button( |
|
| 2960 | + '', |
|
| 2961 | + 'buy_now', |
|
| 2962 | + [], |
|
| 2963 | + 'button-primary button-large', |
|
| 2964 | + esc_url_raw($buy_now_url), |
|
| 2965 | + true |
|
| 2966 | + ) |
|
| 2967 | + : $this->_template_args['preview_action_button']; |
|
| 2968 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2969 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2970 | + $this->_template_args, |
|
| 2971 | + true |
|
| 2972 | + ); |
|
| 2973 | + $this->_display_admin_page($display_sidebar); |
|
| 2974 | + } |
|
| 2975 | + |
|
| 2976 | + |
|
| 2977 | + /** |
|
| 2978 | + * display_admin_list_table_page_with_sidebar |
|
| 2979 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2980 | + * |
|
| 2981 | + * @return void |
|
| 2982 | + * @throws EE_Error |
|
| 2983 | + * @throws DomainException |
|
| 2984 | + */ |
|
| 2985 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2986 | + { |
|
| 2987 | + $this->_display_admin_list_table_page(true); |
|
| 2988 | + } |
|
| 2989 | + |
|
| 2990 | + |
|
| 2991 | + /** |
|
| 2992 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2993 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2994 | + * |
|
| 2995 | + * @return void |
|
| 2996 | + * @throws EE_Error |
|
| 2997 | + * @throws DomainException |
|
| 2998 | + */ |
|
| 2999 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 3000 | + { |
|
| 3001 | + $this->_display_admin_list_table_page(); |
|
| 3002 | + } |
|
| 3003 | + |
|
| 3004 | + |
|
| 3005 | + /** |
|
| 3006 | + * generates html wrapper for an admin_list_table page |
|
| 3007 | + * |
|
| 3008 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 3009 | + * @return void |
|
| 3010 | + * @throws DomainException |
|
| 3011 | + * @throws EE_Error |
|
| 3012 | + */ |
|
| 3013 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 3014 | + { |
|
| 3015 | + // setup search attributes |
|
| 3016 | + $this->_set_search_attributes(); |
|
| 3017 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 3018 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 3019 | + $this->_template_args['table_url'] = $this->request->isAjax() |
|
| 3020 | + ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url) |
|
| 3021 | + : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url); |
|
| 3022 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 3023 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 3024 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 3025 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 3026 | + if (! empty($ajax_sorting_callback)) { |
|
| 3027 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 3028 | + $ajax_sorting_callback . '_nonce', |
|
| 3029 | + $ajax_sorting_callback . '_nonce', |
|
| 3030 | + false, |
|
| 3031 | + false |
|
| 3032 | + ); |
|
| 3033 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3034 | + . $this->page_slug |
|
| 3035 | + . '" />'; |
|
| 3036 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3037 | + . $ajax_sorting_callback |
|
| 3038 | + . '" />'; |
|
| 3039 | + } else { |
|
| 3040 | + $sortable_list_table_form_fields = ''; |
|
| 3041 | + } |
|
| 3042 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3043 | + $hidden_form_fields = |
|
| 3044 | + isset($this->_template_args['list_table_hidden_fields']) |
|
| 3045 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 3046 | + : ''; |
|
| 3047 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3048 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3049 | + . $nonce_ref |
|
| 3050 | + . '" value="' |
|
| 3051 | + . wp_create_nonce($nonce_ref) |
|
| 3052 | + . '">'; |
|
| 3053 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3054 | + // display message about search results? |
|
| 3055 | + $search = $this->request->getRequestParam('s'); |
|
| 3056 | + $this->_template_args['before_list_table'] .= ! empty($search) |
|
| 3057 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 3058 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3059 | + trim($search, '%') |
|
| 3060 | + ) . '</p>' |
|
| 3061 | + : ''; |
|
| 3062 | + // filter before_list_table template arg |
|
| 3063 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 3064 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3065 | + $this->_template_args['before_list_table'], |
|
| 3066 | + $this->page_slug, |
|
| 3067 | + $this->request->requestParams(), |
|
| 3068 | + $this->_req_action |
|
| 3069 | + ); |
|
| 3070 | + // convert to array and filter again |
|
| 3071 | + // arrays are easier to inject new items in a specific location, |
|
| 3072 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3073 | + $this->_template_args['before_list_table'] = implode( |
|
| 3074 | + " \n", |
|
| 3075 | + (array) apply_filters( |
|
| 3076 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3077 | + (array) $this->_template_args['before_list_table'], |
|
| 3078 | + $this->page_slug, |
|
| 3079 | + $this->request->requestParams(), |
|
| 3080 | + $this->_req_action |
|
| 3081 | + ) |
|
| 3082 | + ); |
|
| 3083 | + // filter after_list_table template arg |
|
| 3084 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3085 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3086 | + $this->_template_args['after_list_table'], |
|
| 3087 | + $this->page_slug, |
|
| 3088 | + $this->request->requestParams(), |
|
| 3089 | + $this->_req_action |
|
| 3090 | + ); |
|
| 3091 | + // convert to array and filter again |
|
| 3092 | + // arrays are easier to inject new items in a specific location, |
|
| 3093 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3094 | + $this->_template_args['after_list_table'] = implode( |
|
| 3095 | + " \n", |
|
| 3096 | + (array) apply_filters( |
|
| 3097 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3098 | + (array) $this->_template_args['after_list_table'], |
|
| 3099 | + $this->page_slug, |
|
| 3100 | + $this->request->requestParams(), |
|
| 3101 | + $this->_req_action |
|
| 3102 | + ) |
|
| 3103 | + ); |
|
| 3104 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3105 | + $template_path, |
|
| 3106 | + $this->_template_args, |
|
| 3107 | + true |
|
| 3108 | + ); |
|
| 3109 | + // the final template wrapper |
|
| 3110 | + if ($sidebar) { |
|
| 3111 | + $this->display_admin_page_with_sidebar(); |
|
| 3112 | + } else { |
|
| 3113 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3114 | + } |
|
| 3115 | + } |
|
| 3116 | + |
|
| 3117 | + |
|
| 3118 | + /** |
|
| 3119 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3120 | + * html string for the legend. |
|
| 3121 | + * $items are expected in an array in the following format: |
|
| 3122 | + * $legend_items = array( |
|
| 3123 | + * 'item_id' => array( |
|
| 3124 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3125 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3126 | + * ) |
|
| 3127 | + * ); |
|
| 3128 | + * |
|
| 3129 | + * @param array $items see above for format of array |
|
| 3130 | + * @return string html string of legend |
|
| 3131 | + * @throws DomainException |
|
| 3132 | + */ |
|
| 3133 | + protected function _display_legend($items) |
|
| 3134 | + { |
|
| 3135 | + $this->_template_args['items'] = apply_filters( |
|
| 3136 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3137 | + (array) $items, |
|
| 3138 | + $this |
|
| 3139 | + ); |
|
| 3140 | + return EEH_Template::display_template( |
|
| 3141 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3142 | + $this->_template_args, |
|
| 3143 | + true |
|
| 3144 | + ); |
|
| 3145 | + } |
|
| 3146 | + |
|
| 3147 | + |
|
| 3148 | + /** |
|
| 3149 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3150 | + * The returned json object is created from an array in the following format: |
|
| 3151 | + * array( |
|
| 3152 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3153 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3154 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3155 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3156 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3157 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3158 | + * that might be included in here) |
|
| 3159 | + * ) |
|
| 3160 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3161 | + * |
|
| 3162 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3163 | + * instead of displayed. |
|
| 3164 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3165 | + * @return void |
|
| 3166 | + * @throws EE_Error |
|
| 3167 | + */ |
|
| 3168 | + protected function _return_json($sticky_notices = false, $notices_arguments = []) |
|
| 3169 | + { |
|
| 3170 | + // make sure any EE_Error notices have been handled. |
|
| 3171 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3172 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : []; |
|
| 3173 | + unset($this->_template_args['data']); |
|
| 3174 | + $json = [ |
|
| 3175 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3176 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3177 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3178 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3179 | + 'notices' => EE_Error::get_notices(), |
|
| 3180 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3181 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3182 | + 'data' => array_merge($data, ['template_args' => $this->_template_args]), |
|
| 3183 | + 'isEEajax' => true |
|
| 3184 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3185 | + ]; |
|
| 3186 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3187 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3188 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3189 | + } |
|
| 3190 | + echo wp_json_encode($json); |
|
| 3191 | + exit(); |
|
| 3192 | + } |
|
| 3193 | + |
|
| 3194 | + |
|
| 3195 | + /** |
|
| 3196 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3197 | + * |
|
| 3198 | + * @return void |
|
| 3199 | + * @throws EE_Error |
|
| 3200 | + */ |
|
| 3201 | + public function return_json() |
|
| 3202 | + { |
|
| 3203 | + if ($this->request->isAjax()) { |
|
| 3204 | + $this->_return_json(); |
|
| 3205 | + } else { |
|
| 3206 | + throw new EE_Error( |
|
| 3207 | + sprintf( |
|
| 3208 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3209 | + __FUNCTION__ |
|
| 3210 | + ) |
|
| 3211 | + ); |
|
| 3212 | + } |
|
| 3213 | + } |
|
| 3214 | + |
|
| 3215 | + |
|
| 3216 | + /** |
|
| 3217 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3218 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3219 | + * |
|
| 3220 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3221 | + */ |
|
| 3222 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3223 | + { |
|
| 3224 | + $this->_hook_obj = $hook_obj; |
|
| 3225 | + } |
|
| 3226 | + |
|
| 3227 | + |
|
| 3228 | + /** |
|
| 3229 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3230 | + * |
|
| 3231 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3232 | + * @return void |
|
| 3233 | + * @throws DomainException |
|
| 3234 | + * @throws EE_Error |
|
| 3235 | + */ |
|
| 3236 | + public function admin_page_wrapper($about = false) |
|
| 3237 | + { |
|
| 3238 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3239 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3240 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3241 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3242 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3243 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3244 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3245 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3246 | + : '' |
|
| 3247 | + ); |
|
| 3248 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3249 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3250 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3251 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3252 | + : '' |
|
| 3253 | + ); |
|
| 3254 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3255 | + // load settings page wrapper template |
|
| 3256 | + $template_path = ! $this->request->isAjax() |
|
| 3257 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3258 | + : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php'; |
|
| 3259 | + // about page? |
|
| 3260 | + $template_path = $about |
|
| 3261 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3262 | + : $template_path; |
|
| 3263 | + if ($this->request->isAjax()) { |
|
| 3264 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3265 | + $template_path, |
|
| 3266 | + $this->_template_args, |
|
| 3267 | + true |
|
| 3268 | + ); |
|
| 3269 | + $this->_return_json(); |
|
| 3270 | + } else { |
|
| 3271 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3272 | + } |
|
| 3273 | + } |
|
| 3274 | + |
|
| 3275 | + |
|
| 3276 | + /** |
|
| 3277 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3278 | + * |
|
| 3279 | + * @return string html |
|
| 3280 | + * @throws EE_Error |
|
| 3281 | + */ |
|
| 3282 | + protected function _get_main_nav_tabs() |
|
| 3283 | + { |
|
| 3284 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3285 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3286 | + // (rather than setting in the page_routes array) |
|
| 3287 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3288 | + } |
|
| 3289 | + |
|
| 3290 | + |
|
| 3291 | + /** |
|
| 3292 | + * sort nav tabs |
|
| 3293 | + * |
|
| 3294 | + * @param $a |
|
| 3295 | + * @param $b |
|
| 3296 | + * @return int |
|
| 3297 | + */ |
|
| 3298 | + private function _sort_nav_tabs($a, $b) |
|
| 3299 | + { |
|
| 3300 | + if ($a['order'] === $b['order']) { |
|
| 3301 | + return 0; |
|
| 3302 | + } |
|
| 3303 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3304 | + } |
|
| 3305 | + |
|
| 3306 | + |
|
| 3307 | + /** |
|
| 3308 | + * generates HTML for the forms used on admin pages |
|
| 3309 | + * |
|
| 3310 | + * @param array $input_vars - array of input field details |
|
| 3311 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
| 3312 | + * use) |
|
| 3313 | + * @param bool $id |
|
| 3314 | + * @return array|string |
|
| 3315 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3316 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3317 | + */ |
|
| 3318 | + protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3319 | + { |
|
| 3320 | + return $generator === 'string' |
|
| 3321 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3322 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3323 | + } |
|
| 3324 | + |
|
| 3325 | + |
|
| 3326 | + /** |
|
| 3327 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3328 | + * |
|
| 3329 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3330 | + * Close" button. |
|
| 3331 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3332 | + * 'Save', [1] => 'save & close') |
|
| 3333 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3334 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3335 | + * default actions by submitting some other value. |
|
| 3336 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3337 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3338 | + * close (normal form handling). |
|
| 3339 | + */ |
|
| 3340 | + protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null) |
|
| 3341 | + { |
|
| 3342 | + // make sure $text and $actions are in an array |
|
| 3343 | + $text = (array) $text; |
|
| 3344 | + $actions = (array) $actions; |
|
| 3345 | + $referrer_url = empty($referrer) |
|
| 3346 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3347 | + . $this->request->getServerParam('REQUEST_URI') |
|
| 3348 | + . '" />' |
|
| 3349 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3350 | + . $referrer |
|
| 3351 | + . '" />'; |
|
| 3352 | + $button_text = ! empty($text) |
|
| 3353 | + ? $text |
|
| 3354 | + : [ |
|
| 3355 | + esc_html__('Save', 'event_espresso'), |
|
| 3356 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3357 | + ]; |
|
| 3358 | + $default_names = ['save', 'save_and_close']; |
|
| 3359 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3360 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3361 | + foreach ($button_text as $key => $button) { |
|
| 3362 | + $ref = $default_names[ $key ]; |
|
| 3363 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3364 | + . $ref |
|
| 3365 | + . '" value="' |
|
| 3366 | + . $button |
|
| 3367 | + . '" name="' |
|
| 3368 | + . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3369 | + . '" id="' |
|
| 3370 | + . $this->_current_view . '_' . $ref |
|
| 3371 | + . '" />'; |
|
| 3372 | + if (! $both) { |
|
| 3373 | + break; |
|
| 3374 | + } |
|
| 3375 | + } |
|
| 3376 | + } |
|
| 3377 | + |
|
| 3378 | + |
|
| 3379 | + /** |
|
| 3380 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3381 | + * |
|
| 3382 | + * @param string $route |
|
| 3383 | + * @param array $additional_hidden_fields |
|
| 3384 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3385 | + * @since 4.6.0 |
|
| 3386 | + */ |
|
| 3387 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3388 | + { |
|
| 3389 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3390 | + } |
|
| 3391 | + |
|
| 3392 | + |
|
| 3393 | + /** |
|
| 3394 | + * set form open and close tags on add/edit pages. |
|
| 3395 | + * |
|
| 3396 | + * @param string $route the route you want the form to direct to |
|
| 3397 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3398 | + * @return void |
|
| 3399 | + */ |
|
| 3400 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = []) |
|
| 3401 | + { |
|
| 3402 | + if (empty($route)) { |
|
| 3403 | + $user_msg = esc_html__( |
|
| 3404 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3405 | + 'event_espresso' |
|
| 3406 | + ); |
|
| 3407 | + $dev_msg = $user_msg . "\n" |
|
| 3408 | + . sprintf( |
|
| 3409 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3410 | + __FUNCTION__, |
|
| 3411 | + __CLASS__ |
|
| 3412 | + ); |
|
| 3413 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3414 | + } |
|
| 3415 | + // open form |
|
| 3416 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3417 | + . $this->_admin_base_url |
|
| 3418 | + . '" id="' |
|
| 3419 | + . $route |
|
| 3420 | + . '_event_form" >'; |
|
| 3421 | + // add nonce |
|
| 3422 | + $nonce = |
|
| 3423 | + wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3424 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3425 | + // add REQUIRED form action |
|
| 3426 | + $hidden_fields = [ |
|
| 3427 | + 'action' => ['type' => 'hidden', 'value' => $route], |
|
| 3428 | + ]; |
|
| 3429 | + // merge arrays |
|
| 3430 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3431 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3432 | + : $hidden_fields; |
|
| 3433 | + // generate form fields |
|
| 3434 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3435 | + // add fields to form |
|
| 3436 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3437 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3438 | + } |
|
| 3439 | + // close form |
|
| 3440 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3441 | + } |
|
| 3442 | + |
|
| 3443 | + |
|
| 3444 | + /** |
|
| 3445 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3446 | + * discovered it would be useful for external code to have access. |
|
| 3447 | + * |
|
| 3448 | + * @param bool $success |
|
| 3449 | + * @param string $what |
|
| 3450 | + * @param string $action_desc |
|
| 3451 | + * @param array $query_args |
|
| 3452 | + * @param bool $override_overwrite |
|
| 3453 | + * @throws EE_Error |
|
| 3454 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3455 | + * @since 4.5.0 |
|
| 3456 | + */ |
|
| 3457 | + public function redirect_after_action( |
|
| 3458 | + $success = false, |
|
| 3459 | + $what = 'item', |
|
| 3460 | + $action_desc = 'processed', |
|
| 3461 | + $query_args = [], |
|
| 3462 | + $override_overwrite = false |
|
| 3463 | + ) { |
|
| 3464 | + $this->_redirect_after_action( |
|
| 3465 | + $success, |
|
| 3466 | + $what, |
|
| 3467 | + $action_desc, |
|
| 3468 | + $query_args, |
|
| 3469 | + $override_overwrite |
|
| 3470 | + ); |
|
| 3471 | + } |
|
| 3472 | + |
|
| 3473 | + |
|
| 3474 | + /** |
|
| 3475 | + * Helper method for merging existing request data with the returned redirect url. |
|
| 3476 | + * |
|
| 3477 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3478 | + * filters are still applied. |
|
| 3479 | + * |
|
| 3480 | + * @param array $new_route_data |
|
| 3481 | + * @return array |
|
| 3482 | + */ |
|
| 3483 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3484 | + { |
|
| 3485 | + foreach ($this->request->requestParams() as $ref => $value) { |
|
| 3486 | + // unset nonces |
|
| 3487 | + if (strpos($ref, 'nonce') !== false) { |
|
| 3488 | + $this->request->unSetRequestParam($ref); |
|
| 3489 | + continue; |
|
| 3490 | + } |
|
| 3491 | + // urlencode values. |
|
| 3492 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3493 | + $this->request->setRequestParam($ref, $value); |
|
| 3494 | + } |
|
| 3495 | + return array_merge($this->request->requestParams(), $new_route_data); |
|
| 3496 | + } |
|
| 3497 | + |
|
| 3498 | + |
|
| 3499 | + /** |
|
| 3500 | + * _redirect_after_action |
|
| 3501 | + * |
|
| 3502 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3503 | + * @param string $what - what the action was performed on |
|
| 3504 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3505 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3506 | + * action is completed |
|
| 3507 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3508 | + * override this so that they show. |
|
| 3509 | + * @return void |
|
| 3510 | + * @throws EE_Error |
|
| 3511 | + */ |
|
| 3512 | + protected function _redirect_after_action( |
|
| 3513 | + $success = 0, |
|
| 3514 | + $what = 'item', |
|
| 3515 | + $action_desc = 'processed', |
|
| 3516 | + $query_args = [], |
|
| 3517 | + $override_overwrite = false |
|
| 3518 | + ) { |
|
| 3519 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3520 | + // class name for actions/filters. |
|
| 3521 | + $classname = get_class($this); |
|
| 3522 | + // set redirect url. |
|
| 3523 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3524 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3525 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3526 | + $notices = EE_Error::get_notices(false); |
|
| 3527 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3528 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3529 | + EE_Error::overwrite_success(); |
|
| 3530 | + } |
|
| 3531 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3532 | + // how many records affected ? more than one record ? or just one ? |
|
| 3533 | + if ($success > 1) { |
|
| 3534 | + // set plural msg |
|
| 3535 | + EE_Error::add_success( |
|
| 3536 | + sprintf( |
|
| 3537 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3538 | + $what, |
|
| 3539 | + $action_desc |
|
| 3540 | + ), |
|
| 3541 | + __FILE__, |
|
| 3542 | + __FUNCTION__, |
|
| 3543 | + __LINE__ |
|
| 3544 | + ); |
|
| 3545 | + } elseif ($success === 1) { |
|
| 3546 | + // set singular msg |
|
| 3547 | + EE_Error::add_success( |
|
| 3548 | + sprintf( |
|
| 3549 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3550 | + $what, |
|
| 3551 | + $action_desc |
|
| 3552 | + ), |
|
| 3553 | + __FILE__, |
|
| 3554 | + __FUNCTION__, |
|
| 3555 | + __LINE__ |
|
| 3556 | + ); |
|
| 3557 | + } |
|
| 3558 | + } |
|
| 3559 | + // check that $query_args isn't something crazy |
|
| 3560 | + if (! is_array($query_args)) { |
|
| 3561 | + $query_args = []; |
|
| 3562 | + } |
|
| 3563 | + /** |
|
| 3564 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3565 | + * redirections on save and close actions |
|
| 3566 | + * |
|
| 3567 | + * @param array $query_args The original query_args array coming into the |
|
| 3568 | + * method. |
|
| 3569 | + * @since 4.2.0 |
|
| 3570 | + */ |
|
| 3571 | + do_action( |
|
| 3572 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3573 | + $query_args |
|
| 3574 | + ); |
|
| 3575 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3576 | + |
|
| 3577 | + if ( |
|
| 3578 | + $this->request->requestParamIsSet('save_and_close') |
|
| 3579 | + && $this->request->requestParamIsSet('save_and_close_referrer') |
|
| 3580 | + ) { |
|
| 3581 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3582 | + $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url')); |
|
| 3583 | + // regenerate query args array from referrer URL |
|
| 3584 | + parse_str($parsed_url['query'], $query_args); |
|
| 3585 | + // correct page and action will be in the query args now |
|
| 3586 | + $redirect_url = admin_url('admin.php'); |
|
| 3587 | + } |
|
| 3588 | + // merge any default query_args set in _default_route_query_args property |
|
| 3589 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3590 | + $args_to_merge = []; |
|
| 3591 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3592 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3593 | + if ($query_param === 'wp_referer') { |
|
| 3594 | + $query_value = (array) $query_value; |
|
| 3595 | + foreach ($query_value as $reference => $value) { |
|
| 3596 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3597 | + continue; |
|
| 3598 | + } |
|
| 3599 | + // finally we will override any arguments in the referer with |
|
| 3600 | + // what might be set on the _default_route_query_args array. |
|
| 3601 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3602 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3603 | + } else { |
|
| 3604 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3605 | + } |
|
| 3606 | + } |
|
| 3607 | + continue; |
|
| 3608 | + } |
|
| 3609 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3610 | + } |
|
| 3611 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3612 | + // redirect. |
|
| 3613 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3614 | + } |
|
| 3615 | + $this->_process_notices($query_args); |
|
| 3616 | + // generate redirect url |
|
| 3617 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3618 | + if (isset($query_args['action'])) { |
|
| 3619 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3620 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3621 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3622 | + } |
|
| 3623 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3624 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3625 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3626 | + $redirect_url = apply_filters( |
|
| 3627 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3628 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3629 | + $query_args |
|
| 3630 | + ); |
|
| 3631 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3632 | + if ($this->request->isAjax()) { |
|
| 3633 | + $default_data = [ |
|
| 3634 | + 'close' => true, |
|
| 3635 | + 'redirect_url' => $redirect_url, |
|
| 3636 | + 'where' => 'main', |
|
| 3637 | + 'what' => 'append', |
|
| 3638 | + ]; |
|
| 3639 | + $this->_template_args['success'] = $success; |
|
| 3640 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3641 | + $default_data, |
|
| 3642 | + $this->_template_args['data'] |
|
| 3643 | + ) : $default_data; |
|
| 3644 | + $this->_return_json(); |
|
| 3645 | + } |
|
| 3646 | + wp_safe_redirect($redirect_url); |
|
| 3647 | + exit(); |
|
| 3648 | + } |
|
| 3649 | + |
|
| 3650 | + |
|
| 3651 | + /** |
|
| 3652 | + * process any notices before redirecting (or returning ajax request) |
|
| 3653 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3654 | + * |
|
| 3655 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3656 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3657 | + * page_routes haven't been defined yet. |
|
| 3658 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3659 | + * still save a transient for the notice. |
|
| 3660 | + * @return void |
|
| 3661 | + * @throws EE_Error |
|
| 3662 | + */ |
|
| 3663 | + protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true) |
|
| 3664 | + { |
|
| 3665 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3666 | + if ($this->request->isAjax()) { |
|
| 3667 | + $notices = EE_Error::get_notices(false); |
|
| 3668 | + if (empty($this->_template_args['success'])) { |
|
| 3669 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3670 | + } |
|
| 3671 | + if (empty($this->_template_args['errors'])) { |
|
| 3672 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3673 | + } |
|
| 3674 | + if (empty($this->_template_args['attention'])) { |
|
| 3675 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3676 | + } |
|
| 3677 | + } |
|
| 3678 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3679 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3680 | + if (! $this->request->isAjax() || $sticky_notices) { |
|
| 3681 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3682 | + $this->_add_transient( |
|
| 3683 | + $route, |
|
| 3684 | + $this->_template_args['notices'], |
|
| 3685 | + true, |
|
| 3686 | + $skip_route_verify |
|
| 3687 | + ); |
|
| 3688 | + } |
|
| 3689 | + } |
|
| 3690 | + |
|
| 3691 | + |
|
| 3692 | + /** |
|
| 3693 | + * get_action_link_or_button |
|
| 3694 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3695 | + * |
|
| 3696 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3697 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3698 | + * property. |
|
| 3699 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3700 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3701 | + * @param string $base_url If this is not provided |
|
| 3702 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3703 | + * Otherwise this value will be used. |
|
| 3704 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3705 | + * @return string |
|
| 3706 | + * @throws InvalidArgumentException |
|
| 3707 | + * @throws InvalidInterfaceException |
|
| 3708 | + * @throws InvalidDataTypeException |
|
| 3709 | + * @throws EE_Error |
|
| 3710 | + */ |
|
| 3711 | + public function get_action_link_or_button( |
|
| 3712 | + $action, |
|
| 3713 | + $type = 'add', |
|
| 3714 | + $extra_request = [], |
|
| 3715 | + $class = 'button-primary', |
|
| 3716 | + $base_url = '', |
|
| 3717 | + $exclude_nonce = false |
|
| 3718 | + ) { |
|
| 3719 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3720 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3721 | + throw new EE_Error( |
|
| 3722 | + sprintf( |
|
| 3723 | + esc_html__( |
|
| 3724 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3725 | + 'event_espresso' |
|
| 3726 | + ), |
|
| 3727 | + $action |
|
| 3728 | + ) |
|
| 3729 | + ); |
|
| 3730 | + } |
|
| 3731 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3732 | + throw new EE_Error( |
|
| 3733 | + sprintf( |
|
| 3734 | + esc_html__( |
|
| 3735 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3736 | + 'event_espresso' |
|
| 3737 | + ), |
|
| 3738 | + $type |
|
| 3739 | + ) |
|
| 3740 | + ); |
|
| 3741 | + } |
|
| 3742 | + // finally check user access for this button. |
|
| 3743 | + $has_access = $this->check_user_access($action, true); |
|
| 3744 | + if (! $has_access) { |
|
| 3745 | + return ''; |
|
| 3746 | + } |
|
| 3747 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3748 | + $query_args = [ |
|
| 3749 | + 'action' => $action, |
|
| 3750 | + ]; |
|
| 3751 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3752 | + if (! empty($extra_request)) { |
|
| 3753 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3754 | + } |
|
| 3755 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3756 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3757 | + } |
|
| 3758 | + |
|
| 3759 | + |
|
| 3760 | + /** |
|
| 3761 | + * _per_page_screen_option |
|
| 3762 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3763 | + * |
|
| 3764 | + * @return void |
|
| 3765 | + * @throws InvalidArgumentException |
|
| 3766 | + * @throws InvalidInterfaceException |
|
| 3767 | + * @throws InvalidDataTypeException |
|
| 3768 | + */ |
|
| 3769 | + protected function _per_page_screen_option() |
|
| 3770 | + { |
|
| 3771 | + $option = 'per_page'; |
|
| 3772 | + $args = [ |
|
| 3773 | + 'label' => apply_filters( |
|
| 3774 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3775 | + $this->_admin_page_title, |
|
| 3776 | + $this |
|
| 3777 | + ), |
|
| 3778 | + 'default' => (int) apply_filters( |
|
| 3779 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3780 | + 20 |
|
| 3781 | + ), |
|
| 3782 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3783 | + ]; |
|
| 3784 | + // ONLY add the screen option if the user has access to it. |
|
| 3785 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3786 | + add_screen_option($option, $args); |
|
| 3787 | + } |
|
| 3788 | + } |
|
| 3789 | + |
|
| 3790 | + |
|
| 3791 | + /** |
|
| 3792 | + * set_per_page_screen_option |
|
| 3793 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3794 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3795 | + * admin_menu. |
|
| 3796 | + * |
|
| 3797 | + * @return void |
|
| 3798 | + */ |
|
| 3799 | + private function _set_per_page_screen_options() |
|
| 3800 | + { |
|
| 3801 | + if ($this->request->requestParamIsSet('wp_screen_options')) { |
|
| 3802 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3803 | + if (! $user = wp_get_current_user()) { |
|
| 3804 | + return; |
|
| 3805 | + } |
|
| 3806 | + $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key'); |
|
| 3807 | + if (! $option) { |
|
| 3808 | + return; |
|
| 3809 | + } |
|
| 3810 | + $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int'); |
|
| 3811 | + $map_option = $option; |
|
| 3812 | + $option = str_replace('-', '_', $option); |
|
| 3813 | + switch ($map_option) { |
|
| 3814 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3815 | + $max_value = apply_filters( |
|
| 3816 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3817 | + 999, |
|
| 3818 | + $this->_current_page, |
|
| 3819 | + $this->_current_view |
|
| 3820 | + ); |
|
| 3821 | + if ($value < 1) { |
|
| 3822 | + return; |
|
| 3823 | + } |
|
| 3824 | + $value = min($value, $max_value); |
|
| 3825 | + break; |
|
| 3826 | + default: |
|
| 3827 | + $value = apply_filters( |
|
| 3828 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3829 | + false, |
|
| 3830 | + $option, |
|
| 3831 | + $value |
|
| 3832 | + ); |
|
| 3833 | + if (false === $value) { |
|
| 3834 | + return; |
|
| 3835 | + } |
|
| 3836 | + break; |
|
| 3837 | + } |
|
| 3838 | + update_user_meta($user->ID, $option, $value); |
|
| 3839 | + wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer())); |
|
| 3840 | + exit; |
|
| 3841 | + } |
|
| 3842 | + } |
|
| 3843 | + |
|
| 3844 | + |
|
| 3845 | + /** |
|
| 3846 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3847 | + * |
|
| 3848 | + * @param array $data array that will be assigned to template args. |
|
| 3849 | + */ |
|
| 3850 | + public function set_template_args($data) |
|
| 3851 | + { |
|
| 3852 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3853 | + } |
|
| 3854 | + |
|
| 3855 | + |
|
| 3856 | + /** |
|
| 3857 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3858 | + * |
|
| 3859 | + * @param string $route the route that should receive the transient |
|
| 3860 | + * @param array $data the data that gets sent |
|
| 3861 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3862 | + * normal route transient. |
|
| 3863 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3864 | + * when we are adding a transient before page_routes have been defined. |
|
| 3865 | + * @return void |
|
| 3866 | + * @throws EE_Error |
|
| 3867 | + */ |
|
| 3868 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3869 | + { |
|
| 3870 | + $user_id = get_current_user_id(); |
|
| 3871 | + if (! $skip_route_verify) { |
|
| 3872 | + $this->_verify_route($route); |
|
| 3873 | + } |
|
| 3874 | + // now let's set the string for what kind of transient we're setting |
|
| 3875 | + $transient = $notices |
|
| 3876 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3877 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3878 | + $data = $notices ? ['notices' => $data] : $data; |
|
| 3879 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3880 | + $existing = is_multisite() && is_network_admin() |
|
| 3881 | + ? get_site_transient($transient) |
|
| 3882 | + : get_transient($transient); |
|
| 3883 | + if ($existing) { |
|
| 3884 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3885 | + } |
|
| 3886 | + if (is_multisite() && is_network_admin()) { |
|
| 3887 | + set_site_transient($transient, $data, 8); |
|
| 3888 | + } else { |
|
| 3889 | + set_transient($transient, $data, 8); |
|
| 3890 | + } |
|
| 3891 | + } |
|
| 3892 | + |
|
| 3893 | + |
|
| 3894 | + /** |
|
| 3895 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3896 | + * |
|
| 3897 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3898 | + * @param string $route |
|
| 3899 | + * @return mixed data |
|
| 3900 | + */ |
|
| 3901 | + protected function _get_transient($notices = false, $route = '') |
|
| 3902 | + { |
|
| 3903 | + $user_id = get_current_user_id(); |
|
| 3904 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3905 | + $transient = $notices |
|
| 3906 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3907 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3908 | + $data = is_multisite() && is_network_admin() |
|
| 3909 | + ? get_site_transient($transient) |
|
| 3910 | + : get_transient($transient); |
|
| 3911 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3912 | + if (is_multisite() && is_network_admin()) { |
|
| 3913 | + delete_site_transient($transient); |
|
| 3914 | + } else { |
|
| 3915 | + delete_transient($transient); |
|
| 3916 | + } |
|
| 3917 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3918 | + } |
|
| 3919 | + |
|
| 3920 | + |
|
| 3921 | + /** |
|
| 3922 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3923 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3924 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3925 | + * |
|
| 3926 | + * @return void |
|
| 3927 | + */ |
|
| 3928 | + protected function _transient_garbage_collection() |
|
| 3929 | + { |
|
| 3930 | + global $wpdb; |
|
| 3931 | + // retrieve all existing transients |
|
| 3932 | + $query = |
|
| 3933 | + "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3934 | + if ($results = $wpdb->get_results($query)) { |
|
| 3935 | + foreach ($results as $result) { |
|
| 3936 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3937 | + get_transient($transient); |
|
| 3938 | + if (is_multisite() && is_network_admin()) { |
|
| 3939 | + get_site_transient($transient); |
|
| 3940 | + } |
|
| 3941 | + } |
|
| 3942 | + } |
|
| 3943 | + } |
|
| 3944 | + |
|
| 3945 | + |
|
| 3946 | + /** |
|
| 3947 | + * get_view |
|
| 3948 | + * |
|
| 3949 | + * @return string content of _view property |
|
| 3950 | + */ |
|
| 3951 | + public function get_view() |
|
| 3952 | + { |
|
| 3953 | + return $this->_view; |
|
| 3954 | + } |
|
| 3955 | + |
|
| 3956 | + |
|
| 3957 | + /** |
|
| 3958 | + * getter for the protected $_views property |
|
| 3959 | + * |
|
| 3960 | + * @return array |
|
| 3961 | + */ |
|
| 3962 | + public function get_views() |
|
| 3963 | + { |
|
| 3964 | + return $this->_views; |
|
| 3965 | + } |
|
| 3966 | + |
|
| 3967 | + |
|
| 3968 | + /** |
|
| 3969 | + * get_current_page |
|
| 3970 | + * |
|
| 3971 | + * @return string _current_page property value |
|
| 3972 | + */ |
|
| 3973 | + public function get_current_page() |
|
| 3974 | + { |
|
| 3975 | + return $this->_current_page; |
|
| 3976 | + } |
|
| 3977 | + |
|
| 3978 | + |
|
| 3979 | + /** |
|
| 3980 | + * get_current_view |
|
| 3981 | + * |
|
| 3982 | + * @return string _current_view property value |
|
| 3983 | + */ |
|
| 3984 | + public function get_current_view() |
|
| 3985 | + { |
|
| 3986 | + return $this->_current_view; |
|
| 3987 | + } |
|
| 3988 | + |
|
| 3989 | + |
|
| 3990 | + /** |
|
| 3991 | + * get_current_screen |
|
| 3992 | + * |
|
| 3993 | + * @return object The current WP_Screen object |
|
| 3994 | + */ |
|
| 3995 | + public function get_current_screen() |
|
| 3996 | + { |
|
| 3997 | + return $this->_current_screen; |
|
| 3998 | + } |
|
| 3999 | + |
|
| 4000 | + |
|
| 4001 | + /** |
|
| 4002 | + * get_current_page_view_url |
|
| 4003 | + * |
|
| 4004 | + * @return string This returns the url for the current_page_view. |
|
| 4005 | + */ |
|
| 4006 | + public function get_current_page_view_url() |
|
| 4007 | + { |
|
| 4008 | + return $this->_current_page_view_url; |
|
| 4009 | + } |
|
| 4010 | + |
|
| 4011 | + |
|
| 4012 | + /** |
|
| 4013 | + * just returns the Request |
|
| 4014 | + * |
|
| 4015 | + * @return RequestInterface |
|
| 4016 | + */ |
|
| 4017 | + public function get_request() |
|
| 4018 | + { |
|
| 4019 | + return $this->request; |
|
| 4020 | + } |
|
| 4021 | + |
|
| 4022 | + |
|
| 4023 | + /** |
|
| 4024 | + * just returns the _req_data property |
|
| 4025 | + * |
|
| 4026 | + * @return array |
|
| 4027 | + */ |
|
| 4028 | + public function get_request_data() |
|
| 4029 | + { |
|
| 4030 | + return $this->request->requestParams(); |
|
| 4031 | + } |
|
| 4032 | + |
|
| 4033 | + |
|
| 4034 | + /** |
|
| 4035 | + * returns the _req_data protected property |
|
| 4036 | + * |
|
| 4037 | + * @return string |
|
| 4038 | + */ |
|
| 4039 | + public function get_req_action() |
|
| 4040 | + { |
|
| 4041 | + return $this->_req_action; |
|
| 4042 | + } |
|
| 4043 | + |
|
| 4044 | + |
|
| 4045 | + /** |
|
| 4046 | + * @return bool value of $_is_caf property |
|
| 4047 | + */ |
|
| 4048 | + public function is_caf() |
|
| 4049 | + { |
|
| 4050 | + return $this->_is_caf; |
|
| 4051 | + } |
|
| 4052 | + |
|
| 4053 | + |
|
| 4054 | + /** |
|
| 4055 | + * @return mixed |
|
| 4056 | + */ |
|
| 4057 | + public function default_espresso_metaboxes() |
|
| 4058 | + { |
|
| 4059 | + return $this->_default_espresso_metaboxes; |
|
| 4060 | + } |
|
| 4061 | + |
|
| 4062 | + |
|
| 4063 | + /** |
|
| 4064 | + * @return mixed |
|
| 4065 | + */ |
|
| 4066 | + public function admin_base_url() |
|
| 4067 | + { |
|
| 4068 | + return $this->_admin_base_url; |
|
| 4069 | + } |
|
| 4070 | + |
|
| 4071 | + |
|
| 4072 | + /** |
|
| 4073 | + * @return mixed |
|
| 4074 | + */ |
|
| 4075 | + public function wp_page_slug() |
|
| 4076 | + { |
|
| 4077 | + return $this->_wp_page_slug; |
|
| 4078 | + } |
|
| 4079 | + |
|
| 4080 | + |
|
| 4081 | + /** |
|
| 4082 | + * updates espresso configuration settings |
|
| 4083 | + * |
|
| 4084 | + * @param string $tab |
|
| 4085 | + * @param EE_Config_Base|EE_Config $config |
|
| 4086 | + * @param string $file file where error occurred |
|
| 4087 | + * @param string $func function where error occurred |
|
| 4088 | + * @param string $line line no where error occurred |
|
| 4089 | + * @return boolean |
|
| 4090 | + */ |
|
| 4091 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4092 | + { |
|
| 4093 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 4094 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 4095 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4096 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4097 | + update_option('ee_ueip_has_notified', true); |
|
| 4098 | + } |
|
| 4099 | + // and save it (note we're also doing the network save here) |
|
| 4100 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4101 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4102 | + if ($config_saved && $net_saved) { |
|
| 4103 | + EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4104 | + return true; |
|
| 4105 | + } |
|
| 4106 | + EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4107 | + return false; |
|
| 4108 | + } |
|
| 4109 | + |
|
| 4110 | + |
|
| 4111 | + /** |
|
| 4112 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4113 | + * |
|
| 4114 | + * @return array |
|
| 4115 | + */ |
|
| 4116 | + public function get_yes_no_values() |
|
| 4117 | + { |
|
| 4118 | + return $this->_yes_no_values; |
|
| 4119 | + } |
|
| 4120 | + |
|
| 4121 | + |
|
| 4122 | + protected function _get_dir() |
|
| 4123 | + { |
|
| 4124 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 4125 | + return dirname($reflector->getFileName()); |
|
| 4126 | + } |
|
| 4127 | + |
|
| 4128 | + |
|
| 4129 | + /** |
|
| 4130 | + * A helper for getting a "next link". |
|
| 4131 | + * |
|
| 4132 | + * @param string $url The url to link to |
|
| 4133 | + * @param string $class The class to use. |
|
| 4134 | + * @return string |
|
| 4135 | + */ |
|
| 4136 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4137 | + { |
|
| 4138 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4139 | + } |
|
| 4140 | + |
|
| 4141 | + |
|
| 4142 | + /** |
|
| 4143 | + * A helper for getting a "previous link". |
|
| 4144 | + * |
|
| 4145 | + * @param string $url The url to link to |
|
| 4146 | + * @param string $class The class to use. |
|
| 4147 | + * @return string |
|
| 4148 | + */ |
|
| 4149 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4150 | + { |
|
| 4151 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4152 | + } |
|
| 4153 | + |
|
| 4154 | + |
|
| 4155 | + |
|
| 4156 | + |
|
| 4157 | + |
|
| 4158 | + |
|
| 4159 | + |
|
| 4160 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4161 | + |
|
| 4162 | + |
|
| 4163 | + /** |
|
| 4164 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4165 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
| 4166 | + * _req_data array. |
|
| 4167 | + * |
|
| 4168 | + * @return bool success/fail |
|
| 4169 | + * @throws EE_Error |
|
| 4170 | + * @throws InvalidArgumentException |
|
| 4171 | + * @throws ReflectionException |
|
| 4172 | + * @throws InvalidDataTypeException |
|
| 4173 | + * @throws InvalidInterfaceException |
|
| 4174 | + */ |
|
| 4175 | + protected function _process_resend_registration() |
|
| 4176 | + { |
|
| 4177 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4178 | + do_action( |
|
| 4179 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4180 | + $this->_template_args['success'], |
|
| 4181 | + $this->request->requestParams() |
|
| 4182 | + ); |
|
| 4183 | + return $this->_template_args['success']; |
|
| 4184 | + } |
|
| 4185 | + |
|
| 4186 | + |
|
| 4187 | + /** |
|
| 4188 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4189 | + * |
|
| 4190 | + * @param EE_Payment $payment |
|
| 4191 | + * @return bool success/fail |
|
| 4192 | + */ |
|
| 4193 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4194 | + { |
|
| 4195 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4196 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4197 | + $this->_template_args['success'] = apply_filters( |
|
| 4198 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4199 | + false, |
|
| 4200 | + $payment |
|
| 4201 | + ); |
|
| 4202 | + return $this->_template_args['success']; |
|
| 4203 | + } |
|
| 4204 | 4204 | } |