@@ -16,2894 +16,2894 @@ |
||
| 16 | 16 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This will hold the event object for event_details screen. |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @var EE_Event $_event |
|
| 24 | - */ |
|
| 25 | - protected $_event; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * This will hold the category object for category_details screen. |
|
| 30 | - * |
|
| 31 | - * @var stdClass $_category |
|
| 32 | - */ |
|
| 33 | - protected $_category; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * This will hold the event model instance |
|
| 38 | - * |
|
| 39 | - * @var EEM_Event $_event_model |
|
| 40 | - */ |
|
| 41 | - protected $_event_model; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var EE_Event |
|
| 46 | - */ |
|
| 47 | - protected $_cpt_model_obj = false; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var NodeGroupDao |
|
| 52 | - */ |
|
| 53 | - protected $model_obj_node_group_persister; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Initialize page props for this admin page group. |
|
| 58 | - */ |
|
| 59 | - protected function _init_page_props() |
|
| 60 | - { |
|
| 61 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 62 | - $this->page_label = EVENTS_LABEL; |
|
| 63 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 64 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 65 | - $this->_cpt_model_names = [ |
|
| 66 | - 'create_new' => 'EEM_Event', |
|
| 67 | - 'edit' => 'EEM_Event', |
|
| 68 | - ]; |
|
| 69 | - $this->_cpt_edit_routes = [ |
|
| 70 | - 'espresso_events' => 'edit', |
|
| 71 | - ]; |
|
| 72 | - add_action( |
|
| 73 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 74 | - [$this, 'verify_event_edit'], |
|
| 75 | - 10, |
|
| 76 | - 2 |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Sets the ajax hooks used for this admin page group. |
|
| 83 | - */ |
|
| 84 | - protected function _ajax_hooks() |
|
| 85 | - { |
|
| 86 | - add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Sets the page properties for this admin page group. |
|
| 92 | - */ |
|
| 93 | - protected function _define_page_props() |
|
| 94 | - { |
|
| 95 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 96 | - $this->_labels = [ |
|
| 97 | - 'buttons' => [ |
|
| 98 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 99 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 100 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 101 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 102 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 103 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 104 | - ], |
|
| 105 | - 'editor_title' => [ |
|
| 106 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 107 | - ], |
|
| 108 | - 'publishbox' => [ |
|
| 109 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 110 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 111 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 112 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 113 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 114 | - ], |
|
| 115 | - ]; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Sets the page routes property for this admin page group. |
|
| 121 | - */ |
|
| 122 | - protected function _set_page_routes() |
|
| 123 | - { |
|
| 124 | - // load formatter helper |
|
| 125 | - // load field generator helper |
|
| 126 | - // is there a evt_id in the request? |
|
| 127 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 128 | - ? $this->_req_data['EVT_ID'] |
|
| 129 | - : 0; |
|
| 130 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 131 | - $this->_page_routes = [ |
|
| 132 | - 'default' => [ |
|
| 133 | - 'func' => '_events_overview_list_table', |
|
| 134 | - 'capability' => 'ee_read_events', |
|
| 135 | - ], |
|
| 136 | - 'create_new' => [ |
|
| 137 | - 'func' => '_create_new_cpt_item', |
|
| 138 | - 'capability' => 'ee_edit_events', |
|
| 139 | - ], |
|
| 140 | - 'edit' => [ |
|
| 141 | - 'func' => '_edit_cpt_item', |
|
| 142 | - 'capability' => 'ee_edit_event', |
|
| 143 | - 'obj_id' => $evt_id, |
|
| 144 | - ], |
|
| 145 | - 'copy_event' => [ |
|
| 146 | - 'func' => '_copy_events', |
|
| 147 | - 'capability' => 'ee_edit_event', |
|
| 148 | - 'obj_id' => $evt_id, |
|
| 149 | - 'noheader' => true, |
|
| 150 | - ], |
|
| 151 | - 'trash_event' => [ |
|
| 152 | - 'func' => '_trash_or_restore_event', |
|
| 153 | - 'args' => ['event_status' => 'trash'], |
|
| 154 | - 'capability' => 'ee_delete_event', |
|
| 155 | - 'obj_id' => $evt_id, |
|
| 156 | - 'noheader' => true, |
|
| 157 | - ], |
|
| 158 | - 'trash_events' => [ |
|
| 159 | - 'func' => '_trash_or_restore_events', |
|
| 160 | - 'args' => ['event_status' => 'trash'], |
|
| 161 | - 'capability' => 'ee_delete_events', |
|
| 162 | - 'noheader' => true, |
|
| 163 | - ], |
|
| 164 | - 'restore_event' => [ |
|
| 165 | - 'func' => '_trash_or_restore_event', |
|
| 166 | - 'args' => ['event_status' => 'draft'], |
|
| 167 | - 'capability' => 'ee_delete_event', |
|
| 168 | - 'obj_id' => $evt_id, |
|
| 169 | - 'noheader' => true, |
|
| 170 | - ], |
|
| 171 | - 'restore_events' => [ |
|
| 172 | - 'func' => '_trash_or_restore_events', |
|
| 173 | - 'args' => ['event_status' => 'draft'], |
|
| 174 | - 'capability' => 'ee_delete_events', |
|
| 175 | - 'noheader' => true, |
|
| 176 | - ], |
|
| 177 | - 'delete_event' => [ |
|
| 178 | - 'func' => '_delete_event', |
|
| 179 | - 'capability' => 'ee_delete_event', |
|
| 180 | - 'obj_id' => $evt_id, |
|
| 181 | - 'noheader' => true, |
|
| 182 | - ], |
|
| 183 | - 'delete_events' => [ |
|
| 184 | - 'func' => '_delete_events', |
|
| 185 | - 'capability' => 'ee_delete_events', |
|
| 186 | - 'noheader' => true, |
|
| 187 | - ], |
|
| 188 | - 'view_report' => [ |
|
| 189 | - 'func' => '_view_report', |
|
| 190 | - 'capability' => 'ee_edit_events', |
|
| 191 | - ], |
|
| 192 | - 'default_event_settings' => [ |
|
| 193 | - 'func' => '_default_event_settings', |
|
| 194 | - 'capability' => 'manage_options', |
|
| 195 | - ], |
|
| 196 | - 'update_default_event_settings' => [ |
|
| 197 | - 'func' => '_update_default_event_settings', |
|
| 198 | - 'capability' => 'manage_options', |
|
| 199 | - 'noheader' => true, |
|
| 200 | - ], |
|
| 201 | - 'template_settings' => [ |
|
| 202 | - 'func' => '_template_settings', |
|
| 203 | - 'capability' => 'manage_options', |
|
| 204 | - ], |
|
| 205 | - // event category tab related |
|
| 206 | - 'add_category' => [ |
|
| 207 | - 'func' => '_category_details', |
|
| 208 | - 'capability' => 'ee_edit_event_category', |
|
| 209 | - 'args' => ['add'], |
|
| 210 | - ], |
|
| 211 | - 'edit_category' => [ |
|
| 212 | - 'func' => '_category_details', |
|
| 213 | - 'capability' => 'ee_edit_event_category', |
|
| 214 | - 'args' => ['edit'], |
|
| 215 | - ], |
|
| 216 | - 'delete_categories' => [ |
|
| 217 | - 'func' => '_delete_categories', |
|
| 218 | - 'capability' => 'ee_delete_event_category', |
|
| 219 | - 'noheader' => true, |
|
| 220 | - ], |
|
| 221 | - 'delete_category' => [ |
|
| 222 | - 'func' => '_delete_categories', |
|
| 223 | - 'capability' => 'ee_delete_event_category', |
|
| 224 | - 'noheader' => true, |
|
| 225 | - ], |
|
| 226 | - 'insert_category' => [ |
|
| 227 | - 'func' => '_insert_or_update_category', |
|
| 228 | - 'args' => ['new_category' => true], |
|
| 229 | - 'capability' => 'ee_edit_event_category', |
|
| 230 | - 'noheader' => true, |
|
| 231 | - ], |
|
| 232 | - 'update_category' => [ |
|
| 233 | - 'func' => '_insert_or_update_category', |
|
| 234 | - 'args' => ['new_category' => false], |
|
| 235 | - 'capability' => 'ee_edit_event_category', |
|
| 236 | - 'noheader' => true, |
|
| 237 | - ], |
|
| 238 | - 'category_list' => [ |
|
| 239 | - 'func' => '_category_list_table', |
|
| 240 | - 'capability' => 'ee_manage_event_categories', |
|
| 241 | - ], |
|
| 242 | - 'preview_deletion' => [ |
|
| 243 | - 'func' => 'previewDeletion', |
|
| 244 | - 'capability' => 'ee_delete_events', |
|
| 245 | - ], |
|
| 246 | - 'confirm_deletion' => [ |
|
| 247 | - 'func' => 'confirmDeletion', |
|
| 248 | - 'capability' => 'ee_delete_events', |
|
| 249 | - 'noheader' => true, |
|
| 250 | - ], |
|
| 251 | - ]; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Set the _page_config property for this admin page group. |
|
| 257 | - */ |
|
| 258 | - protected function _set_page_config() |
|
| 259 | - { |
|
| 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' => [ |
|
| 291 | - // 'Event_Overview_Help_Tour', |
|
| 292 | - // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 293 | - // ], |
|
| 294 | - 'require_nonce' => false, |
|
| 295 | - 'qtips' => ['EE_Event_List_Table_Tips'], |
|
| 296 | - ], |
|
| 297 | - 'create_new' => [ |
|
| 298 | - 'nav' => [ |
|
| 299 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 300 | - 'order' => 5, |
|
| 301 | - 'persistent' => false, |
|
| 302 | - ], |
|
| 303 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 304 | - 'help_tabs' => [ |
|
| 305 | - 'event_editor_help_tab' => [ |
|
| 306 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 307 | - 'filename' => 'event_editor', |
|
| 308 | - ], |
|
| 309 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 310 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 311 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 312 | - ], |
|
| 313 | - 'event_editor_venue_details_help_tab' => [ |
|
| 314 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 315 | - 'filename' => 'event_editor_venue_details', |
|
| 316 | - ], |
|
| 317 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 318 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 319 | - 'filename' => 'event_editor_event_datetimes', |
|
| 320 | - ], |
|
| 321 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 322 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 323 | - 'filename' => 'event_editor_event_tickets', |
|
| 324 | - ], |
|
| 325 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 326 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 327 | - 'filename' => 'event_editor_event_registration_options', |
|
| 328 | - ], |
|
| 329 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 330 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 331 | - 'filename' => 'event_editor_tags_categories', |
|
| 332 | - ], |
|
| 333 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 334 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 335 | - 'filename' => 'event_editor_questions_registrants', |
|
| 336 | - ], |
|
| 337 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 338 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 339 | - 'filename' => 'event_editor_save_new_event', |
|
| 340 | - ], |
|
| 341 | - 'event_editor_other_help_tab' => [ |
|
| 342 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 343 | - 'filename' => 'event_editor_other', |
|
| 344 | - ], |
|
| 345 | - ], |
|
| 346 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 347 | - // 'help_tour' => [ |
|
| 348 | - // 'Event_Editor_Help_Tour', |
|
| 349 | - // ], |
|
| 350 | - 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 351 | - 'require_nonce' => false, |
|
| 352 | - ], |
|
| 353 | - 'edit' => [ |
|
| 354 | - 'nav' => [ |
|
| 355 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 356 | - 'order' => 5, |
|
| 357 | - 'persistent' => false, |
|
| 358 | - 'url' => isset($this->_req_data['post']) |
|
| 359 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 360 | - ['post' => $this->_req_data['post'], 'action' => 'edit'], |
|
| 361 | - $this->_current_page_view_url |
|
| 362 | - ) |
|
| 363 | - : $this->_admin_base_url, |
|
| 364 | - ], |
|
| 365 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 366 | - 'help_tabs' => [ |
|
| 367 | - 'event_editor_help_tab' => [ |
|
| 368 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 369 | - 'filename' => 'event_editor', |
|
| 370 | - ], |
|
| 371 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 372 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 373 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 374 | - ], |
|
| 375 | - 'event_editor_venue_details_help_tab' => [ |
|
| 376 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 377 | - 'filename' => 'event_editor_venue_details', |
|
| 378 | - ], |
|
| 379 | - 'event_editor_event_datetimes_help_tab' => [ |
|
| 380 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 381 | - 'filename' => 'event_editor_event_datetimes', |
|
| 382 | - ], |
|
| 383 | - 'event_editor_event_tickets_help_tab' => [ |
|
| 384 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 385 | - 'filename' => 'event_editor_event_tickets', |
|
| 386 | - ], |
|
| 387 | - 'event_editor_event_registration_options_help_tab' => [ |
|
| 388 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 389 | - 'filename' => 'event_editor_event_registration_options', |
|
| 390 | - ], |
|
| 391 | - 'event_editor_tags_categories_help_tab' => [ |
|
| 392 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 393 | - 'filename' => 'event_editor_tags_categories', |
|
| 394 | - ], |
|
| 395 | - 'event_editor_questions_registrants_help_tab' => [ |
|
| 396 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 397 | - 'filename' => 'event_editor_questions_registrants', |
|
| 398 | - ], |
|
| 399 | - 'event_editor_save_new_event_help_tab' => [ |
|
| 400 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 401 | - 'filename' => 'event_editor_save_new_event', |
|
| 402 | - ], |
|
| 403 | - 'event_editor_other_help_tab' => [ |
|
| 404 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 405 | - 'filename' => 'event_editor_other', |
|
| 406 | - ], |
|
| 407 | - ], |
|
| 408 | - 'require_nonce' => false, |
|
| 409 | - ], |
|
| 410 | - 'default_event_settings' => [ |
|
| 411 | - 'nav' => [ |
|
| 412 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 413 | - 'order' => 40, |
|
| 414 | - ], |
|
| 415 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 416 | - 'labels' => [ |
|
| 417 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 418 | - ], |
|
| 419 | - 'help_tabs' => [ |
|
| 420 | - 'default_settings_help_tab' => [ |
|
| 421 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 422 | - 'filename' => 'events_default_settings', |
|
| 423 | - ], |
|
| 424 | - 'default_settings_status_help_tab' => [ |
|
| 425 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 426 | - 'filename' => 'events_default_settings_status', |
|
| 427 | - ], |
|
| 428 | - 'default_maximum_tickets_help_tab' => [ |
|
| 429 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 430 | - 'filename' => 'events_default_settings_max_tickets', |
|
| 431 | - ], |
|
| 432 | - ], |
|
| 433 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 434 | - // 'help_tour' => ['Event_Default_Settings_Help_Tour'], |
|
| 435 | - 'require_nonce' => false, |
|
| 436 | - ], |
|
| 437 | - // template settings |
|
| 438 | - 'template_settings' => [ |
|
| 439 | - 'nav' => [ |
|
| 440 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 441 | - 'order' => 30, |
|
| 442 | - ], |
|
| 443 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 444 | - 'help_tabs' => [ |
|
| 445 | - 'general_settings_templates_help_tab' => [ |
|
| 446 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 447 | - 'filename' => 'general_settings_templates', |
|
| 448 | - ], |
|
| 449 | - ], |
|
| 450 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 451 | - // 'help_tour' => ['Templates_Help_Tour'], |
|
| 452 | - 'require_nonce' => false, |
|
| 453 | - ], |
|
| 454 | - // event category stuff |
|
| 455 | - 'add_category' => [ |
|
| 456 | - 'nav' => [ |
|
| 457 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 458 | - 'order' => 15, |
|
| 459 | - 'persistent' => false, |
|
| 460 | - ], |
|
| 461 | - 'help_tabs' => [ |
|
| 462 | - 'add_category_help_tab' => [ |
|
| 463 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 464 | - 'filename' => 'events_add_category', |
|
| 465 | - ], |
|
| 466 | - ], |
|
| 467 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 468 | - // 'help_tour' => ['Event_Add_Category_Help_Tour'], |
|
| 469 | - 'metaboxes' => ['_publish_post_box'], |
|
| 470 | - 'require_nonce' => false, |
|
| 471 | - ], |
|
| 472 | - 'edit_category' => [ |
|
| 473 | - 'nav' => [ |
|
| 474 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 475 | - 'order' => 15, |
|
| 476 | - 'persistent' => false, |
|
| 477 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 478 | - ? add_query_arg( |
|
| 479 | - ['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']], |
|
| 480 | - $this->_current_page_view_url |
|
| 481 | - ) |
|
| 482 | - : $this->_admin_base_url, |
|
| 483 | - ], |
|
| 484 | - 'help_tabs' => [ |
|
| 485 | - 'edit_category_help_tab' => [ |
|
| 486 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 487 | - 'filename' => 'events_edit_category', |
|
| 488 | - ], |
|
| 489 | - ], |
|
| 490 | - /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/ |
|
| 491 | - 'metaboxes' => ['_publish_post_box'], |
|
| 492 | - 'require_nonce' => false, |
|
| 493 | - ], |
|
| 494 | - 'category_list' => [ |
|
| 495 | - 'nav' => [ |
|
| 496 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 497 | - 'order' => 20, |
|
| 498 | - ], |
|
| 499 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 500 | - 'help_tabs' => [ |
|
| 501 | - 'events_categories_help_tab' => [ |
|
| 502 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 503 | - 'filename' => 'events_categories', |
|
| 504 | - ], |
|
| 505 | - 'events_categories_table_column_headings_help_tab' => [ |
|
| 506 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 507 | - 'filename' => 'events_categories_table_column_headings', |
|
| 508 | - ], |
|
| 509 | - 'events_categories_view_help_tab' => [ |
|
| 510 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 511 | - 'filename' => 'events_categories_views', |
|
| 512 | - ], |
|
| 513 | - 'events_categories_other_help_tab' => [ |
|
| 514 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 515 | - 'filename' => 'events_categories_other', |
|
| 516 | - ], |
|
| 517 | - ], |
|
| 518 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 519 | - // 'help_tour' => [ |
|
| 520 | - // 'Event_Categories_Help_Tour', |
|
| 521 | - // ], |
|
| 522 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 523 | - 'require_nonce' => false, |
|
| 524 | - ], |
|
| 525 | - 'preview_deletion' => [ |
|
| 526 | - 'nav' => [ |
|
| 527 | - 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 528 | - 'order' => 15, |
|
| 529 | - 'persistent' => false, |
|
| 530 | - 'url' => '', |
|
| 531 | - ], |
|
| 532 | - 'require_nonce' => false, |
|
| 533 | - ], |
|
| 534 | - ]; |
|
| 535 | - // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated |
|
| 536 | - $domain = $this->loader->getShared('EventEspresso\core\domain\Domain'); |
|
| 537 | - if (! $domain->isCaffeinated()) { |
|
| 538 | - $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
|
| 539 | - $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 546 | - */ |
|
| 547 | - protected function _add_screen_options() |
|
| 548 | - { |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Implementing the screen options for the 'default' route. |
|
| 554 | - * |
|
| 555 | - * @throws InvalidArgumentException |
|
| 556 | - * @throws InvalidDataTypeException |
|
| 557 | - * @throws InvalidInterfaceException |
|
| 558 | - */ |
|
| 559 | - protected function _add_screen_options_default() |
|
| 560 | - { |
|
| 561 | - $this->_per_page_screen_option(); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Implementing screen options for the category list route. |
|
| 567 | - * |
|
| 568 | - * @throws InvalidArgumentException |
|
| 569 | - * @throws InvalidDataTypeException |
|
| 570 | - * @throws InvalidInterfaceException |
|
| 571 | - */ |
|
| 572 | - protected function _add_screen_options_category_list() |
|
| 573 | - { |
|
| 574 | - $page_title = $this->_admin_page_title; |
|
| 575 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 576 | - $this->_per_page_screen_option(); |
|
| 577 | - $this->_admin_page_title = $page_title; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Used to register any global feature pointers for the admin page group. |
|
| 583 | - */ |
|
| 584 | - protected function _add_feature_pointers() |
|
| 585 | - { |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 591 | - */ |
|
| 592 | - public function load_scripts_styles() |
|
| 593 | - { |
|
| 594 | - wp_register_style( |
|
| 595 | - 'events-admin-css', |
|
| 596 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 597 | - [], |
|
| 598 | - EVENT_ESPRESSO_VERSION |
|
| 599 | - ); |
|
| 600 | - wp_register_style( |
|
| 601 | - 'ee-cat-admin', |
|
| 602 | - EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 603 | - [], |
|
| 604 | - EVENT_ESPRESSO_VERSION |
|
| 605 | - ); |
|
| 606 | - wp_enqueue_style('events-admin-css'); |
|
| 607 | - wp_enqueue_style('ee-cat-admin'); |
|
| 608 | - // scripts |
|
| 609 | - wp_register_script( |
|
| 610 | - 'event_editor_js', |
|
| 611 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 612 | - ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 613 | - EVENT_ESPRESSO_VERSION, |
|
| 614 | - true |
|
| 615 | - ); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Enqueuing scripts and styles specific to this view |
|
| 621 | - */ |
|
| 622 | - public function load_scripts_styles_create_new() |
|
| 623 | - { |
|
| 624 | - $this->load_scripts_styles_edit(); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * Enqueuing scripts and styles specific to this view |
|
| 630 | - */ |
|
| 631 | - public function load_scripts_styles_edit() |
|
| 632 | - { |
|
| 633 | - // styles |
|
| 634 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 635 | - wp_register_style( |
|
| 636 | - 'event-editor-css', |
|
| 637 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 638 | - ['ee-admin-css'], |
|
| 639 | - EVENT_ESPRESSO_VERSION |
|
| 640 | - ); |
|
| 641 | - wp_enqueue_style('event-editor-css'); |
|
| 642 | - // scripts |
|
| 643 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 644 | - wp_register_script( |
|
| 645 | - 'event-datetime-metabox', |
|
| 646 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 647 | - ['event_editor_js', 'ee-datepicker'], |
|
| 648 | - EVENT_ESPRESSO_VERSION |
|
| 649 | - ); |
|
| 650 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * Populating the _views property for the category list table view. |
|
| 657 | - */ |
|
| 658 | - protected function _set_list_table_views_category_list() |
|
| 659 | - { |
|
| 660 | - $this->_views = [ |
|
| 661 | - 'all' => [ |
|
| 662 | - 'slug' => 'all', |
|
| 663 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 664 | - 'count' => 0, |
|
| 665 | - 'bulk_action' => [ |
|
| 666 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 667 | - ], |
|
| 668 | - ], |
|
| 669 | - ]; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 675 | - */ |
|
| 676 | - public function admin_init() |
|
| 677 | - { |
|
| 678 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 679 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 680 | - 'event_espresso' |
|
| 681 | - ); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 687 | - * group. |
|
| 688 | - */ |
|
| 689 | - public function admin_notices() |
|
| 690 | - { |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 696 | - * this admin page group. |
|
| 697 | - */ |
|
| 698 | - public function admin_footer_scripts() |
|
| 699 | - { |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 705 | - * warning (via EE_Error::add_error()); |
|
| 706 | - * |
|
| 707 | - * @param EE_Event $event Event object |
|
| 708 | - * @param string $req_type |
|
| 709 | - * @return void |
|
| 710 | - * @throws EE_Error |
|
| 711 | - * @access public |
|
| 712 | - */ |
|
| 713 | - public function verify_event_edit($event = null, $req_type = '') |
|
| 714 | - { |
|
| 715 | - // don't need to do this when processing |
|
| 716 | - if (! empty($req_type)) { |
|
| 717 | - return; |
|
| 718 | - } |
|
| 719 | - // no event? |
|
| 720 | - if (! $event instanceof EE_Event) { |
|
| 721 | - $event = $this->_cpt_model_obj; |
|
| 722 | - } |
|
| 723 | - // STILL no event? |
|
| 724 | - if (! $event instanceof EE_Event) { |
|
| 725 | - return; |
|
| 726 | - } |
|
| 727 | - $orig_status = $event->status(); |
|
| 728 | - // first check if event is active. |
|
| 729 | - if ( |
|
| 730 | - $orig_status === EEM_Event::cancelled |
|
| 731 | - || $orig_status === EEM_Event::postponed |
|
| 732 | - || $event->is_expired() |
|
| 733 | - || $event->is_inactive() |
|
| 734 | - ) { |
|
| 735 | - return; |
|
| 736 | - } |
|
| 737 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
| 738 | - if ($event->is_sold_out(true)) { |
|
| 739 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 740 | - EE_Error::add_attention( |
|
| 741 | - sprintf( |
|
| 742 | - esc_html__( |
|
| 743 | - '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.', |
|
| 744 | - 'event_espresso' |
|
| 745 | - ), |
|
| 746 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 747 | - ) |
|
| 748 | - ); |
|
| 749 | - } |
|
| 750 | - return; |
|
| 751 | - } |
|
| 752 | - if ($orig_status === EEM_Event::sold_out) { |
|
| 753 | - EE_Error::add_attention( |
|
| 754 | - sprintf( |
|
| 755 | - esc_html__( |
|
| 756 | - '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.', |
|
| 757 | - 'event_espresso' |
|
| 758 | - ), |
|
| 759 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 760 | - ) |
|
| 761 | - ); |
|
| 762 | - } |
|
| 763 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 764 | - if (! $event->tickets_on_sale()) { |
|
| 765 | - return; |
|
| 766 | - } |
|
| 767 | - // made it here so show warning |
|
| 768 | - $this->_edit_event_warning(); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 774 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 775 | - * |
|
| 776 | - * @access protected |
|
| 777 | - * @return void |
|
| 778 | - */ |
|
| 779 | - protected function _edit_event_warning() |
|
| 780 | - { |
|
| 781 | - // we don't want to add warnings during these requests |
|
| 782 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 783 | - return; |
|
| 784 | - } |
|
| 785 | - EE_Error::add_attention( |
|
| 786 | - sprintf( |
|
| 787 | - esc_html__( |
|
| 788 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 789 | - 'event_espresso' |
|
| 790 | - ), |
|
| 791 | - '<a class="espresso-help-tab-lnk">', |
|
| 792 | - '</a>' |
|
| 793 | - ) |
|
| 794 | - ); |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 800 | - * Otherwise, do the normal logic |
|
| 801 | - * |
|
| 802 | - * @return void |
|
| 803 | - * @throws EE_Error |
|
| 804 | - * @throws InvalidArgumentException |
|
| 805 | - * @throws InvalidDataTypeException |
|
| 806 | - * @throws InvalidInterfaceException |
|
| 807 | - */ |
|
| 808 | - protected function _create_new_cpt_item() |
|
| 809 | - { |
|
| 810 | - $has_timezone_string = get_option('timezone_string'); |
|
| 811 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 812 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 813 | - EE_Error::add_attention( |
|
| 814 | - sprintf( |
|
| 815 | - __( |
|
| 816 | - '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', |
|
| 817 | - 'event_espresso' |
|
| 818 | - ), |
|
| 819 | - '<br>', |
|
| 820 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 821 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 822 | - . '</select>', |
|
| 823 | - '<button class="button button-secondary timezone-submit">', |
|
| 824 | - '</button><span class="spinner"></span>' |
|
| 825 | - ), |
|
| 826 | - __FILE__, |
|
| 827 | - __FUNCTION__, |
|
| 828 | - __LINE__ |
|
| 829 | - ); |
|
| 830 | - } |
|
| 831 | - parent::_create_new_cpt_item(); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * Sets the _views property for the default route in this admin page group. |
|
| 837 | - */ |
|
| 838 | - protected function _set_list_table_views_default() |
|
| 839 | - { |
|
| 840 | - $this->_views = [ |
|
| 841 | - 'all' => [ |
|
| 842 | - 'slug' => 'all', |
|
| 843 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 844 | - 'count' => 0, |
|
| 845 | - 'bulk_action' => [ |
|
| 846 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 847 | - ], |
|
| 848 | - ], |
|
| 849 | - 'draft' => [ |
|
| 850 | - 'slug' => 'draft', |
|
| 851 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 852 | - 'count' => 0, |
|
| 853 | - 'bulk_action' => [ |
|
| 854 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 855 | - ], |
|
| 856 | - ], |
|
| 857 | - ]; |
|
| 858 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 859 | - $this->_views['trash'] = [ |
|
| 860 | - 'slug' => 'trash', |
|
| 861 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 862 | - 'count' => 0, |
|
| 863 | - 'bulk_action' => [ |
|
| 864 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 865 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 866 | - ], |
|
| 867 | - ]; |
|
| 868 | - } |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * Provides the legend item array for the default list table view. |
|
| 874 | - * |
|
| 875 | - * @return array |
|
| 876 | - */ |
|
| 877 | - protected function _event_legend_items() |
|
| 878 | - { |
|
| 879 | - $items = [ |
|
| 880 | - 'view_details' => [ |
|
| 881 | - 'class' => 'dashicons dashicons-search', |
|
| 882 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 883 | - ], |
|
| 884 | - 'edit_event' => [ |
|
| 885 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 886 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 887 | - ], |
|
| 888 | - 'view_attendees' => [ |
|
| 889 | - 'class' => 'dashicons dashicons-groups', |
|
| 890 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 891 | - ], |
|
| 892 | - ]; |
|
| 893 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 894 | - $statuses = [ |
|
| 895 | - 'sold_out_status' => [ |
|
| 896 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 897 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 898 | - ], |
|
| 899 | - 'active_status' => [ |
|
| 900 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 901 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 902 | - ], |
|
| 903 | - 'upcoming_status' => [ |
|
| 904 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 905 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 906 | - ], |
|
| 907 | - 'postponed_status' => [ |
|
| 908 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 909 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 910 | - ], |
|
| 911 | - 'cancelled_status' => [ |
|
| 912 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 913 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 914 | - ], |
|
| 915 | - 'expired_status' => [ |
|
| 916 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 917 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 918 | - ], |
|
| 919 | - 'inactive_status' => [ |
|
| 920 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 921 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 922 | - ], |
|
| 923 | - ]; |
|
| 924 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 925 | - return array_merge($items, $statuses); |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - /** |
|
| 930 | - * @return EEM_Event |
|
| 931 | - * @throws EE_Error |
|
| 932 | - * @throws InvalidArgumentException |
|
| 933 | - * @throws InvalidDataTypeException |
|
| 934 | - * @throws InvalidInterfaceException |
|
| 935 | - * @throws ReflectionException |
|
| 936 | - */ |
|
| 937 | - private function _event_model() |
|
| 938 | - { |
|
| 939 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 940 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 941 | - } |
|
| 942 | - return $this->_event_model; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 948 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 949 | - * |
|
| 950 | - * @param string $return the current html |
|
| 951 | - * @param int $id the post id for the page |
|
| 952 | - * @param string $new_title What the title is |
|
| 953 | - * @param string $new_slug what the slug is |
|
| 954 | - * @return string The new html string for the permalink area |
|
| 955 | - */ |
|
| 956 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 957 | - { |
|
| 958 | - // make sure this is only when editing |
|
| 959 | - if (! empty($id)) { |
|
| 960 | - $post = get_post($id); |
|
| 961 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 962 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 963 | - . '</a> '; |
|
| 964 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 965 | - . $post->ID |
|
| 966 | - . ']">'; |
|
| 967 | - } |
|
| 968 | - return $return; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - |
|
| 972 | - /** |
|
| 973 | - * _events_overview_list_table |
|
| 974 | - * This contains the logic for showing the events_overview list |
|
| 975 | - * |
|
| 976 | - * @access protected |
|
| 977 | - * @return void |
|
| 978 | - * @throws DomainException |
|
| 979 | - * @throws EE_Error |
|
| 980 | - * @throws InvalidArgumentException |
|
| 981 | - * @throws InvalidDataTypeException |
|
| 982 | - * @throws InvalidInterfaceException |
|
| 983 | - */ |
|
| 984 | - protected function _events_overview_list_table() |
|
| 985 | - { |
|
| 986 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 987 | - $after_list_table = []; |
|
| 988 | - $after_list_table['view_event_list_button'] = EEH_HTML::br(); |
|
| 989 | - $after_list_table['view_event_list_button'] .= EEH_Template::get_button_or_link( |
|
| 990 | - get_post_type_archive_link('espresso_events'), |
|
| 991 | - esc_html__('View Event Archive Page', 'event_espresso'), |
|
| 992 | - 'button' |
|
| 993 | - ); |
|
| 994 | - $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 995 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 996 | - 'create_new', |
|
| 997 | - 'add', |
|
| 998 | - [], |
|
| 999 | - 'add-new-h2' |
|
| 1000 | - ); |
|
| 1001 | - $this->_template_args['after_list_table'] = array_merge( |
|
| 1002 | - (array) $this->_template_args['after_list_table'], |
|
| 1003 | - $after_list_table |
|
| 1004 | - ); |
|
| 1005 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - |
|
| 1009 | - /** |
|
| 1010 | - * this allows for extra misc actions in the default WP publish box |
|
| 1011 | - * |
|
| 1012 | - * @return void |
|
| 1013 | - * @throws DomainException |
|
| 1014 | - * @throws EE_Error |
|
| 1015 | - * @throws InvalidArgumentException |
|
| 1016 | - * @throws InvalidDataTypeException |
|
| 1017 | - * @throws InvalidInterfaceException |
|
| 1018 | - * @throws ReflectionException |
|
| 1019 | - */ |
|
| 1020 | - public function extra_misc_actions_publish_box() |
|
| 1021 | - { |
|
| 1022 | - $this->_generate_publish_box_extra_content(); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1028 | - * saved. |
|
| 1029 | - * Typically you would use this to save any additional data. |
|
| 1030 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1031 | - * ALSO very important. When a post transitions from scheduled to published, |
|
| 1032 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1033 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1034 | - * |
|
| 1035 | - * @access protected |
|
| 1036 | - * @abstract |
|
| 1037 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1038 | - * @param object $post The post object of the cpt that was saved. |
|
| 1039 | - * @return void |
|
| 1040 | - * @throws EE_Error |
|
| 1041 | - * @throws InvalidArgumentException |
|
| 1042 | - * @throws InvalidDataTypeException |
|
| 1043 | - * @throws InvalidInterfaceException |
|
| 1044 | - * @throws ReflectionException |
|
| 1045 | - */ |
|
| 1046 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 1047 | - { |
|
| 1048 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1049 | - // get out we're not processing an event save. |
|
| 1050 | - return; |
|
| 1051 | - } |
|
| 1052 | - $event_values = [ |
|
| 1053 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 1054 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 1055 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 1056 | - ? sanitize_text_field($this->_req_data['timezone_string']) |
|
| 1057 | - : null, |
|
| 1058 | - ]; |
|
| 1059 | - // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
| 1060 | - if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1061 | - $event_values['EVT_display_ticket_selector'] = |
|
| 1062 | - ! empty($this->_req_data['display_ticket_selector']) |
|
| 1063 | - ? 1 |
|
| 1064 | - : 0; |
|
| 1065 | - $event_values['EVT_additional_limit'] = min( |
|
| 1066 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1067 | - ! empty($this->_req_data['additional_limit']) |
|
| 1068 | - ? absint($this->_req_data['additional_limit']) |
|
| 1069 | - : null |
|
| 1070 | - ); |
|
| 1071 | - $event_values['EVT_default_registration_status'] = |
|
| 1072 | - ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 1073 | - ? sanitize_text_field($this->_req_data['EVT_default_registration_status']) |
|
| 1074 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 1075 | - $event_values['EVT_external_URL'] = ! empty($this->_req_data['externalURL']) |
|
| 1076 | - ? esc_url_raw($this->_req_data['externalURL']) |
|
| 1077 | - : null; |
|
| 1078 | - $event_values['EVT_phone'] = ! empty($this->_req_data['event_phone']) |
|
| 1079 | - ? sanitize_text_field($this->_req_data['event_phone']) |
|
| 1080 | - : null; |
|
| 1081 | - } |
|
| 1082 | - // update event |
|
| 1083 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1084 | - // get event_object for other metaboxes... |
|
| 1085 | - // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
| 1086 | - // i have to setup where conditions to override the filters in the model that filter out autodraft |
|
| 1087 | - // and inherit statuses so we GET the inherit id! |
|
| 1088 | - $get_one_where = [ |
|
| 1089 | - $this->_event_model()->primary_key_name() => $post_id, |
|
| 1090 | - 'OR' => [ |
|
| 1091 | - 'status' => $post->post_status, |
|
| 1092 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1093 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1094 | - 'status*1' => $this->_req_data['original_post_status'], |
|
| 1095 | - ], |
|
| 1096 | - ]; |
|
| 1097 | - $event = $this->_event_model()->get_one([$get_one_where]); |
|
| 1098 | - // the following are default callbacks for event attachment updates |
|
| 1099 | - // that can be overridden by caffeinated functionality and/or addons. |
|
| 1100 | - $event_update_callbacks = apply_filters( |
|
| 1101 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1102 | - [ |
|
| 1103 | - [$this, '_default_venue_update'], |
|
| 1104 | - [$this, '_default_tickets_update'], |
|
| 1105 | - ] |
|
| 1106 | - ); |
|
| 1107 | - $att_success = true; |
|
| 1108 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 1109 | - $_success = is_callable($e_callback) |
|
| 1110 | - ? $e_callback($event, $this->_req_data) |
|
| 1111 | - : false; |
|
| 1112 | - // if ANY of these updates fail then we want the appropriate global error message |
|
| 1113 | - $att_success = ! $att_success ? $att_success : $_success; |
|
| 1114 | - } |
|
| 1115 | - // any errors? |
|
| 1116 | - if ($success && false === $att_success) { |
|
| 1117 | - EE_Error::add_error( |
|
| 1118 | - esc_html__( |
|
| 1119 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1120 | - 'event_espresso' |
|
| 1121 | - ), |
|
| 1122 | - __FILE__, |
|
| 1123 | - __FUNCTION__, |
|
| 1124 | - __LINE__ |
|
| 1125 | - ); |
|
| 1126 | - } elseif ($success === false) { |
|
| 1127 | - EE_Error::add_error( |
|
| 1128 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1129 | - __FILE__, |
|
| 1130 | - __FUNCTION__, |
|
| 1131 | - __LINE__ |
|
| 1132 | - ); |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * @param int $post_id |
|
| 1139 | - * @param int $revision_id |
|
| 1140 | - * @throws EE_Error |
|
| 1141 | - * @throws InvalidArgumentException |
|
| 1142 | - * @throws InvalidDataTypeException |
|
| 1143 | - * @throws InvalidInterfaceException |
|
| 1144 | - * @throws ReflectionException |
|
| 1145 | - * @see parent::restore_item() |
|
| 1146 | - */ |
|
| 1147 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1148 | - { |
|
| 1149 | - // copy existing event meta to new post |
|
| 1150 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1151 | - if ($post_evt instanceof EE_Event) { |
|
| 1152 | - // meta revision restore |
|
| 1153 | - $post_evt->restore_revision($revision_id); |
|
| 1154 | - // related objs restore |
|
| 1155 | - $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - |
|
| 1160 | - /** |
|
| 1161 | - * Attach the venue to the Event |
|
| 1162 | - * |
|
| 1163 | - * @param EE_Event $evtobj Event Object to add the venue to |
|
| 1164 | - * @param array $data The request data from the form |
|
| 1165 | - * @return bool Success or fail. |
|
| 1166 | - * @throws EE_Error |
|
| 1167 | - * @throws InvalidArgumentException |
|
| 1168 | - * @throws InvalidDataTypeException |
|
| 1169 | - * @throws InvalidInterfaceException |
|
| 1170 | - * @throws ReflectionException |
|
| 1171 | - */ |
|
| 1172 | - protected function _default_venue_update(EE_Event $evtobj, $data) |
|
| 1173 | - { |
|
| 1174 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1175 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1176 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1177 | - // very important. If we don't have a venue name... |
|
| 1178 | - // then we'll get out because not necessary to create empty venue |
|
| 1179 | - if (empty($data['venue_title'])) { |
|
| 1180 | - return false; |
|
| 1181 | - } |
|
| 1182 | - $venue_array = [ |
|
| 1183 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1184 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1185 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1186 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1187 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1188 | - : null, |
|
| 1189 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1190 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1191 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1192 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1193 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1194 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1195 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1196 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1197 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1198 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1199 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1200 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1201 | - 'status' => 'publish', |
|
| 1202 | - ]; |
|
| 1203 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1204 | - if (! empty($venue_id)) { |
|
| 1205 | - $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1206 | - $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1207 | - // we've gotta make sure that the venue is always attached to a revision.. |
|
| 1208 | - // add_relation_to should take care of making sure that the relation is already present. |
|
| 1209 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1210 | - return $rows_affected > 0; |
|
| 1211 | - } |
|
| 1212 | - // we insert the venue |
|
| 1213 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1214 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1215 | - return ! empty($venue_id); |
|
| 1216 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - |
|
| 1220 | - /** |
|
| 1221 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1222 | - * |
|
| 1223 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1224 | - * @param array $data The request data from the form |
|
| 1225 | - * @return array |
|
| 1226 | - * @throws EE_Error |
|
| 1227 | - * @throws InvalidArgumentException |
|
| 1228 | - * @throws InvalidDataTypeException |
|
| 1229 | - * @throws InvalidInterfaceException |
|
| 1230 | - * @throws ReflectionException |
|
| 1231 | - * @throws Exception |
|
| 1232 | - */ |
|
| 1233 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1234 | - { |
|
| 1235 | - if ($this->admin_config->useAdvancedEditor()) { |
|
| 1236 | - return []; |
|
| 1237 | - } |
|
| 1238 | - $success = true; |
|
| 1239 | - $saved_dtt = null; |
|
| 1240 | - $saved_tickets = []; |
|
| 1241 | - $incoming_date_formats = ['Y-m-d', 'h:i a']; |
|
| 1242 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1243 | - // trim all values to ensure any excess whitespace is removed. |
|
| 1244 | - $dtt = array_map('trim', $dtt); |
|
| 1245 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1246 | - : $dtt['DTT_EVT_start']; |
|
| 1247 | - $datetime_values = [ |
|
| 1248 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1249 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1250 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1251 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1252 | - 'DTT_order' => $row, |
|
| 1253 | - ]; |
|
| 1254 | - // if we have an id then let's get existing object first and then set the new values. |
|
| 1255 | - // Otherwise we instantiate a new object for save. |
|
| 1256 | - if (! empty($dtt['DTT_ID'])) { |
|
| 1257 | - $DTM = EE_Registry::instance() |
|
| 1258 | - ->load_model('Datetime', [$evtobj->get_timezone()]) |
|
| 1259 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1260 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1261 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1262 | - foreach ($datetime_values as $field => $value) { |
|
| 1263 | - $DTM->set($field, $value); |
|
| 1264 | - } |
|
| 1265 | - // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it. |
|
| 1266 | - // We need to do this so we dont' TRASH the parent DTT. |
|
| 1267 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1268 | - } else { |
|
| 1269 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1270 | - 'Datetime', |
|
| 1271 | - [$datetime_values, $evtobj->get_timezone(), $incoming_date_formats], |
|
| 1272 | - false, |
|
| 1273 | - false |
|
| 1274 | - ); |
|
| 1275 | - foreach ($datetime_values as $field => $value) { |
|
| 1276 | - $DTM->set($field, $value); |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - $DTM->save(); |
|
| 1280 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1281 | - // load DTT helper |
|
| 1282 | - // before going any further make sure our dates are setup correctly |
|
| 1283 | - // so that the end date is always equal or greater than the start date. |
|
| 1284 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1285 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1286 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1287 | - $DTT->save(); |
|
| 1288 | - } |
|
| 1289 | - // now we got to make sure we add the new DTT_ID to the $saved_dtts array |
|
| 1290 | - // because it is possible there was a new one created for the autosave. |
|
| 1291 | - $saved_dtt = $DTT; |
|
| 1292 | - $success = ! $success ? $success : $DTT; |
|
| 1293 | - // if ANY of these updates fail then we want the appropriate global error message. |
|
| 1294 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1295 | - } |
|
| 1296 | - // no dtts get deleted so we don't do any of that logic here. |
|
| 1297 | - // update tickets next |
|
| 1298 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1299 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1300 | - $incoming_date_formats = ['Y-m-d', 'h:i a']; |
|
| 1301 | - $update_prices = false; |
|
| 1302 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1303 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1304 | - : 0; |
|
| 1305 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1306 | - $tkt = array_map('trim', $tkt); |
|
| 1307 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1308 | - // let's use now in the set timezone. |
|
| 1309 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1310 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1311 | - } |
|
| 1312 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1313 | - // use the start date of the first datetime |
|
| 1314 | - $dtt = $evtobj->first_datetime(); |
|
| 1315 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1316 | - $incoming_date_formats[0], |
|
| 1317 | - $incoming_date_formats[1] |
|
| 1318 | - ); |
|
| 1319 | - } |
|
| 1320 | - $TKT_values = [ |
|
| 1321 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1322 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1323 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1324 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1325 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1326 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1327 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1328 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1329 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1330 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1331 | - 'TKT_row' => $row, |
|
| 1332 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1333 | - 'TKT_price' => $ticket_price, |
|
| 1334 | - ]; |
|
| 1335 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 1336 | - // which means in turn that the prices will become new prices as well. |
|
| 1337 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1338 | - $TKT_values['TKT_ID'] = 0; |
|
| 1339 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1340 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1341 | - $update_prices = true; |
|
| 1342 | - } |
|
| 1343 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1344 | - // we actually do our saves a head of doing any add_relations to because its entirely possible |
|
| 1345 | - // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1346 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 1347 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1348 | - if (! empty($tkt['TKT_ID'])) { |
|
| 1349 | - $TKT = EE_Registry::instance() |
|
| 1350 | - ->load_model('Ticket', [$evtobj->get_timezone()]) |
|
| 1351 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1352 | - if ($TKT instanceof EE_Ticket) { |
|
| 1353 | - $ticket_sold = $TKT->count_related( |
|
| 1354 | - 'Registration', |
|
| 1355 | - [ |
|
| 1356 | - [ |
|
| 1357 | - 'STS_ID' => [ |
|
| 1358 | - 'NOT IN', |
|
| 1359 | - [EEM_Registration::status_id_incomplete], |
|
| 1360 | - ], |
|
| 1361 | - ], |
|
| 1362 | - ] |
|
| 1363 | - ) > 0; |
|
| 1364 | - // let's just check the total price for the existing ticket and determine if it matches the new |
|
| 1365 | - // total price. if they are different then we create a new ticket (if tickets sold) |
|
| 1366 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 1367 | - $create_new_TKT = $ticket_sold |
|
| 1368 | - && ! $TKT->deleted() |
|
| 1369 | - && EEH_Money::compare_floats( |
|
| 1370 | - $ticket_price, |
|
| 1371 | - $TKT->get('TKT_price'), |
|
| 1372 | - '!==' |
|
| 1373 | - ); |
|
| 1374 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1375 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1376 | - // set new values |
|
| 1377 | - foreach ($TKT_values as $field => $value) { |
|
| 1378 | - if ($field === 'TKT_qty') { |
|
| 1379 | - $TKT->set_qty($value); |
|
| 1380 | - } else { |
|
| 1381 | - $TKT->set($field, $value); |
|
| 1382 | - } |
|
| 1383 | - } |
|
| 1384 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 1385 | - // Otherwise we have to create a new ticket. |
|
| 1386 | - if ($create_new_TKT) { |
|
| 1387 | - // archive the old ticket first |
|
| 1388 | - $TKT->set('TKT_deleted', 1); |
|
| 1389 | - $TKT->save(); |
|
| 1390 | - // make sure this ticket is still recorded in our saved_tkts |
|
| 1391 | - // so we don't run it through the regular trash routine. |
|
| 1392 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1393 | - // create new ticket that's a copy of the existing except a new id of course |
|
| 1394 | - // (and not archived) AND has the new TKT_price associated with it. |
|
| 1395 | - $TKT = clone $TKT; |
|
| 1396 | - $TKT->set('TKT_ID', 0); |
|
| 1397 | - $TKT->set('TKT_deleted', 0); |
|
| 1398 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1399 | - $TKT->set('TKT_sold', 0); |
|
| 1400 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1401 | - $update_prices = true; |
|
| 1402 | - } |
|
| 1403 | - // make sure price is set if it hasn't been already |
|
| 1404 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1405 | - } |
|
| 1406 | - } else { |
|
| 1407 | - // no TKT_id so a new TKT |
|
| 1408 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1409 | - $TKT = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false); |
|
| 1410 | - if ($TKT instanceof EE_Ticket) { |
|
| 1411 | - // need to reset values to properly account for the date formats |
|
| 1412 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1413 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1414 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1415 | - // set new values |
|
| 1416 | - foreach ($TKT_values as $field => $value) { |
|
| 1417 | - if ($field === 'TKT_qty') { |
|
| 1418 | - $TKT->set_qty($value); |
|
| 1419 | - } else { |
|
| 1420 | - $TKT->set($field, $value); |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - $update_prices = true; |
|
| 1424 | - } |
|
| 1425 | - } |
|
| 1426 | - // cap ticket qty by datetime reg limits |
|
| 1427 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1428 | - // update ticket. |
|
| 1429 | - $TKT->save(); |
|
| 1430 | - // before going any further make sure our dates are setup correctly |
|
| 1431 | - // so that the end date is always equal or greater than the start date. |
|
| 1432 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1433 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1434 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1435 | - $TKT->save(); |
|
| 1436 | - } |
|
| 1437 | - // initially let's add the ticket to the dtt |
|
| 1438 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1439 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1440 | - // add prices to ticket |
|
| 1441 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1442 | - } |
|
| 1443 | - // however now we need to handle permanently deleting tickets via the ui. |
|
| 1444 | - // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
| 1445 | - // However, it does allow for deleting tickets that have no tickets sold, |
|
| 1446 | - // in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1447 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
| 1448 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1449 | - foreach ($tickets_removed as $id) { |
|
| 1450 | - $id = absint($id); |
|
| 1451 | - // get the ticket for this id |
|
| 1452 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1453 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 1454 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1455 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1456 | - foreach ($dtts as $dtt) { |
|
| 1457 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1458 | - } |
|
| 1459 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 1460 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1461 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1462 | - // finally let's delete this ticket |
|
| 1463 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1464 | - $tkt_to_remove->delete_permanently(); |
|
| 1465 | - } |
|
| 1466 | - return [$saved_dtt, $saved_tickets]; |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * This attaches a list of given prices to a ticket. |
|
| 1472 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) |
|
| 1473 | - * because if there is a change in price information on a ticket, a new ticket is created anyways |
|
| 1474 | - * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. |
|
| 1475 | - * |
|
| 1476 | - * @access private |
|
| 1477 | - * @param array $prices Array of prices from the form. |
|
| 1478 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1479 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1480 | - * @return void |
|
| 1481 | - * @throws EE_Error |
|
| 1482 | - * @throws InvalidArgumentException |
|
| 1483 | - * @throws InvalidDataTypeException |
|
| 1484 | - * @throws InvalidInterfaceException |
|
| 1485 | - * @throws ReflectionException |
|
| 1486 | - */ |
|
| 1487 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1488 | - { |
|
| 1489 | - foreach ($prices as $row => $prc) { |
|
| 1490 | - $PRC_values = [ |
|
| 1491 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1492 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1493 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1494 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1495 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1496 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1497 | - 'PRC_order' => $row, |
|
| 1498 | - ]; |
|
| 1499 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1500 | - $PRC_values['PRC_ID'] = 0; |
|
| 1501 | - $PRC = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false); |
|
| 1502 | - } else { |
|
| 1503 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1504 | - // update this price with new values |
|
| 1505 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1506 | - $PRC->set($field, $newprc); |
|
| 1507 | - } |
|
| 1508 | - $PRC->save(); |
|
| 1509 | - } |
|
| 1510 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1511 | - } |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - |
|
| 1515 | - /** |
|
| 1516 | - * Add in our autosave ajax handlers |
|
| 1517 | - * |
|
| 1518 | - */ |
|
| 1519 | - protected function _ee_autosave_create_new() |
|
| 1520 | - { |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - |
|
| 1524 | - /** |
|
| 1525 | - * More autosave handlers. |
|
| 1526 | - */ |
|
| 1527 | - protected function _ee_autosave_edit() |
|
| 1528 | - { |
|
| 1529 | - } |
|
| 1530 | - |
|
| 1531 | - |
|
| 1532 | - /** |
|
| 1533 | - * _generate_publish_box_extra_content |
|
| 1534 | - * |
|
| 1535 | - * @throws DomainException |
|
| 1536 | - * @throws EE_Error |
|
| 1537 | - * @throws InvalidArgumentException |
|
| 1538 | - * @throws InvalidDataTypeException |
|
| 1539 | - * @throws InvalidInterfaceException |
|
| 1540 | - * @throws ReflectionException |
|
| 1541 | - */ |
|
| 1542 | - private function _generate_publish_box_extra_content() |
|
| 1543 | - { |
|
| 1544 | - // load formatter helper |
|
| 1545 | - // args for getting related registrations |
|
| 1546 | - $approved_query_args = [ |
|
| 1547 | - [ |
|
| 1548 | - 'REG_deleted' => 0, |
|
| 1549 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1550 | - ], |
|
| 1551 | - ]; |
|
| 1552 | - $not_approved_query_args = [ |
|
| 1553 | - [ |
|
| 1554 | - 'REG_deleted' => 0, |
|
| 1555 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1556 | - ], |
|
| 1557 | - ]; |
|
| 1558 | - $pending_payment_query_args = [ |
|
| 1559 | - [ |
|
| 1560 | - 'REG_deleted' => 0, |
|
| 1561 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1562 | - ], |
|
| 1563 | - ]; |
|
| 1564 | - // publish box |
|
| 1565 | - $publish_box_extra_args = [ |
|
| 1566 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1567 | - [ |
|
| 1568 | - 'action' => 'default', |
|
| 1569 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1570 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1571 | - ], |
|
| 1572 | - REG_ADMIN_URL |
|
| 1573 | - ), |
|
| 1574 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1575 | - [ |
|
| 1576 | - 'action' => 'default', |
|
| 1577 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1578 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1579 | - ], |
|
| 1580 | - REG_ADMIN_URL |
|
| 1581 | - ), |
|
| 1582 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1583 | - [ |
|
| 1584 | - 'action' => 'default', |
|
| 1585 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1586 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1587 | - ], |
|
| 1588 | - REG_ADMIN_URL |
|
| 1589 | - ), |
|
| 1590 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1591 | - 'Registration', |
|
| 1592 | - $approved_query_args |
|
| 1593 | - ), |
|
| 1594 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1595 | - 'Registration', |
|
| 1596 | - $not_approved_query_args |
|
| 1597 | - ), |
|
| 1598 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1599 | - 'Registration', |
|
| 1600 | - $pending_payment_query_args |
|
| 1601 | - ), |
|
| 1602 | - 'misc_pub_section_class' => apply_filters( |
|
| 1603 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1604 | - 'misc-pub-section' |
|
| 1605 | - ), |
|
| 1606 | - ]; |
|
| 1607 | - ob_start(); |
|
| 1608 | - do_action( |
|
| 1609 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1610 | - $this->_cpt_model_obj |
|
| 1611 | - ); |
|
| 1612 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1613 | - // load template |
|
| 1614 | - EEH_Template::display_template( |
|
| 1615 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1616 | - $publish_box_extra_args |
|
| 1617 | - ); |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - |
|
| 1621 | - /** |
|
| 1622 | - * @return EE_Event |
|
| 1623 | - */ |
|
| 1624 | - public function get_event_object() |
|
| 1625 | - { |
|
| 1626 | - return $this->_cpt_model_obj; |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - |
|
| 1631 | - |
|
| 1632 | - /** METABOXES * */ |
|
| 1633 | - /** |
|
| 1634 | - * _register_event_editor_meta_boxes |
|
| 1635 | - * add all metaboxes related to the event_editor |
|
| 1636 | - * |
|
| 1637 | - * @return void |
|
| 1638 | - * @throws EE_Error |
|
| 1639 | - * @throws InvalidArgumentException |
|
| 1640 | - * @throws InvalidDataTypeException |
|
| 1641 | - * @throws InvalidInterfaceException |
|
| 1642 | - * @throws ReflectionException |
|
| 1643 | - */ |
|
| 1644 | - protected function _register_event_editor_meta_boxes() |
|
| 1645 | - { |
|
| 1646 | - $this->verify_cpt_object(); |
|
| 1647 | - $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
| 1648 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1649 | - if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1650 | - add_meta_box( |
|
| 1651 | - 'espresso_event_editor_event_options', |
|
| 1652 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1653 | - [$this, 'registration_options_meta_box'], |
|
| 1654 | - $this->page_slug, |
|
| 1655 | - 'side' |
|
| 1656 | - ); |
|
| 1657 | - } |
|
| 1658 | - if (! $use_advanced_editor) { |
|
| 1659 | - add_meta_box( |
|
| 1660 | - 'espresso_event_editor_tickets', |
|
| 1661 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1662 | - [$this, 'ticket_metabox'], |
|
| 1663 | - $this->page_slug, |
|
| 1664 | - 'normal', |
|
| 1665 | - 'high' |
|
| 1666 | - ); |
|
| 1667 | - } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1668 | - add_action( |
|
| 1669 | - 'add_meta_boxes_espresso_events', |
|
| 1670 | - function () { |
|
| 1671 | - global $current_screen; |
|
| 1672 | - remove_meta_box('authordiv', $current_screen, 'normal'); |
|
| 1673 | - }, |
|
| 1674 | - 99 |
|
| 1675 | - ); |
|
| 1676 | - } |
|
| 1677 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1678 | - // where a metabox has a related management page in the admin |
|
| 1679 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1680 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - |
|
| 1684 | - /** |
|
| 1685 | - * @throws DomainException |
|
| 1686 | - * @throws EE_Error |
|
| 1687 | - * @throws InvalidArgumentException |
|
| 1688 | - * @throws InvalidDataTypeException |
|
| 1689 | - * @throws InvalidInterfaceException |
|
| 1690 | - * @throws ReflectionException |
|
| 1691 | - */ |
|
| 1692 | - public function ticket_metabox() |
|
| 1693 | - { |
|
| 1694 | - $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1695 | - // defaults for template args |
|
| 1696 | - $template_args = [ |
|
| 1697 | - 'existing_datetime_ids' => '', |
|
| 1698 | - 'event_datetime_help_link' => '', |
|
| 1699 | - 'ticket_options_help_link' => '', |
|
| 1700 | - 'time' => null, |
|
| 1701 | - 'ticket_rows' => '', |
|
| 1702 | - 'existing_ticket_ids' => '', |
|
| 1703 | - 'total_ticket_rows' => 1, |
|
| 1704 | - 'ticket_js_structure' => '', |
|
| 1705 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1706 | - 'disabled' => '', |
|
| 1707 | - ]; |
|
| 1708 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1709 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1710 | - /** |
|
| 1711 | - * 1. Start with retrieving Datetimes |
|
| 1712 | - * 2. Fore each datetime get related tickets |
|
| 1713 | - * 3. For each ticket get related prices |
|
| 1714 | - */ |
|
| 1715 | - /** @var EEM_Datetime $datetime_model */ |
|
| 1716 | - $datetime_model = EE_Registry::instance()->load_model('Datetime'); |
|
| 1717 | - /** @var EEM_Ticket $datetime_model */ |
|
| 1718 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1719 | - $times = $datetime_model->get_all_event_dates($event_id); |
|
| 1720 | - /** @type EE_Datetime $first_datetime */ |
|
| 1721 | - $first_datetime = reset($times); |
|
| 1722 | - // do we get related tickets? |
|
| 1723 | - if ( |
|
| 1724 | - $first_datetime instanceof EE_Datetime |
|
| 1725 | - && $first_datetime->ID() !== 0 |
|
| 1726 | - ) { |
|
| 1727 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1728 | - $template_args['time'] = $first_datetime; |
|
| 1729 | - $related_tickets = $first_datetime->tickets( |
|
| 1730 | - [ |
|
| 1731 | - ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1732 | - 'default_where_conditions' => 'none', |
|
| 1733 | - ] |
|
| 1734 | - ); |
|
| 1735 | - if (! empty($related_tickets)) { |
|
| 1736 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1737 | - $row = 0; |
|
| 1738 | - foreach ($related_tickets as $ticket) { |
|
| 1739 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1740 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1741 | - $row++; |
|
| 1742 | - } |
|
| 1743 | - } else { |
|
| 1744 | - $template_args['total_ticket_rows'] = 1; |
|
| 1745 | - /** @type EE_Ticket $ticket */ |
|
| 1746 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1747 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1748 | - } |
|
| 1749 | - } else { |
|
| 1750 | - $template_args['time'] = $times[0]; |
|
| 1751 | - /** @type EE_Ticket[] $tickets */ |
|
| 1752 | - $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1753 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
| 1754 | - // NOTE: we're just sending the first default row |
|
| 1755 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1756 | - } |
|
| 1757 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1758 | - 'event_editor_event_datetimes_help_tab' |
|
| 1759 | - ); |
|
| 1760 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1761 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1762 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1763 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1764 | - $ticket_model->create_default_object(), |
|
| 1765 | - true |
|
| 1766 | - ); |
|
| 1767 | - $template = apply_filters( |
|
| 1768 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1769 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1770 | - ); |
|
| 1771 | - EEH_Template::display_template($template, $template_args); |
|
| 1772 | - } |
|
| 1773 | - |
|
| 1774 | - |
|
| 1775 | - /** |
|
| 1776 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1777 | - * |
|
| 1778 | - * @access private |
|
| 1779 | - * @param EE_Ticket $ticket the ticket object |
|
| 1780 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1781 | - * @param int $row |
|
| 1782 | - * @return string generated html for the ticket row. |
|
| 1783 | - * @throws DomainException |
|
| 1784 | - * @throws EE_Error |
|
| 1785 | - * @throws InvalidArgumentException |
|
| 1786 | - * @throws InvalidDataTypeException |
|
| 1787 | - * @throws InvalidInterfaceException |
|
| 1788 | - * @throws ReflectionException |
|
| 1789 | - */ |
|
| 1790 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1791 | - { |
|
| 1792 | - $template_args = [ |
|
| 1793 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1794 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1795 | - : '', |
|
| 1796 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1797 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1798 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1799 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1800 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1801 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1802 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1803 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1804 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1805 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1806 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1807 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1808 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1809 | - : ' disabled=disabled', |
|
| 1810 | - ]; |
|
| 1811 | - $price = $ticket->ID() !== 0 |
|
| 1812 | - ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1813 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1814 | - $price_args = [ |
|
| 1815 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1816 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1817 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1818 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1819 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1820 | - ]; |
|
| 1821 | - // make sure we have default start and end dates if skeleton |
|
| 1822 | - // handle rows that should NOT be empty |
|
| 1823 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1824 | - // if empty then the start date will be now. |
|
| 1825 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1826 | - } |
|
| 1827 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1828 | - // get the earliest datetime (if present); |
|
| 1829 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1830 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1831 | - 'Datetime', |
|
| 1832 | - ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1833 | - ) |
|
| 1834 | - : null; |
|
| 1835 | - if (! empty($earliest_dtt)) { |
|
| 1836 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1837 | - } else { |
|
| 1838 | - $template_args['TKT_end_date'] = date( |
|
| 1839 | - 'Y-m-d h:i a', |
|
| 1840 | - mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')) |
|
| 1841 | - ); |
|
| 1842 | - } |
|
| 1843 | - } |
|
| 1844 | - $template_args = array_merge($template_args, $price_args); |
|
| 1845 | - $template = apply_filters( |
|
| 1846 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1847 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1848 | - $ticket |
|
| 1849 | - ); |
|
| 1850 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - |
|
| 1854 | - /** |
|
| 1855 | - * @throws DomainException |
|
| 1856 | - * @throws EE_Error |
|
| 1857 | - */ |
|
| 1858 | - public function registration_options_meta_box() |
|
| 1859 | - { |
|
| 1860 | - $yes_no_values = [ |
|
| 1861 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1862 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1863 | - ]; |
|
| 1864 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1865 | - [ |
|
| 1866 | - EEM_Registration::status_id_cancelled, |
|
| 1867 | - EEM_Registration::status_id_declined, |
|
| 1868 | - EEM_Registration::status_id_incomplete, |
|
| 1869 | - ], |
|
| 1870 | - true |
|
| 1871 | - ); |
|
| 1872 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1873 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1874 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1875 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1876 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1877 | - 'default_reg_status', |
|
| 1878 | - $default_reg_status_values, |
|
| 1879 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1880 | - ); |
|
| 1881 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1882 | - 'display_desc', |
|
| 1883 | - $yes_no_values, |
|
| 1884 | - $this->_cpt_model_obj->display_description() |
|
| 1885 | - ); |
|
| 1886 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1887 | - 'display_ticket_selector', |
|
| 1888 | - $yes_no_values, |
|
| 1889 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1890 | - '', |
|
| 1891 | - '', |
|
| 1892 | - false |
|
| 1893 | - ); |
|
| 1894 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1895 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1896 | - '', |
|
| 1897 | - $template_args, |
|
| 1898 | - $yes_no_values, |
|
| 1899 | - $default_reg_status_values |
|
| 1900 | - ); |
|
| 1901 | - EEH_Template::display_template( |
|
| 1902 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1903 | - $template_args |
|
| 1904 | - ); |
|
| 1905 | - } |
|
| 1906 | - |
|
| 1907 | - |
|
| 1908 | - /** |
|
| 1909 | - * _get_events() |
|
| 1910 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1911 | - * |
|
| 1912 | - * @access public |
|
| 1913 | - * @param int $per_page count of items per page (20 default); |
|
| 1914 | - * @param int $current_page what is the current page being viewed. |
|
| 1915 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1916 | - * If FALSE then we return an array of event objects |
|
| 1917 | - * that match the given _view and paging parameters. |
|
| 1918 | - * @return array|int an array of event objects. |
|
| 1919 | - * @throws EE_Error |
|
| 1920 | - * @throws InvalidArgumentException |
|
| 1921 | - * @throws InvalidDataTypeException |
|
| 1922 | - * @throws InvalidInterfaceException |
|
| 1923 | - * @throws ReflectionException |
|
| 1924 | - * @throws Exception |
|
| 1925 | - * @throws Exception |
|
| 1926 | - * @throws Exception |
|
| 1927 | - */ |
|
| 1928 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1929 | - { |
|
| 1930 | - $EEME = $this->_event_model(); |
|
| 1931 | - $offset = ($current_page - 1) * $per_page; |
|
| 1932 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1933 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1934 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 1935 | - $month_r = ''; |
|
| 1936 | - $year_r = ''; |
|
| 1937 | - if (isset($this->_req_data['month_range'])) { |
|
| 1938 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1939 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1940 | - // where PHP doesn't know what to assume for date. |
|
| 1941 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1942 | - $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1943 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1944 | - } |
|
| 1945 | - $where = []; |
|
| 1946 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1947 | - // determine what post_status our condition will have for the query. |
|
| 1948 | - switch ($status) { |
|
| 1949 | - case 'month': |
|
| 1950 | - case 'today': |
|
| 1951 | - case null: |
|
| 1952 | - case 'all': |
|
| 1953 | - break; |
|
| 1954 | - case 'draft': |
|
| 1955 | - $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1956 | - break; |
|
| 1957 | - default: |
|
| 1958 | - $where['status'] = $status; |
|
| 1959 | - } |
|
| 1960 | - // categories? |
|
| 1961 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1962 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1963 | - if (! empty($category)) { |
|
| 1964 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1965 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1966 | - } |
|
| 1967 | - // date where conditions |
|
| 1968 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1969 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
|
| 1970 | - $DateTime = new DateTime( |
|
| 1971 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1972 | - new DateTimeZone('UTC') |
|
| 1973 | - ); |
|
| 1974 | - $start = $DateTime->getTimestamp(); |
|
| 1975 | - // set the datetime to be the end of the month |
|
| 1976 | - $DateTime->setDate( |
|
| 1977 | - $year_r, |
|
| 1978 | - $month_r, |
|
| 1979 | - $DateTime->format('t') |
|
| 1980 | - )->setTime(23, 59, 59); |
|
| 1981 | - $end = $DateTime->getTimestamp(); |
|
| 1982 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1983 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') { |
|
| 1984 | - $DateTime = |
|
| 1985 | - new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1986 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1987 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1988 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1989 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') { |
|
| 1990 | - $now = date('Y-m-01'); |
|
| 1991 | - $DateTime = |
|
| 1992 | - new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1993 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1994 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1995 | - ->setTime(23, 59, 59) |
|
| 1996 | - ->format(implode(' ', $start_formats)); |
|
| 1997 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1998 | - } |
|
| 1999 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 2000 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 2001 | - } elseif ( |
|
| 2002 | - ! isset($where['status']) |
|
| 2003 | - && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events') |
|
| 2004 | - ) { |
|
| 2005 | - $where['OR'] = [ |
|
| 2006 | - 'status*restrict_private' => ['!=', 'private'], |
|
| 2007 | - 'AND' => [ |
|
| 2008 | - 'status*inclusive' => ['=', 'private'], |
|
| 2009 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 2010 | - ], |
|
| 2011 | - ]; |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - if ( |
|
| 2015 | - isset($this->_req_data['EVT_wp_user']) |
|
| 2016 | - && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id() |
|
| 2017 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 2018 | - ) { |
|
| 2019 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 2020 | - } |
|
| 2021 | - // search query handling |
|
| 2022 | - if (isset($this->_req_data['s'])) { |
|
| 2023 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2024 | - $where['OR'] = [ |
|
| 2025 | - 'EVT_name' => ['LIKE', $search_string], |
|
| 2026 | - 'EVT_desc' => ['LIKE', $search_string], |
|
| 2027 | - 'EVT_short_desc' => ['LIKE', $search_string], |
|
| 2028 | - ]; |
|
| 2029 | - } |
|
| 2030 | - // filter events by venue. |
|
| 2031 | - if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
| 2032 | - $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
| 2033 | - } |
|
| 2034 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 2035 | - $query_params = apply_filters( |
|
| 2036 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 2037 | - [ |
|
| 2038 | - $where, |
|
| 2039 | - 'limit' => $limit, |
|
| 2040 | - 'order_by' => $orderby, |
|
| 2041 | - 'order' => $order, |
|
| 2042 | - 'group_by' => 'EVT_ID', |
|
| 2043 | - ], |
|
| 2044 | - $this->_req_data |
|
| 2045 | - ); |
|
| 2046 | - |
|
| 2047 | - // let's first check if we have special requests coming in. |
|
| 2048 | - if (isset($this->_req_data['active_status'])) { |
|
| 2049 | - switch ($this->_req_data['active_status']) { |
|
| 2050 | - case 'upcoming': |
|
| 2051 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 2052 | - case 'expired': |
|
| 2053 | - return $EEME->get_expired_events($query_params, $count); |
|
| 2054 | - case 'active': |
|
| 2055 | - return $EEME->get_active_events($query_params, $count); |
|
| 2056 | - case 'inactive': |
|
| 2057 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 2058 | - } |
|
| 2059 | - } |
|
| 2060 | - |
|
| 2061 | - return $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 2062 | - } |
|
| 2063 | - |
|
| 2064 | - |
|
| 2065 | - /** |
|
| 2066 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 2067 | - * |
|
| 2068 | - * @param string $post_id |
|
| 2069 | - * @throws EE_Error |
|
| 2070 | - * @throws InvalidArgumentException |
|
| 2071 | - * @throws InvalidDataTypeException |
|
| 2072 | - * @throws InvalidInterfaceException |
|
| 2073 | - * @throws ReflectionException |
|
| 2074 | - */ |
|
| 2075 | - public function trash_cpt_item($post_id) |
|
| 2076 | - { |
|
| 2077 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 2078 | - $this->_trash_or_restore_event('trash', false); |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - |
|
| 2082 | - /** |
|
| 2083 | - * @param string $post_id |
|
| 2084 | - * @throws EE_Error |
|
| 2085 | - * @throws InvalidArgumentException |
|
| 2086 | - * @throws InvalidDataTypeException |
|
| 2087 | - * @throws InvalidInterfaceException |
|
| 2088 | - * @throws ReflectionException |
|
| 2089 | - */ |
|
| 2090 | - public function restore_cpt_item($post_id) |
|
| 2091 | - { |
|
| 2092 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 2093 | - $this->_trash_or_restore_event('draft', false); |
|
| 2094 | - } |
|
| 2095 | - |
|
| 2096 | - |
|
| 2097 | - /** |
|
| 2098 | - * @param string $post_id |
|
| 2099 | - * @throws EE_Error |
|
| 2100 | - * @throws InvalidArgumentException |
|
| 2101 | - * @throws InvalidDataTypeException |
|
| 2102 | - * @throws InvalidInterfaceException |
|
| 2103 | - * @throws ReflectionException |
|
| 2104 | - */ |
|
| 2105 | - public function delete_cpt_item($post_id) |
|
| 2106 | - { |
|
| 2107 | - throw new EE_Error( |
|
| 2108 | - esc_html__( |
|
| 2109 | - 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
| 2110 | - 'event_espresso' |
|
| 2111 | - ) |
|
| 2112 | - ); |
|
| 2113 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 2114 | - $this->_delete_event(); |
|
| 2115 | - } |
|
| 2116 | - |
|
| 2117 | - |
|
| 2118 | - /** |
|
| 2119 | - * _trash_or_restore_event |
|
| 2120 | - * |
|
| 2121 | - * @access protected |
|
| 2122 | - * @param string $event_status |
|
| 2123 | - * @param bool $redirect_after |
|
| 2124 | - * @throws EE_Error |
|
| 2125 | - * @throws InvalidArgumentException |
|
| 2126 | - * @throws InvalidDataTypeException |
|
| 2127 | - * @throws InvalidInterfaceException |
|
| 2128 | - * @throws ReflectionException |
|
| 2129 | - */ |
|
| 2130 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 2131 | - { |
|
| 2132 | - // determine the event id and set to array. |
|
| 2133 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 2134 | - // loop thru events |
|
| 2135 | - if ($EVT_ID) { |
|
| 2136 | - // clean status |
|
| 2137 | - $event_status = sanitize_key($event_status); |
|
| 2138 | - // grab status |
|
| 2139 | - if (! empty($event_status)) { |
|
| 2140 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2141 | - } else { |
|
| 2142 | - $success = false; |
|
| 2143 | - $msg = esc_html__( |
|
| 2144 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2145 | - 'event_espresso' |
|
| 2146 | - ); |
|
| 2147 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2148 | - } |
|
| 2149 | - } else { |
|
| 2150 | - $success = false; |
|
| 2151 | - $msg = esc_html__( |
|
| 2152 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2153 | - 'event_espresso' |
|
| 2154 | - ); |
|
| 2155 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2156 | - } |
|
| 2157 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2158 | - if ($redirect_after) { |
|
| 2159 | - $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2160 | - } |
|
| 2161 | - } |
|
| 2162 | - |
|
| 2163 | - |
|
| 2164 | - /** |
|
| 2165 | - * _trash_or_restore_events |
|
| 2166 | - * |
|
| 2167 | - * @access protected |
|
| 2168 | - * @param string $event_status |
|
| 2169 | - * @return void |
|
| 2170 | - * @throws EE_Error |
|
| 2171 | - * @throws InvalidArgumentException |
|
| 2172 | - * @throws InvalidDataTypeException |
|
| 2173 | - * @throws InvalidInterfaceException |
|
| 2174 | - * @throws ReflectionException |
|
| 2175 | - */ |
|
| 2176 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2177 | - { |
|
| 2178 | - // clean status |
|
| 2179 | - $event_status = sanitize_key($event_status); |
|
| 2180 | - // grab status |
|
| 2181 | - if (! empty($event_status)) { |
|
| 2182 | - $success = true; |
|
| 2183 | - // determine the event id and set to array. |
|
| 2184 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []; |
|
| 2185 | - // loop thru events |
|
| 2186 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2187 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 2188 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2189 | - $success = $results !== false ? $success : false; |
|
| 2190 | - } else { |
|
| 2191 | - $msg = sprintf( |
|
| 2192 | - esc_html__( |
|
| 2193 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2194 | - 'event_espresso' |
|
| 2195 | - ), |
|
| 2196 | - $EVT_ID |
|
| 2197 | - ); |
|
| 2198 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2199 | - $success = false; |
|
| 2200 | - } |
|
| 2201 | - } |
|
| 2202 | - } else { |
|
| 2203 | - $success = false; |
|
| 2204 | - $msg = esc_html__( |
|
| 2205 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2206 | - 'event_espresso' |
|
| 2207 | - ); |
|
| 2208 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2209 | - } |
|
| 2210 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2211 | - $success = $success ? 2 : false; |
|
| 2212 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2213 | - $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2214 | - } |
|
| 2215 | - |
|
| 2216 | - |
|
| 2217 | - /** |
|
| 2218 | - * _trash_or_restore_events |
|
| 2219 | - * |
|
| 2220 | - * @access private |
|
| 2221 | - * @param int $EVT_ID |
|
| 2222 | - * @param string $event_status |
|
| 2223 | - * @return bool |
|
| 2224 | - * @throws EE_Error |
|
| 2225 | - * @throws InvalidArgumentException |
|
| 2226 | - * @throws InvalidDataTypeException |
|
| 2227 | - * @throws InvalidInterfaceException |
|
| 2228 | - * @throws ReflectionException |
|
| 2229 | - */ |
|
| 2230 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2231 | - { |
|
| 2232 | - // grab event id |
|
| 2233 | - if (! $EVT_ID) { |
|
| 2234 | - $msg = esc_html__( |
|
| 2235 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2236 | - 'event_espresso' |
|
| 2237 | - ); |
|
| 2238 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2239 | - return false; |
|
| 2240 | - } |
|
| 2241 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2242 | - // clean status |
|
| 2243 | - $event_status = sanitize_key($event_status); |
|
| 2244 | - // grab status |
|
| 2245 | - if (empty($event_status)) { |
|
| 2246 | - $msg = esc_html__( |
|
| 2247 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2248 | - 'event_espresso' |
|
| 2249 | - ); |
|
| 2250 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2251 | - return false; |
|
| 2252 | - } |
|
| 2253 | - // was event trashed or restored ? |
|
| 2254 | - switch ($event_status) { |
|
| 2255 | - case 'draft': |
|
| 2256 | - $action = 'restored from the trash'; |
|
| 2257 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2258 | - break; |
|
| 2259 | - case 'trash': |
|
| 2260 | - $action = 'moved to the trash'; |
|
| 2261 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2262 | - break; |
|
| 2263 | - default: |
|
| 2264 | - $action = 'updated'; |
|
| 2265 | - $hook = false; |
|
| 2266 | - } |
|
| 2267 | - // use class to change status |
|
| 2268 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2269 | - $success = $this->_cpt_model_obj->save(); |
|
| 2270 | - if ($success === false) { |
|
| 2271 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2272 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2273 | - return false; |
|
| 2274 | - } |
|
| 2275 | - if ($hook) { |
|
| 2276 | - do_action($hook); |
|
| 2277 | - } |
|
| 2278 | - return true; |
|
| 2279 | - } |
|
| 2280 | - |
|
| 2281 | - |
|
| 2282 | - /** |
|
| 2283 | - * @throws InvalidArgumentException |
|
| 2284 | - * @throws InvalidDataTypeException |
|
| 2285 | - * @throws InvalidInterfaceException |
|
| 2286 | - */ |
|
| 2287 | - protected function _delete_event() |
|
| 2288 | - { |
|
| 2289 | - $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []); |
|
| 2290 | - } |
|
| 2291 | - |
|
| 2292 | - |
|
| 2293 | - /** |
|
| 2294 | - * Gets the tree traversal batch persister. |
|
| 2295 | - * |
|
| 2296 | - * @return NodeGroupDao |
|
| 2297 | - * @throws InvalidArgumentException |
|
| 2298 | - * @throws InvalidDataTypeException |
|
| 2299 | - * @throws InvalidInterfaceException |
|
| 2300 | - * @since 4.10.12.p |
|
| 2301 | - */ |
|
| 2302 | - protected function getModelObjNodeGroupPersister() |
|
| 2303 | - { |
|
| 2304 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2305 | - $this->model_obj_node_group_persister = |
|
| 2306 | - $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2307 | - } |
|
| 2308 | - return $this->model_obj_node_group_persister; |
|
| 2309 | - } |
|
| 2310 | - |
|
| 2311 | - |
|
| 2312 | - /** |
|
| 2313 | - * @return void |
|
| 2314 | - * @throws InvalidArgumentException |
|
| 2315 | - * @throws InvalidDataTypeException |
|
| 2316 | - * @throws InvalidInterfaceException |
|
| 2317 | - */ |
|
| 2318 | - protected function _delete_events() |
|
| 2319 | - { |
|
| 2320 | - $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []); |
|
| 2321 | - } |
|
| 2322 | - |
|
| 2323 | - |
|
| 2324 | - protected function generateDeletionPreview($event_ids) |
|
| 2325 | - { |
|
| 2326 | - $event_ids = (array) $event_ids; |
|
| 2327 | - // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2328 | - $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2329 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2330 | - [ |
|
| 2331 | - 'action' => 'preview_deletion', |
|
| 2332 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2333 | - ], |
|
| 2334 | - $this->_admin_base_url |
|
| 2335 | - ); |
|
| 2336 | - $event_ids = array_map( |
|
| 2337 | - 'intval', |
|
| 2338 | - $event_ids |
|
| 2339 | - ); |
|
| 2340 | - |
|
| 2341 | - EEH_URL::safeRedirectAndExit( |
|
| 2342 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2343 | - [ |
|
| 2344 | - 'page' => 'espresso_batch', |
|
| 2345 | - 'batch' => EED_Batch::batch_job, |
|
| 2346 | - 'EVT_IDs' => $event_ids, |
|
| 2347 | - 'deletion_job_code' => $deletion_job_code, |
|
| 2348 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
| 2349 | - 'return_url' => urlencode($return_url), |
|
| 2350 | - ], |
|
| 2351 | - admin_url() |
|
| 2352 | - ) |
|
| 2353 | - ); |
|
| 2354 | - } |
|
| 2355 | - |
|
| 2356 | - |
|
| 2357 | - /** |
|
| 2358 | - * Checks for a POST submission |
|
| 2359 | - * |
|
| 2360 | - * @since 4.10.12.p |
|
| 2361 | - */ |
|
| 2362 | - protected function confirmDeletion() |
|
| 2363 | - { |
|
| 2364 | - $deletion_redirect_logic = |
|
| 2365 | - $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
| 2366 | - $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2367 | - } |
|
| 2368 | - |
|
| 2369 | - |
|
| 2370 | - /** |
|
| 2371 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2372 | - * |
|
| 2373 | - * @throws EE_Error |
|
| 2374 | - * @since 4.10.12.p |
|
| 2375 | - */ |
|
| 2376 | - protected function previewDeletion() |
|
| 2377 | - { |
|
| 2378 | - $preview_deletion_logic = |
|
| 2379 | - $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
| 2380 | - $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2381 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2382 | - } |
|
| 2383 | - |
|
| 2384 | - |
|
| 2385 | - /** |
|
| 2386 | - * get total number of events |
|
| 2387 | - * |
|
| 2388 | - * @access public |
|
| 2389 | - * @return int |
|
| 2390 | - * @throws EE_Error |
|
| 2391 | - * @throws InvalidArgumentException |
|
| 2392 | - * @throws InvalidDataTypeException |
|
| 2393 | - * @throws InvalidInterfaceException |
|
| 2394 | - */ |
|
| 2395 | - public function total_events() |
|
| 2396 | - { |
|
| 2397 | - return EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2398 | - } |
|
| 2399 | - |
|
| 2400 | - |
|
| 2401 | - /** |
|
| 2402 | - * get total number of draft events |
|
| 2403 | - * |
|
| 2404 | - * @access public |
|
| 2405 | - * @return int |
|
| 2406 | - * @throws EE_Error |
|
| 2407 | - * @throws InvalidArgumentException |
|
| 2408 | - * @throws InvalidDataTypeException |
|
| 2409 | - * @throws InvalidInterfaceException |
|
| 2410 | - */ |
|
| 2411 | - public function total_events_draft() |
|
| 2412 | - { |
|
| 2413 | - $where = [ |
|
| 2414 | - 'status' => ['IN', ['draft', 'auto-draft']], |
|
| 2415 | - ]; |
|
| 2416 | - return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2417 | - } |
|
| 2418 | - |
|
| 2419 | - |
|
| 2420 | - /** |
|
| 2421 | - * get total number of trashed events |
|
| 2422 | - * |
|
| 2423 | - * @access public |
|
| 2424 | - * @return int |
|
| 2425 | - * @throws EE_Error |
|
| 2426 | - * @throws InvalidArgumentException |
|
| 2427 | - * @throws InvalidDataTypeException |
|
| 2428 | - * @throws InvalidInterfaceException |
|
| 2429 | - */ |
|
| 2430 | - public function total_trashed_events() |
|
| 2431 | - { |
|
| 2432 | - $where = [ |
|
| 2433 | - 'status' => 'trash', |
|
| 2434 | - ]; |
|
| 2435 | - return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2436 | - } |
|
| 2437 | - |
|
| 2438 | - |
|
| 2439 | - /** |
|
| 2440 | - * _default_event_settings |
|
| 2441 | - * This generates the Default Settings Tab |
|
| 2442 | - * |
|
| 2443 | - * @return void |
|
| 2444 | - * @throws DomainException |
|
| 2445 | - * @throws EE_Error |
|
| 2446 | - * @throws InvalidArgumentException |
|
| 2447 | - * @throws InvalidDataTypeException |
|
| 2448 | - * @throws InvalidInterfaceException |
|
| 2449 | - */ |
|
| 2450 | - protected function _default_event_settings() |
|
| 2451 | - { |
|
| 2452 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2453 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2454 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2455 | - $this->display_admin_page_with_sidebar(); |
|
| 2456 | - } |
|
| 2457 | - |
|
| 2458 | - |
|
| 2459 | - /** |
|
| 2460 | - * Return the form for event settings. |
|
| 2461 | - * |
|
| 2462 | - * @return EE_Form_Section_Proper |
|
| 2463 | - * @throws EE_Error |
|
| 2464 | - */ |
|
| 2465 | - protected function _default_event_settings_form() |
|
| 2466 | - { |
|
| 2467 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2468 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2469 | - // exclude |
|
| 2470 | - [ |
|
| 2471 | - EEM_Registration::status_id_cancelled, |
|
| 2472 | - EEM_Registration::status_id_declined, |
|
| 2473 | - EEM_Registration::status_id_incomplete, |
|
| 2474 | - EEM_Registration::status_id_wait_list, |
|
| 2475 | - ], |
|
| 2476 | - true |
|
| 2477 | - ); |
|
| 2478 | - return new EE_Form_Section_Proper( |
|
| 2479 | - [ |
|
| 2480 | - 'name' => 'update_default_event_settings', |
|
| 2481 | - 'html_id' => 'update_default_event_settings', |
|
| 2482 | - 'html_class' => 'form-table', |
|
| 2483 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2484 | - 'subsections' => apply_filters( |
|
| 2485 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2486 | - [ |
|
| 2487 | - 'default_reg_status' => new EE_Select_Input( |
|
| 2488 | - $registration_stati_for_selection, |
|
| 2489 | - [ |
|
| 2490 | - 'default' => isset($registration_config->default_STS_ID) |
|
| 2491 | - && array_key_exists( |
|
| 2492 | - $registration_config->default_STS_ID, |
|
| 2493 | - $registration_stati_for_selection |
|
| 2494 | - ) |
|
| 2495 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2496 | - : EEM_Registration::status_id_pending_payment, |
|
| 2497 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2498 | - . EEH_Template::get_help_tab_link( |
|
| 2499 | - 'default_settings_status_help_tab' |
|
| 2500 | - ), |
|
| 2501 | - 'html_help_text' => esc_html__( |
|
| 2502 | - '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.', |
|
| 2503 | - 'event_espresso' |
|
| 2504 | - ), |
|
| 2505 | - ] |
|
| 2506 | - ), |
|
| 2507 | - 'default_max_tickets' => new EE_Integer_Input( |
|
| 2508 | - [ |
|
| 2509 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2510 | - ? $registration_config->default_maximum_number_of_tickets |
|
| 2511 | - : EEM_Event::get_default_additional_limit(), |
|
| 2512 | - 'html_label_text' => esc_html__( |
|
| 2513 | - 'Default Maximum Tickets Allowed Per Order:', |
|
| 2514 | - 'event_espresso' |
|
| 2515 | - ) |
|
| 2516 | - . EEH_Template::get_help_tab_link( |
|
| 2517 | - 'default_maximum_tickets_help_tab"' |
|
| 2518 | - ), |
|
| 2519 | - 'html_help_text' => esc_html__( |
|
| 2520 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2521 | - 'event_espresso' |
|
| 2522 | - ), |
|
| 2523 | - ] |
|
| 2524 | - ), |
|
| 2525 | - ] |
|
| 2526 | - ), |
|
| 2527 | - ] |
|
| 2528 | - ); |
|
| 2529 | - } |
|
| 2530 | - |
|
| 2531 | - |
|
| 2532 | - /** |
|
| 2533 | - * @return void |
|
| 2534 | - * @throws EE_Error |
|
| 2535 | - * @throws InvalidArgumentException |
|
| 2536 | - * @throws InvalidDataTypeException |
|
| 2537 | - * @throws InvalidInterfaceException |
|
| 2538 | - */ |
|
| 2539 | - protected function _update_default_event_settings() |
|
| 2540 | - { |
|
| 2541 | - $form = $this->_default_event_settings_form(); |
|
| 2542 | - if ($form->was_submitted()) { |
|
| 2543 | - $form->receive_form_submission(); |
|
| 2544 | - if ($form->is_valid()) { |
|
| 2545 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2546 | - $valid_data = $form->valid_data(); |
|
| 2547 | - if (isset($valid_data['default_reg_status'])) { |
|
| 2548 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2549 | - } |
|
| 2550 | - if (isset($valid_data['default_max_tickets'])) { |
|
| 2551 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2552 | - } |
|
| 2553 | - do_action( |
|
| 2554 | - 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
| 2555 | - $valid_data, |
|
| 2556 | - EE_Registry::instance()->CFG, |
|
| 2557 | - $this |
|
| 2558 | - ); |
|
| 2559 | - // update because data was valid! |
|
| 2560 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2561 | - EE_Error::overwrite_success(); |
|
| 2562 | - EE_Error::add_success( |
|
| 2563 | - __('Default Event Settings were updated', 'event_espresso') |
|
| 2564 | - ); |
|
| 2565 | - } |
|
| 2566 | - } |
|
| 2567 | - $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2568 | - } |
|
| 2569 | - |
|
| 2570 | - |
|
| 2571 | - /************* Templates ************* |
|
| 2572 | - * |
|
| 2573 | - * @throws EE_Error |
|
| 2574 | - */ |
|
| 2575 | - protected function _template_settings() |
|
| 2576 | - { |
|
| 2577 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2578 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2579 | - . EVENTS_ASSETS_URL |
|
| 2580 | - . '/images/' |
|
| 2581 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2582 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2583 | - . '" />'; |
|
| 2584 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 2585 | - . esc_html__( |
|
| 2586 | - '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.', |
|
| 2587 | - 'event_espresso' |
|
| 2588 | - ) . '</strong>'; |
|
| 2589 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2590 | - } |
|
| 2591 | - |
|
| 2592 | - |
|
| 2593 | - /** Event Category Stuff **/ |
|
| 2594 | - /** |
|
| 2595 | - * set the _category property with the category object for the loaded page. |
|
| 2596 | - * |
|
| 2597 | - * @access private |
|
| 2598 | - * @return void |
|
| 2599 | - */ |
|
| 2600 | - private function _set_category_object() |
|
| 2601 | - { |
|
| 2602 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2603 | - return; |
|
| 2604 | - } //already have the category object so get out. |
|
| 2605 | - // set default category object |
|
| 2606 | - $this->_set_empty_category_object(); |
|
| 2607 | - // only set if we've got an id |
|
| 2608 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2609 | - return; |
|
| 2610 | - } |
|
| 2611 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2612 | - $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2613 | - if (! empty($term)) { |
|
| 2614 | - $this->_category->category_name = $term->name; |
|
| 2615 | - $this->_category->category_identifier = $term->slug; |
|
| 2616 | - $this->_category->category_desc = $term->description; |
|
| 2617 | - $this->_category->id = $term->term_id; |
|
| 2618 | - $this->_category->parent = $term->parent; |
|
| 2619 | - } |
|
| 2620 | - } |
|
| 2621 | - |
|
| 2622 | - |
|
| 2623 | - /** |
|
| 2624 | - * Clears out category properties. |
|
| 2625 | - */ |
|
| 2626 | - private function _set_empty_category_object() |
|
| 2627 | - { |
|
| 2628 | - $this->_category = new stdClass(); |
|
| 2629 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2630 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2631 | - } |
|
| 2632 | - |
|
| 2633 | - |
|
| 2634 | - /** |
|
| 2635 | - * @throws DomainException |
|
| 2636 | - * @throws EE_Error |
|
| 2637 | - * @throws InvalidArgumentException |
|
| 2638 | - * @throws InvalidDataTypeException |
|
| 2639 | - * @throws InvalidInterfaceException |
|
| 2640 | - */ |
|
| 2641 | - protected function _category_list_table() |
|
| 2642 | - { |
|
| 2643 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2644 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2645 | - $this->_admin_page_title .= ' '; |
|
| 2646 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 2647 | - 'add_category', |
|
| 2648 | - 'add_category', |
|
| 2649 | - [], |
|
| 2650 | - 'add-new-h2' |
|
| 2651 | - ); |
|
| 2652 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2653 | - } |
|
| 2654 | - |
|
| 2655 | - |
|
| 2656 | - /** |
|
| 2657 | - * Output category details view. |
|
| 2658 | - * |
|
| 2659 | - * @param string $view |
|
| 2660 | - * @throws DomainException |
|
| 2661 | - * @throws EE_Error |
|
| 2662 | - * @throws InvalidArgumentException |
|
| 2663 | - * @throws InvalidDataTypeException |
|
| 2664 | - * @throws InvalidInterfaceException |
|
| 2665 | - */ |
|
| 2666 | - protected function _category_details($view) |
|
| 2667 | - { |
|
| 2668 | - // load formatter helper |
|
| 2669 | - // load field generator helper |
|
| 2670 | - $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
| 2671 | - $this->_set_add_edit_form_tags($route); |
|
| 2672 | - $this->_set_category_object(); |
|
| 2673 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2674 | - $delete_action = 'delete_category'; |
|
| 2675 | - // custom redirect |
|
| 2676 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2677 | - ['action' => 'category_list'], |
|
| 2678 | - $this->_admin_base_url |
|
| 2679 | - ); |
|
| 2680 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2681 | - // take care of contents |
|
| 2682 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2683 | - $this->display_admin_page_with_sidebar(); |
|
| 2684 | - } |
|
| 2685 | - |
|
| 2686 | - |
|
| 2687 | - /** |
|
| 2688 | - * Output category details content. |
|
| 2689 | - * |
|
| 2690 | - * @throws DomainException |
|
| 2691 | - */ |
|
| 2692 | - protected function _category_details_content() |
|
| 2693 | - { |
|
| 2694 | - $editor_args['category_desc'] = [ |
|
| 2695 | - 'type' => 'wp_editor', |
|
| 2696 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2697 | - 'class' => 'my_editor_custom', |
|
| 2698 | - 'wpeditor_args' => ['media_buttons' => false], |
|
| 2699 | - ]; |
|
| 2700 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2701 | - $all_terms = get_terms( |
|
| 2702 | - [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2703 | - ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2704 | - ); |
|
| 2705 | - // setup category select for term parents. |
|
| 2706 | - $category_select_values[] = [ |
|
| 2707 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2708 | - 'id' => 0, |
|
| 2709 | - ]; |
|
| 2710 | - foreach ($all_terms as $term) { |
|
| 2711 | - $category_select_values[] = [ |
|
| 2712 | - 'text' => $term->name, |
|
| 2713 | - 'id' => $term->term_id, |
|
| 2714 | - ]; |
|
| 2715 | - } |
|
| 2716 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2717 | - 'category_parent', |
|
| 2718 | - $category_select_values, |
|
| 2719 | - $this->_category->parent |
|
| 2720 | - ); |
|
| 2721 | - $template_args = [ |
|
| 2722 | - 'category' => $this->_category, |
|
| 2723 | - 'category_select' => $category_select, |
|
| 2724 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2725 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2726 | - 'disable' => '', |
|
| 2727 | - 'disabled_message' => false, |
|
| 2728 | - ]; |
|
| 2729 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2730 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2731 | - } |
|
| 2732 | - |
|
| 2733 | - |
|
| 2734 | - /** |
|
| 2735 | - * Handles deleting categories. |
|
| 2736 | - * |
|
| 2737 | - * @throws EE_Error |
|
| 2738 | - */ |
|
| 2739 | - protected function _delete_categories() |
|
| 2740 | - { |
|
| 2741 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2742 | - : (array) $this->_req_data['category_id']; |
|
| 2743 | - foreach ($cat_ids as $cat_id) { |
|
| 2744 | - $this->_delete_category($cat_id); |
|
| 2745 | - } |
|
| 2746 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2747 | - $query_args = [ |
|
| 2748 | - 'action' => 'category_list', |
|
| 2749 | - ]; |
|
| 2750 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2751 | - } |
|
| 2752 | - |
|
| 2753 | - |
|
| 2754 | - /** |
|
| 2755 | - * Handles deleting specific category. |
|
| 2756 | - * |
|
| 2757 | - * @param int $cat_id |
|
| 2758 | - */ |
|
| 2759 | - protected function _delete_category($cat_id) |
|
| 2760 | - { |
|
| 2761 | - $cat_id = absint($cat_id); |
|
| 2762 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2763 | - } |
|
| 2764 | - |
|
| 2765 | - |
|
| 2766 | - /** |
|
| 2767 | - * Handles triggering the update or insertion of a new category. |
|
| 2768 | - * |
|
| 2769 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2770 | - * @throws EE_Error |
|
| 2771 | - * @throws InvalidArgumentException |
|
| 2772 | - * @throws InvalidDataTypeException |
|
| 2773 | - * @throws InvalidInterfaceException |
|
| 2774 | - */ |
|
| 2775 | - protected function _insert_or_update_category($new_category) |
|
| 2776 | - { |
|
| 2777 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2778 | - $success = 0; // we already have a success message so lets not send another. |
|
| 2779 | - if ($cat_id) { |
|
| 2780 | - $query_args = [ |
|
| 2781 | - 'action' => 'edit_category', |
|
| 2782 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2783 | - ]; |
|
| 2784 | - } else { |
|
| 2785 | - $query_args = ['action' => 'add_category']; |
|
| 2786 | - } |
|
| 2787 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2788 | - } |
|
| 2789 | - |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * Inserts or updates category |
|
| 2793 | - * |
|
| 2794 | - * @param bool $update (true indicates we're updating a category). |
|
| 2795 | - * @return bool|mixed|string |
|
| 2796 | - */ |
|
| 2797 | - private function _insert_category($update = false) |
|
| 2798 | - { |
|
| 2799 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2800 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2801 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2802 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2803 | - if (empty($category_name)) { |
|
| 2804 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2805 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2806 | - return false; |
|
| 2807 | - } |
|
| 2808 | - $term_args = [ |
|
| 2809 | - 'name' => $category_name, |
|
| 2810 | - 'description' => $category_desc, |
|
| 2811 | - 'parent' => $category_parent, |
|
| 2812 | - ]; |
|
| 2813 | - // was the category_identifier input disabled? |
|
| 2814 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2815 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2816 | - } |
|
| 2817 | - $insert_ids = $update |
|
| 2818 | - ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2819 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2820 | - if (! is_array($insert_ids)) { |
|
| 2821 | - $msg = esc_html__( |
|
| 2822 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2823 | - 'event_espresso' |
|
| 2824 | - ); |
|
| 2825 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2826 | - } else { |
|
| 2827 | - $cat_id = $insert_ids['term_id']; |
|
| 2828 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2829 | - EE_Error::add_success($msg); |
|
| 2830 | - } |
|
| 2831 | - return $cat_id; |
|
| 2832 | - } |
|
| 2833 | - |
|
| 2834 | - |
|
| 2835 | - /** |
|
| 2836 | - * Gets categories or count of categories matching the arguments in the request. |
|
| 2837 | - * |
|
| 2838 | - * @param int $per_page |
|
| 2839 | - * @param int $current_page |
|
| 2840 | - * @param bool $count |
|
| 2841 | - * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
| 2842 | - * @throws EE_Error |
|
| 2843 | - * @throws InvalidArgumentException |
|
| 2844 | - * @throws InvalidDataTypeException |
|
| 2845 | - * @throws InvalidInterfaceException |
|
| 2846 | - */ |
|
| 2847 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2848 | - { |
|
| 2849 | - // testing term stuff |
|
| 2850 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2851 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2852 | - $limit = ($current_page - 1) * $per_page; |
|
| 2853 | - $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2854 | - if (isset($this->_req_data['s'])) { |
|
| 2855 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2856 | - $where['OR'] = [ |
|
| 2857 | - 'Term.name' => ['LIKE', $sstr], |
|
| 2858 | - 'description' => ['LIKE', $sstr], |
|
| 2859 | - ]; |
|
| 2860 | - } |
|
| 2861 | - $query_params = [ |
|
| 2862 | - $where, |
|
| 2863 | - 'order_by' => [$orderby => $order], |
|
| 2864 | - 'limit' => $limit . ',' . $per_page, |
|
| 2865 | - 'force_join' => ['Term'], |
|
| 2866 | - ]; |
|
| 2867 | - return $count |
|
| 2868 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2869 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2870 | - } |
|
| 2871 | - |
|
| 2872 | - /* end category stuff */ |
|
| 2873 | - |
|
| 2874 | - |
|
| 2875 | - /**************/ |
|
| 2876 | - |
|
| 2877 | - |
|
| 2878 | - /** |
|
| 2879 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 19 | + /** |
|
| 20 | + * This will hold the event object for event_details screen. |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @var EE_Event $_event |
|
| 24 | + */ |
|
| 25 | + protected $_event; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * This will hold the category object for category_details screen. |
|
| 30 | + * |
|
| 31 | + * @var stdClass $_category |
|
| 32 | + */ |
|
| 33 | + protected $_category; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * This will hold the event model instance |
|
| 38 | + * |
|
| 39 | + * @var EEM_Event $_event_model |
|
| 40 | + */ |
|
| 41 | + protected $_event_model; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var EE_Event |
|
| 46 | + */ |
|
| 47 | + protected $_cpt_model_obj = false; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var NodeGroupDao |
|
| 52 | + */ |
|
| 53 | + protected $model_obj_node_group_persister; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Initialize page props for this admin page group. |
|
| 58 | + */ |
|
| 59 | + protected function _init_page_props() |
|
| 60 | + { |
|
| 61 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 62 | + $this->page_label = EVENTS_LABEL; |
|
| 63 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 64 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 65 | + $this->_cpt_model_names = [ |
|
| 66 | + 'create_new' => 'EEM_Event', |
|
| 67 | + 'edit' => 'EEM_Event', |
|
| 68 | + ]; |
|
| 69 | + $this->_cpt_edit_routes = [ |
|
| 70 | + 'espresso_events' => 'edit', |
|
| 71 | + ]; |
|
| 72 | + add_action( |
|
| 73 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 74 | + [$this, 'verify_event_edit'], |
|
| 75 | + 10, |
|
| 76 | + 2 |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Sets the ajax hooks used for this admin page group. |
|
| 83 | + */ |
|
| 84 | + protected function _ajax_hooks() |
|
| 85 | + { |
|
| 86 | + add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Sets the page properties for this admin page group. |
|
| 92 | + */ |
|
| 93 | + protected function _define_page_props() |
|
| 94 | + { |
|
| 95 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 96 | + $this->_labels = [ |
|
| 97 | + 'buttons' => [ |
|
| 98 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 99 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 100 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 101 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 102 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 103 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 104 | + ], |
|
| 105 | + 'editor_title' => [ |
|
| 106 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 107 | + ], |
|
| 108 | + 'publishbox' => [ |
|
| 109 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 110 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 111 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 112 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 113 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 114 | + ], |
|
| 115 | + ]; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Sets the page routes property for this admin page group. |
|
| 121 | + */ |
|
| 122 | + protected function _set_page_routes() |
|
| 123 | + { |
|
| 124 | + // load formatter helper |
|
| 125 | + // load field generator helper |
|
| 126 | + // is there a evt_id in the request? |
|
| 127 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 128 | + ? $this->_req_data['EVT_ID'] |
|
| 129 | + : 0; |
|
| 130 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 131 | + $this->_page_routes = [ |
|
| 132 | + 'default' => [ |
|
| 133 | + 'func' => '_events_overview_list_table', |
|
| 134 | + 'capability' => 'ee_read_events', |
|
| 135 | + ], |
|
| 136 | + 'create_new' => [ |
|
| 137 | + 'func' => '_create_new_cpt_item', |
|
| 138 | + 'capability' => 'ee_edit_events', |
|
| 139 | + ], |
|
| 140 | + 'edit' => [ |
|
| 141 | + 'func' => '_edit_cpt_item', |
|
| 142 | + 'capability' => 'ee_edit_event', |
|
| 143 | + 'obj_id' => $evt_id, |
|
| 144 | + ], |
|
| 145 | + 'copy_event' => [ |
|
| 146 | + 'func' => '_copy_events', |
|
| 147 | + 'capability' => 'ee_edit_event', |
|
| 148 | + 'obj_id' => $evt_id, |
|
| 149 | + 'noheader' => true, |
|
| 150 | + ], |
|
| 151 | + 'trash_event' => [ |
|
| 152 | + 'func' => '_trash_or_restore_event', |
|
| 153 | + 'args' => ['event_status' => 'trash'], |
|
| 154 | + 'capability' => 'ee_delete_event', |
|
| 155 | + 'obj_id' => $evt_id, |
|
| 156 | + 'noheader' => true, |
|
| 157 | + ], |
|
| 158 | + 'trash_events' => [ |
|
| 159 | + 'func' => '_trash_or_restore_events', |
|
| 160 | + 'args' => ['event_status' => 'trash'], |
|
| 161 | + 'capability' => 'ee_delete_events', |
|
| 162 | + 'noheader' => true, |
|
| 163 | + ], |
|
| 164 | + 'restore_event' => [ |
|
| 165 | + 'func' => '_trash_or_restore_event', |
|
| 166 | + 'args' => ['event_status' => 'draft'], |
|
| 167 | + 'capability' => 'ee_delete_event', |
|
| 168 | + 'obj_id' => $evt_id, |
|
| 169 | + 'noheader' => true, |
|
| 170 | + ], |
|
| 171 | + 'restore_events' => [ |
|
| 172 | + 'func' => '_trash_or_restore_events', |
|
| 173 | + 'args' => ['event_status' => 'draft'], |
|
| 174 | + 'capability' => 'ee_delete_events', |
|
| 175 | + 'noheader' => true, |
|
| 176 | + ], |
|
| 177 | + 'delete_event' => [ |
|
| 178 | + 'func' => '_delete_event', |
|
| 179 | + 'capability' => 'ee_delete_event', |
|
| 180 | + 'obj_id' => $evt_id, |
|
| 181 | + 'noheader' => true, |
|
| 182 | + ], |
|
| 183 | + 'delete_events' => [ |
|
| 184 | + 'func' => '_delete_events', |
|
| 185 | + 'capability' => 'ee_delete_events', |
|
| 186 | + 'noheader' => true, |
|
| 187 | + ], |
|
| 188 | + 'view_report' => [ |
|
| 189 | + 'func' => '_view_report', |
|
| 190 | + 'capability' => 'ee_edit_events', |
|
| 191 | + ], |
|
| 192 | + 'default_event_settings' => [ |
|
| 193 | + 'func' => '_default_event_settings', |
|
| 194 | + 'capability' => 'manage_options', |
|
| 195 | + ], |
|
| 196 | + 'update_default_event_settings' => [ |
|
| 197 | + 'func' => '_update_default_event_settings', |
|
| 198 | + 'capability' => 'manage_options', |
|
| 199 | + 'noheader' => true, |
|
| 200 | + ], |
|
| 201 | + 'template_settings' => [ |
|
| 202 | + 'func' => '_template_settings', |
|
| 203 | + 'capability' => 'manage_options', |
|
| 204 | + ], |
|
| 205 | + // event category tab related |
|
| 206 | + 'add_category' => [ |
|
| 207 | + 'func' => '_category_details', |
|
| 208 | + 'capability' => 'ee_edit_event_category', |
|
| 209 | + 'args' => ['add'], |
|
| 210 | + ], |
|
| 211 | + 'edit_category' => [ |
|
| 212 | + 'func' => '_category_details', |
|
| 213 | + 'capability' => 'ee_edit_event_category', |
|
| 214 | + 'args' => ['edit'], |
|
| 215 | + ], |
|
| 216 | + 'delete_categories' => [ |
|
| 217 | + 'func' => '_delete_categories', |
|
| 218 | + 'capability' => 'ee_delete_event_category', |
|
| 219 | + 'noheader' => true, |
|
| 220 | + ], |
|
| 221 | + 'delete_category' => [ |
|
| 222 | + 'func' => '_delete_categories', |
|
| 223 | + 'capability' => 'ee_delete_event_category', |
|
| 224 | + 'noheader' => true, |
|
| 225 | + ], |
|
| 226 | + 'insert_category' => [ |
|
| 227 | + 'func' => '_insert_or_update_category', |
|
| 228 | + 'args' => ['new_category' => true], |
|
| 229 | + 'capability' => 'ee_edit_event_category', |
|
| 230 | + 'noheader' => true, |
|
| 231 | + ], |
|
| 232 | + 'update_category' => [ |
|
| 233 | + 'func' => '_insert_or_update_category', |
|
| 234 | + 'args' => ['new_category' => false], |
|
| 235 | + 'capability' => 'ee_edit_event_category', |
|
| 236 | + 'noheader' => true, |
|
| 237 | + ], |
|
| 238 | + 'category_list' => [ |
|
| 239 | + 'func' => '_category_list_table', |
|
| 240 | + 'capability' => 'ee_manage_event_categories', |
|
| 241 | + ], |
|
| 242 | + 'preview_deletion' => [ |
|
| 243 | + 'func' => 'previewDeletion', |
|
| 244 | + 'capability' => 'ee_delete_events', |
|
| 245 | + ], |
|
| 246 | + 'confirm_deletion' => [ |
|
| 247 | + 'func' => 'confirmDeletion', |
|
| 248 | + 'capability' => 'ee_delete_events', |
|
| 249 | + 'noheader' => true, |
|
| 250 | + ], |
|
| 251 | + ]; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Set the _page_config property for this admin page group. |
|
| 257 | + */ |
|
| 258 | + protected function _set_page_config() |
|
| 259 | + { |
|
| 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' => [ |
|
| 291 | + // 'Event_Overview_Help_Tour', |
|
| 292 | + // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 293 | + // ], |
|
| 294 | + 'require_nonce' => false, |
|
| 295 | + 'qtips' => ['EE_Event_List_Table_Tips'], |
|
| 296 | + ], |
|
| 297 | + 'create_new' => [ |
|
| 298 | + 'nav' => [ |
|
| 299 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 300 | + 'order' => 5, |
|
| 301 | + 'persistent' => false, |
|
| 302 | + ], |
|
| 303 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 304 | + 'help_tabs' => [ |
|
| 305 | + 'event_editor_help_tab' => [ |
|
| 306 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 307 | + 'filename' => 'event_editor', |
|
| 308 | + ], |
|
| 309 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 310 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 311 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 312 | + ], |
|
| 313 | + 'event_editor_venue_details_help_tab' => [ |
|
| 314 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 315 | + 'filename' => 'event_editor_venue_details', |
|
| 316 | + ], |
|
| 317 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 318 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 319 | + 'filename' => 'event_editor_event_datetimes', |
|
| 320 | + ], |
|
| 321 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 322 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 323 | + 'filename' => 'event_editor_event_tickets', |
|
| 324 | + ], |
|
| 325 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 326 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 327 | + 'filename' => 'event_editor_event_registration_options', |
|
| 328 | + ], |
|
| 329 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 330 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 331 | + 'filename' => 'event_editor_tags_categories', |
|
| 332 | + ], |
|
| 333 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 334 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 335 | + 'filename' => 'event_editor_questions_registrants', |
|
| 336 | + ], |
|
| 337 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 338 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 339 | + 'filename' => 'event_editor_save_new_event', |
|
| 340 | + ], |
|
| 341 | + 'event_editor_other_help_tab' => [ |
|
| 342 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 343 | + 'filename' => 'event_editor_other', |
|
| 344 | + ], |
|
| 345 | + ], |
|
| 346 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 347 | + // 'help_tour' => [ |
|
| 348 | + // 'Event_Editor_Help_Tour', |
|
| 349 | + // ], |
|
| 350 | + 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
| 351 | + 'require_nonce' => false, |
|
| 352 | + ], |
|
| 353 | + 'edit' => [ |
|
| 354 | + 'nav' => [ |
|
| 355 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 356 | + 'order' => 5, |
|
| 357 | + 'persistent' => false, |
|
| 358 | + 'url' => isset($this->_req_data['post']) |
|
| 359 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 360 | + ['post' => $this->_req_data['post'], 'action' => 'edit'], |
|
| 361 | + $this->_current_page_view_url |
|
| 362 | + ) |
|
| 363 | + : $this->_admin_base_url, |
|
| 364 | + ], |
|
| 365 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
| 366 | + 'help_tabs' => [ |
|
| 367 | + 'event_editor_help_tab' => [ |
|
| 368 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 369 | + 'filename' => 'event_editor', |
|
| 370 | + ], |
|
| 371 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
| 372 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 373 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 374 | + ], |
|
| 375 | + 'event_editor_venue_details_help_tab' => [ |
|
| 376 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 377 | + 'filename' => 'event_editor_venue_details', |
|
| 378 | + ], |
|
| 379 | + 'event_editor_event_datetimes_help_tab' => [ |
|
| 380 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 381 | + 'filename' => 'event_editor_event_datetimes', |
|
| 382 | + ], |
|
| 383 | + 'event_editor_event_tickets_help_tab' => [ |
|
| 384 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 385 | + 'filename' => 'event_editor_event_tickets', |
|
| 386 | + ], |
|
| 387 | + 'event_editor_event_registration_options_help_tab' => [ |
|
| 388 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 389 | + 'filename' => 'event_editor_event_registration_options', |
|
| 390 | + ], |
|
| 391 | + 'event_editor_tags_categories_help_tab' => [ |
|
| 392 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 393 | + 'filename' => 'event_editor_tags_categories', |
|
| 394 | + ], |
|
| 395 | + 'event_editor_questions_registrants_help_tab' => [ |
|
| 396 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 397 | + 'filename' => 'event_editor_questions_registrants', |
|
| 398 | + ], |
|
| 399 | + 'event_editor_save_new_event_help_tab' => [ |
|
| 400 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 401 | + 'filename' => 'event_editor_save_new_event', |
|
| 402 | + ], |
|
| 403 | + 'event_editor_other_help_tab' => [ |
|
| 404 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 405 | + 'filename' => 'event_editor_other', |
|
| 406 | + ], |
|
| 407 | + ], |
|
| 408 | + 'require_nonce' => false, |
|
| 409 | + ], |
|
| 410 | + 'default_event_settings' => [ |
|
| 411 | + 'nav' => [ |
|
| 412 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 413 | + 'order' => 40, |
|
| 414 | + ], |
|
| 415 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 416 | + 'labels' => [ |
|
| 417 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 418 | + ], |
|
| 419 | + 'help_tabs' => [ |
|
| 420 | + 'default_settings_help_tab' => [ |
|
| 421 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 422 | + 'filename' => 'events_default_settings', |
|
| 423 | + ], |
|
| 424 | + 'default_settings_status_help_tab' => [ |
|
| 425 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 426 | + 'filename' => 'events_default_settings_status', |
|
| 427 | + ], |
|
| 428 | + 'default_maximum_tickets_help_tab' => [ |
|
| 429 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 430 | + 'filename' => 'events_default_settings_max_tickets', |
|
| 431 | + ], |
|
| 432 | + ], |
|
| 433 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 434 | + // 'help_tour' => ['Event_Default_Settings_Help_Tour'], |
|
| 435 | + 'require_nonce' => false, |
|
| 436 | + ], |
|
| 437 | + // template settings |
|
| 438 | + 'template_settings' => [ |
|
| 439 | + 'nav' => [ |
|
| 440 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 441 | + 'order' => 30, |
|
| 442 | + ], |
|
| 443 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 444 | + 'help_tabs' => [ |
|
| 445 | + 'general_settings_templates_help_tab' => [ |
|
| 446 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 447 | + 'filename' => 'general_settings_templates', |
|
| 448 | + ], |
|
| 449 | + ], |
|
| 450 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 451 | + // 'help_tour' => ['Templates_Help_Tour'], |
|
| 452 | + 'require_nonce' => false, |
|
| 453 | + ], |
|
| 454 | + // event category stuff |
|
| 455 | + 'add_category' => [ |
|
| 456 | + 'nav' => [ |
|
| 457 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 458 | + 'order' => 15, |
|
| 459 | + 'persistent' => false, |
|
| 460 | + ], |
|
| 461 | + 'help_tabs' => [ |
|
| 462 | + 'add_category_help_tab' => [ |
|
| 463 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 464 | + 'filename' => 'events_add_category', |
|
| 465 | + ], |
|
| 466 | + ], |
|
| 467 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 468 | + // 'help_tour' => ['Event_Add_Category_Help_Tour'], |
|
| 469 | + 'metaboxes' => ['_publish_post_box'], |
|
| 470 | + 'require_nonce' => false, |
|
| 471 | + ], |
|
| 472 | + 'edit_category' => [ |
|
| 473 | + 'nav' => [ |
|
| 474 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 475 | + 'order' => 15, |
|
| 476 | + 'persistent' => false, |
|
| 477 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 478 | + ? add_query_arg( |
|
| 479 | + ['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']], |
|
| 480 | + $this->_current_page_view_url |
|
| 481 | + ) |
|
| 482 | + : $this->_admin_base_url, |
|
| 483 | + ], |
|
| 484 | + 'help_tabs' => [ |
|
| 485 | + 'edit_category_help_tab' => [ |
|
| 486 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 487 | + 'filename' => 'events_edit_category', |
|
| 488 | + ], |
|
| 489 | + ], |
|
| 490 | + /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/ |
|
| 491 | + 'metaboxes' => ['_publish_post_box'], |
|
| 492 | + 'require_nonce' => false, |
|
| 493 | + ], |
|
| 494 | + 'category_list' => [ |
|
| 495 | + 'nav' => [ |
|
| 496 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 497 | + 'order' => 20, |
|
| 498 | + ], |
|
| 499 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 500 | + 'help_tabs' => [ |
|
| 501 | + 'events_categories_help_tab' => [ |
|
| 502 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 503 | + 'filename' => 'events_categories', |
|
| 504 | + ], |
|
| 505 | + 'events_categories_table_column_headings_help_tab' => [ |
|
| 506 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 507 | + 'filename' => 'events_categories_table_column_headings', |
|
| 508 | + ], |
|
| 509 | + 'events_categories_view_help_tab' => [ |
|
| 510 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 511 | + 'filename' => 'events_categories_views', |
|
| 512 | + ], |
|
| 513 | + 'events_categories_other_help_tab' => [ |
|
| 514 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 515 | + 'filename' => 'events_categories_other', |
|
| 516 | + ], |
|
| 517 | + ], |
|
| 518 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 519 | + // 'help_tour' => [ |
|
| 520 | + // 'Event_Categories_Help_Tour', |
|
| 521 | + // ], |
|
| 522 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 523 | + 'require_nonce' => false, |
|
| 524 | + ], |
|
| 525 | + 'preview_deletion' => [ |
|
| 526 | + 'nav' => [ |
|
| 527 | + 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
| 528 | + 'order' => 15, |
|
| 529 | + 'persistent' => false, |
|
| 530 | + 'url' => '', |
|
| 531 | + ], |
|
| 532 | + 'require_nonce' => false, |
|
| 533 | + ], |
|
| 534 | + ]; |
|
| 535 | + // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated |
|
| 536 | + $domain = $this->loader->getShared('EventEspresso\core\domain\Domain'); |
|
| 537 | + if (! $domain->isCaffeinated()) { |
|
| 538 | + $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
|
| 539 | + $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
| 546 | + */ |
|
| 547 | + protected function _add_screen_options() |
|
| 548 | + { |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Implementing the screen options for the 'default' route. |
|
| 554 | + * |
|
| 555 | + * @throws InvalidArgumentException |
|
| 556 | + * @throws InvalidDataTypeException |
|
| 557 | + * @throws InvalidInterfaceException |
|
| 558 | + */ |
|
| 559 | + protected function _add_screen_options_default() |
|
| 560 | + { |
|
| 561 | + $this->_per_page_screen_option(); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Implementing screen options for the category list route. |
|
| 567 | + * |
|
| 568 | + * @throws InvalidArgumentException |
|
| 569 | + * @throws InvalidDataTypeException |
|
| 570 | + * @throws InvalidInterfaceException |
|
| 571 | + */ |
|
| 572 | + protected function _add_screen_options_category_list() |
|
| 573 | + { |
|
| 574 | + $page_title = $this->_admin_page_title; |
|
| 575 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 576 | + $this->_per_page_screen_option(); |
|
| 577 | + $this->_admin_page_title = $page_title; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Used to register any global feature pointers for the admin page group. |
|
| 583 | + */ |
|
| 584 | + protected function _add_feature_pointers() |
|
| 585 | + { |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
| 591 | + */ |
|
| 592 | + public function load_scripts_styles() |
|
| 593 | + { |
|
| 594 | + wp_register_style( |
|
| 595 | + 'events-admin-css', |
|
| 596 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 597 | + [], |
|
| 598 | + EVENT_ESPRESSO_VERSION |
|
| 599 | + ); |
|
| 600 | + wp_register_style( |
|
| 601 | + 'ee-cat-admin', |
|
| 602 | + EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 603 | + [], |
|
| 604 | + EVENT_ESPRESSO_VERSION |
|
| 605 | + ); |
|
| 606 | + wp_enqueue_style('events-admin-css'); |
|
| 607 | + wp_enqueue_style('ee-cat-admin'); |
|
| 608 | + // scripts |
|
| 609 | + wp_register_script( |
|
| 610 | + 'event_editor_js', |
|
| 611 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 612 | + ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
| 613 | + EVENT_ESPRESSO_VERSION, |
|
| 614 | + true |
|
| 615 | + ); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Enqueuing scripts and styles specific to this view |
|
| 621 | + */ |
|
| 622 | + public function load_scripts_styles_create_new() |
|
| 623 | + { |
|
| 624 | + $this->load_scripts_styles_edit(); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * Enqueuing scripts and styles specific to this view |
|
| 630 | + */ |
|
| 631 | + public function load_scripts_styles_edit() |
|
| 632 | + { |
|
| 633 | + // styles |
|
| 634 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 635 | + wp_register_style( |
|
| 636 | + 'event-editor-css', |
|
| 637 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 638 | + ['ee-admin-css'], |
|
| 639 | + EVENT_ESPRESSO_VERSION |
|
| 640 | + ); |
|
| 641 | + wp_enqueue_style('event-editor-css'); |
|
| 642 | + // scripts |
|
| 643 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
| 644 | + wp_register_script( |
|
| 645 | + 'event-datetime-metabox', |
|
| 646 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 647 | + ['event_editor_js', 'ee-datepicker'], |
|
| 648 | + EVENT_ESPRESSO_VERSION |
|
| 649 | + ); |
|
| 650 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * Populating the _views property for the category list table view. |
|
| 657 | + */ |
|
| 658 | + protected function _set_list_table_views_category_list() |
|
| 659 | + { |
|
| 660 | + $this->_views = [ |
|
| 661 | + 'all' => [ |
|
| 662 | + 'slug' => 'all', |
|
| 663 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 664 | + 'count' => 0, |
|
| 665 | + 'bulk_action' => [ |
|
| 666 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 667 | + ], |
|
| 668 | + ], |
|
| 669 | + ]; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
| 675 | + */ |
|
| 676 | + public function admin_init() |
|
| 677 | + { |
|
| 678 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 679 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 680 | + 'event_espresso' |
|
| 681 | + ); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
| 687 | + * group. |
|
| 688 | + */ |
|
| 689 | + public function admin_notices() |
|
| 690 | + { |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
| 696 | + * this admin page group. |
|
| 697 | + */ |
|
| 698 | + public function admin_footer_scripts() |
|
| 699 | + { |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 705 | + * warning (via EE_Error::add_error()); |
|
| 706 | + * |
|
| 707 | + * @param EE_Event $event Event object |
|
| 708 | + * @param string $req_type |
|
| 709 | + * @return void |
|
| 710 | + * @throws EE_Error |
|
| 711 | + * @access public |
|
| 712 | + */ |
|
| 713 | + public function verify_event_edit($event = null, $req_type = '') |
|
| 714 | + { |
|
| 715 | + // don't need to do this when processing |
|
| 716 | + if (! empty($req_type)) { |
|
| 717 | + return; |
|
| 718 | + } |
|
| 719 | + // no event? |
|
| 720 | + if (! $event instanceof EE_Event) { |
|
| 721 | + $event = $this->_cpt_model_obj; |
|
| 722 | + } |
|
| 723 | + // STILL no event? |
|
| 724 | + if (! $event instanceof EE_Event) { |
|
| 725 | + return; |
|
| 726 | + } |
|
| 727 | + $orig_status = $event->status(); |
|
| 728 | + // first check if event is active. |
|
| 729 | + if ( |
|
| 730 | + $orig_status === EEM_Event::cancelled |
|
| 731 | + || $orig_status === EEM_Event::postponed |
|
| 732 | + || $event->is_expired() |
|
| 733 | + || $event->is_inactive() |
|
| 734 | + ) { |
|
| 735 | + return; |
|
| 736 | + } |
|
| 737 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
| 738 | + if ($event->is_sold_out(true)) { |
|
| 739 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 740 | + EE_Error::add_attention( |
|
| 741 | + sprintf( |
|
| 742 | + esc_html__( |
|
| 743 | + '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.', |
|
| 744 | + 'event_espresso' |
|
| 745 | + ), |
|
| 746 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 747 | + ) |
|
| 748 | + ); |
|
| 749 | + } |
|
| 750 | + return; |
|
| 751 | + } |
|
| 752 | + if ($orig_status === EEM_Event::sold_out) { |
|
| 753 | + EE_Error::add_attention( |
|
| 754 | + sprintf( |
|
| 755 | + esc_html__( |
|
| 756 | + '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.', |
|
| 757 | + 'event_espresso' |
|
| 758 | + ), |
|
| 759 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 760 | + ) |
|
| 761 | + ); |
|
| 762 | + } |
|
| 763 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 764 | + if (! $event->tickets_on_sale()) { |
|
| 765 | + return; |
|
| 766 | + } |
|
| 767 | + // made it here so show warning |
|
| 768 | + $this->_edit_event_warning(); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 774 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 775 | + * |
|
| 776 | + * @access protected |
|
| 777 | + * @return void |
|
| 778 | + */ |
|
| 779 | + protected function _edit_event_warning() |
|
| 780 | + { |
|
| 781 | + // we don't want to add warnings during these requests |
|
| 782 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 783 | + return; |
|
| 784 | + } |
|
| 785 | + EE_Error::add_attention( |
|
| 786 | + sprintf( |
|
| 787 | + esc_html__( |
|
| 788 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
| 789 | + 'event_espresso' |
|
| 790 | + ), |
|
| 791 | + '<a class="espresso-help-tab-lnk">', |
|
| 792 | + '</a>' |
|
| 793 | + ) |
|
| 794 | + ); |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 800 | + * Otherwise, do the normal logic |
|
| 801 | + * |
|
| 802 | + * @return void |
|
| 803 | + * @throws EE_Error |
|
| 804 | + * @throws InvalidArgumentException |
|
| 805 | + * @throws InvalidDataTypeException |
|
| 806 | + * @throws InvalidInterfaceException |
|
| 807 | + */ |
|
| 808 | + protected function _create_new_cpt_item() |
|
| 809 | + { |
|
| 810 | + $has_timezone_string = get_option('timezone_string'); |
|
| 811 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 812 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 813 | + EE_Error::add_attention( |
|
| 814 | + sprintf( |
|
| 815 | + __( |
|
| 816 | + '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', |
|
| 817 | + 'event_espresso' |
|
| 818 | + ), |
|
| 819 | + '<br>', |
|
| 820 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
| 821 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
| 822 | + . '</select>', |
|
| 823 | + '<button class="button button-secondary timezone-submit">', |
|
| 824 | + '</button><span class="spinner"></span>' |
|
| 825 | + ), |
|
| 826 | + __FILE__, |
|
| 827 | + __FUNCTION__, |
|
| 828 | + __LINE__ |
|
| 829 | + ); |
|
| 830 | + } |
|
| 831 | + parent::_create_new_cpt_item(); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * Sets the _views property for the default route in this admin page group. |
|
| 837 | + */ |
|
| 838 | + protected function _set_list_table_views_default() |
|
| 839 | + { |
|
| 840 | + $this->_views = [ |
|
| 841 | + 'all' => [ |
|
| 842 | + 'slug' => 'all', |
|
| 843 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 844 | + 'count' => 0, |
|
| 845 | + 'bulk_action' => [ |
|
| 846 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 847 | + ], |
|
| 848 | + ], |
|
| 849 | + 'draft' => [ |
|
| 850 | + 'slug' => 'draft', |
|
| 851 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 852 | + 'count' => 0, |
|
| 853 | + 'bulk_action' => [ |
|
| 854 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 855 | + ], |
|
| 856 | + ], |
|
| 857 | + ]; |
|
| 858 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 859 | + $this->_views['trash'] = [ |
|
| 860 | + 'slug' => 'trash', |
|
| 861 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 862 | + 'count' => 0, |
|
| 863 | + 'bulk_action' => [ |
|
| 864 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 865 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 866 | + ], |
|
| 867 | + ]; |
|
| 868 | + } |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * Provides the legend item array for the default list table view. |
|
| 874 | + * |
|
| 875 | + * @return array |
|
| 876 | + */ |
|
| 877 | + protected function _event_legend_items() |
|
| 878 | + { |
|
| 879 | + $items = [ |
|
| 880 | + 'view_details' => [ |
|
| 881 | + 'class' => 'dashicons dashicons-search', |
|
| 882 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 883 | + ], |
|
| 884 | + 'edit_event' => [ |
|
| 885 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 886 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 887 | + ], |
|
| 888 | + 'view_attendees' => [ |
|
| 889 | + 'class' => 'dashicons dashicons-groups', |
|
| 890 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 891 | + ], |
|
| 892 | + ]; |
|
| 893 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 894 | + $statuses = [ |
|
| 895 | + 'sold_out_status' => [ |
|
| 896 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 897 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 898 | + ], |
|
| 899 | + 'active_status' => [ |
|
| 900 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 901 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 902 | + ], |
|
| 903 | + 'upcoming_status' => [ |
|
| 904 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 905 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 906 | + ], |
|
| 907 | + 'postponed_status' => [ |
|
| 908 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 909 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 910 | + ], |
|
| 911 | + 'cancelled_status' => [ |
|
| 912 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 913 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 914 | + ], |
|
| 915 | + 'expired_status' => [ |
|
| 916 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 917 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 918 | + ], |
|
| 919 | + 'inactive_status' => [ |
|
| 920 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 921 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 922 | + ], |
|
| 923 | + ]; |
|
| 924 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 925 | + return array_merge($items, $statuses); |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + /** |
|
| 930 | + * @return EEM_Event |
|
| 931 | + * @throws EE_Error |
|
| 932 | + * @throws InvalidArgumentException |
|
| 933 | + * @throws InvalidDataTypeException |
|
| 934 | + * @throws InvalidInterfaceException |
|
| 935 | + * @throws ReflectionException |
|
| 936 | + */ |
|
| 937 | + private function _event_model() |
|
| 938 | + { |
|
| 939 | + if (! $this->_event_model instanceof EEM_Event) { |
|
| 940 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 941 | + } |
|
| 942 | + return $this->_event_model; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 948 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 949 | + * |
|
| 950 | + * @param string $return the current html |
|
| 951 | + * @param int $id the post id for the page |
|
| 952 | + * @param string $new_title What the title is |
|
| 953 | + * @param string $new_slug what the slug is |
|
| 954 | + * @return string The new html string for the permalink area |
|
| 955 | + */ |
|
| 956 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 957 | + { |
|
| 958 | + // make sure this is only when editing |
|
| 959 | + if (! empty($id)) { |
|
| 960 | + $post = get_post($id); |
|
| 961 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 962 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 963 | + . '</a> '; |
|
| 964 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 965 | + . $post->ID |
|
| 966 | + . ']">'; |
|
| 967 | + } |
|
| 968 | + return $return; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + |
|
| 972 | + /** |
|
| 973 | + * _events_overview_list_table |
|
| 974 | + * This contains the logic for showing the events_overview list |
|
| 975 | + * |
|
| 976 | + * @access protected |
|
| 977 | + * @return void |
|
| 978 | + * @throws DomainException |
|
| 979 | + * @throws EE_Error |
|
| 980 | + * @throws InvalidArgumentException |
|
| 981 | + * @throws InvalidDataTypeException |
|
| 982 | + * @throws InvalidInterfaceException |
|
| 983 | + */ |
|
| 984 | + protected function _events_overview_list_table() |
|
| 985 | + { |
|
| 986 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 987 | + $after_list_table = []; |
|
| 988 | + $after_list_table['view_event_list_button'] = EEH_HTML::br(); |
|
| 989 | + $after_list_table['view_event_list_button'] .= EEH_Template::get_button_or_link( |
|
| 990 | + get_post_type_archive_link('espresso_events'), |
|
| 991 | + esc_html__('View Event Archive Page', 'event_espresso'), |
|
| 992 | + 'button' |
|
| 993 | + ); |
|
| 994 | + $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 995 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 996 | + 'create_new', |
|
| 997 | + 'add', |
|
| 998 | + [], |
|
| 999 | + 'add-new-h2' |
|
| 1000 | + ); |
|
| 1001 | + $this->_template_args['after_list_table'] = array_merge( |
|
| 1002 | + (array) $this->_template_args['after_list_table'], |
|
| 1003 | + $after_list_table |
|
| 1004 | + ); |
|
| 1005 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + |
|
| 1009 | + /** |
|
| 1010 | + * this allows for extra misc actions in the default WP publish box |
|
| 1011 | + * |
|
| 1012 | + * @return void |
|
| 1013 | + * @throws DomainException |
|
| 1014 | + * @throws EE_Error |
|
| 1015 | + * @throws InvalidArgumentException |
|
| 1016 | + * @throws InvalidDataTypeException |
|
| 1017 | + * @throws InvalidInterfaceException |
|
| 1018 | + * @throws ReflectionException |
|
| 1019 | + */ |
|
| 1020 | + public function extra_misc_actions_publish_box() |
|
| 1021 | + { |
|
| 1022 | + $this->_generate_publish_box_extra_content(); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 1028 | + * saved. |
|
| 1029 | + * Typically you would use this to save any additional data. |
|
| 1030 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 1031 | + * ALSO very important. When a post transitions from scheduled to published, |
|
| 1032 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
| 1033 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
| 1034 | + * |
|
| 1035 | + * @access protected |
|
| 1036 | + * @abstract |
|
| 1037 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 1038 | + * @param object $post The post object of the cpt that was saved. |
|
| 1039 | + * @return void |
|
| 1040 | + * @throws EE_Error |
|
| 1041 | + * @throws InvalidArgumentException |
|
| 1042 | + * @throws InvalidDataTypeException |
|
| 1043 | + * @throws InvalidInterfaceException |
|
| 1044 | + * @throws ReflectionException |
|
| 1045 | + */ |
|
| 1046 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 1047 | + { |
|
| 1048 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 1049 | + // get out we're not processing an event save. |
|
| 1050 | + return; |
|
| 1051 | + } |
|
| 1052 | + $event_values = [ |
|
| 1053 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 1054 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 1055 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 1056 | + ? sanitize_text_field($this->_req_data['timezone_string']) |
|
| 1057 | + : null, |
|
| 1058 | + ]; |
|
| 1059 | + // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
| 1060 | + if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1061 | + $event_values['EVT_display_ticket_selector'] = |
|
| 1062 | + ! empty($this->_req_data['display_ticket_selector']) |
|
| 1063 | + ? 1 |
|
| 1064 | + : 0; |
|
| 1065 | + $event_values['EVT_additional_limit'] = min( |
|
| 1066 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 1067 | + ! empty($this->_req_data['additional_limit']) |
|
| 1068 | + ? absint($this->_req_data['additional_limit']) |
|
| 1069 | + : null |
|
| 1070 | + ); |
|
| 1071 | + $event_values['EVT_default_registration_status'] = |
|
| 1072 | + ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 1073 | + ? sanitize_text_field($this->_req_data['EVT_default_registration_status']) |
|
| 1074 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 1075 | + $event_values['EVT_external_URL'] = ! empty($this->_req_data['externalURL']) |
|
| 1076 | + ? esc_url_raw($this->_req_data['externalURL']) |
|
| 1077 | + : null; |
|
| 1078 | + $event_values['EVT_phone'] = ! empty($this->_req_data['event_phone']) |
|
| 1079 | + ? sanitize_text_field($this->_req_data['event_phone']) |
|
| 1080 | + : null; |
|
| 1081 | + } |
|
| 1082 | + // update event |
|
| 1083 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 1084 | + // get event_object for other metaboxes... |
|
| 1085 | + // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
| 1086 | + // i have to setup where conditions to override the filters in the model that filter out autodraft |
|
| 1087 | + // and inherit statuses so we GET the inherit id! |
|
| 1088 | + $get_one_where = [ |
|
| 1089 | + $this->_event_model()->primary_key_name() => $post_id, |
|
| 1090 | + 'OR' => [ |
|
| 1091 | + 'status' => $post->post_status, |
|
| 1092 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
| 1093 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
| 1094 | + 'status*1' => $this->_req_data['original_post_status'], |
|
| 1095 | + ], |
|
| 1096 | + ]; |
|
| 1097 | + $event = $this->_event_model()->get_one([$get_one_where]); |
|
| 1098 | + // the following are default callbacks for event attachment updates |
|
| 1099 | + // that can be overridden by caffeinated functionality and/or addons. |
|
| 1100 | + $event_update_callbacks = apply_filters( |
|
| 1101 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 1102 | + [ |
|
| 1103 | + [$this, '_default_venue_update'], |
|
| 1104 | + [$this, '_default_tickets_update'], |
|
| 1105 | + ] |
|
| 1106 | + ); |
|
| 1107 | + $att_success = true; |
|
| 1108 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 1109 | + $_success = is_callable($e_callback) |
|
| 1110 | + ? $e_callback($event, $this->_req_data) |
|
| 1111 | + : false; |
|
| 1112 | + // if ANY of these updates fail then we want the appropriate global error message |
|
| 1113 | + $att_success = ! $att_success ? $att_success : $_success; |
|
| 1114 | + } |
|
| 1115 | + // any errors? |
|
| 1116 | + if ($success && false === $att_success) { |
|
| 1117 | + EE_Error::add_error( |
|
| 1118 | + esc_html__( |
|
| 1119 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1120 | + 'event_espresso' |
|
| 1121 | + ), |
|
| 1122 | + __FILE__, |
|
| 1123 | + __FUNCTION__, |
|
| 1124 | + __LINE__ |
|
| 1125 | + ); |
|
| 1126 | + } elseif ($success === false) { |
|
| 1127 | + EE_Error::add_error( |
|
| 1128 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1129 | + __FILE__, |
|
| 1130 | + __FUNCTION__, |
|
| 1131 | + __LINE__ |
|
| 1132 | + ); |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * @param int $post_id |
|
| 1139 | + * @param int $revision_id |
|
| 1140 | + * @throws EE_Error |
|
| 1141 | + * @throws InvalidArgumentException |
|
| 1142 | + * @throws InvalidDataTypeException |
|
| 1143 | + * @throws InvalidInterfaceException |
|
| 1144 | + * @throws ReflectionException |
|
| 1145 | + * @see parent::restore_item() |
|
| 1146 | + */ |
|
| 1147 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1148 | + { |
|
| 1149 | + // copy existing event meta to new post |
|
| 1150 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1151 | + if ($post_evt instanceof EE_Event) { |
|
| 1152 | + // meta revision restore |
|
| 1153 | + $post_evt->restore_revision($revision_id); |
|
| 1154 | + // related objs restore |
|
| 1155 | + $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + |
|
| 1160 | + /** |
|
| 1161 | + * Attach the venue to the Event |
|
| 1162 | + * |
|
| 1163 | + * @param EE_Event $evtobj Event Object to add the venue to |
|
| 1164 | + * @param array $data The request data from the form |
|
| 1165 | + * @return bool Success or fail. |
|
| 1166 | + * @throws EE_Error |
|
| 1167 | + * @throws InvalidArgumentException |
|
| 1168 | + * @throws InvalidDataTypeException |
|
| 1169 | + * @throws InvalidInterfaceException |
|
| 1170 | + * @throws ReflectionException |
|
| 1171 | + */ |
|
| 1172 | + protected function _default_venue_update(EE_Event $evtobj, $data) |
|
| 1173 | + { |
|
| 1174 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1175 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1176 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1177 | + // very important. If we don't have a venue name... |
|
| 1178 | + // then we'll get out because not necessary to create empty venue |
|
| 1179 | + if (empty($data['venue_title'])) { |
|
| 1180 | + return false; |
|
| 1181 | + } |
|
| 1182 | + $venue_array = [ |
|
| 1183 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1184 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1185 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1186 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1187 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1188 | + : null, |
|
| 1189 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1190 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1191 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1192 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1193 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1194 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1195 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1196 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1197 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1198 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1199 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1200 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1201 | + 'status' => 'publish', |
|
| 1202 | + ]; |
|
| 1203 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1204 | + if (! empty($venue_id)) { |
|
| 1205 | + $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
| 1206 | + $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
| 1207 | + // we've gotta make sure that the venue is always attached to a revision.. |
|
| 1208 | + // add_relation_to should take care of making sure that the relation is already present. |
|
| 1209 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1210 | + return $rows_affected > 0; |
|
| 1211 | + } |
|
| 1212 | + // we insert the venue |
|
| 1213 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1214 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1215 | + return ! empty($venue_id); |
|
| 1216 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + |
|
| 1220 | + /** |
|
| 1221 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1222 | + * |
|
| 1223 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1224 | + * @param array $data The request data from the form |
|
| 1225 | + * @return array |
|
| 1226 | + * @throws EE_Error |
|
| 1227 | + * @throws InvalidArgumentException |
|
| 1228 | + * @throws InvalidDataTypeException |
|
| 1229 | + * @throws InvalidInterfaceException |
|
| 1230 | + * @throws ReflectionException |
|
| 1231 | + * @throws Exception |
|
| 1232 | + */ |
|
| 1233 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1234 | + { |
|
| 1235 | + if ($this->admin_config->useAdvancedEditor()) { |
|
| 1236 | + return []; |
|
| 1237 | + } |
|
| 1238 | + $success = true; |
|
| 1239 | + $saved_dtt = null; |
|
| 1240 | + $saved_tickets = []; |
|
| 1241 | + $incoming_date_formats = ['Y-m-d', 'h:i a']; |
|
| 1242 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1243 | + // trim all values to ensure any excess whitespace is removed. |
|
| 1244 | + $dtt = array_map('trim', $dtt); |
|
| 1245 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1246 | + : $dtt['DTT_EVT_start']; |
|
| 1247 | + $datetime_values = [ |
|
| 1248 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1249 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1250 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1251 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1252 | + 'DTT_order' => $row, |
|
| 1253 | + ]; |
|
| 1254 | + // if we have an id then let's get existing object first and then set the new values. |
|
| 1255 | + // Otherwise we instantiate a new object for save. |
|
| 1256 | + if (! empty($dtt['DTT_ID'])) { |
|
| 1257 | + $DTM = EE_Registry::instance() |
|
| 1258 | + ->load_model('Datetime', [$evtobj->get_timezone()]) |
|
| 1259 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1260 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1261 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1262 | + foreach ($datetime_values as $field => $value) { |
|
| 1263 | + $DTM->set($field, $value); |
|
| 1264 | + } |
|
| 1265 | + // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it. |
|
| 1266 | + // We need to do this so we dont' TRASH the parent DTT. |
|
| 1267 | + $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1268 | + } else { |
|
| 1269 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1270 | + 'Datetime', |
|
| 1271 | + [$datetime_values, $evtobj->get_timezone(), $incoming_date_formats], |
|
| 1272 | + false, |
|
| 1273 | + false |
|
| 1274 | + ); |
|
| 1275 | + foreach ($datetime_values as $field => $value) { |
|
| 1276 | + $DTM->set($field, $value); |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + $DTM->save(); |
|
| 1280 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1281 | + // load DTT helper |
|
| 1282 | + // before going any further make sure our dates are setup correctly |
|
| 1283 | + // so that the end date is always equal or greater than the start date. |
|
| 1284 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1285 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1286 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1287 | + $DTT->save(); |
|
| 1288 | + } |
|
| 1289 | + // now we got to make sure we add the new DTT_ID to the $saved_dtts array |
|
| 1290 | + // because it is possible there was a new one created for the autosave. |
|
| 1291 | + $saved_dtt = $DTT; |
|
| 1292 | + $success = ! $success ? $success : $DTT; |
|
| 1293 | + // if ANY of these updates fail then we want the appropriate global error message. |
|
| 1294 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1295 | + } |
|
| 1296 | + // no dtts get deleted so we don't do any of that logic here. |
|
| 1297 | + // update tickets next |
|
| 1298 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
| 1299 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1300 | + $incoming_date_formats = ['Y-m-d', 'h:i a']; |
|
| 1301 | + $update_prices = false; |
|
| 1302 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1303 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1304 | + : 0; |
|
| 1305 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1306 | + $tkt = array_map('trim', $tkt); |
|
| 1307 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1308 | + // let's use now in the set timezone. |
|
| 1309 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1310 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1311 | + } |
|
| 1312 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1313 | + // use the start date of the first datetime |
|
| 1314 | + $dtt = $evtobj->first_datetime(); |
|
| 1315 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1316 | + $incoming_date_formats[0], |
|
| 1317 | + $incoming_date_formats[1] |
|
| 1318 | + ); |
|
| 1319 | + } |
|
| 1320 | + $TKT_values = [ |
|
| 1321 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1322 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1323 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1324 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1325 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1326 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1327 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1328 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1329 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1330 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1331 | + 'TKT_row' => $row, |
|
| 1332 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1333 | + 'TKT_price' => $ticket_price, |
|
| 1334 | + ]; |
|
| 1335 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 1336 | + // which means in turn that the prices will become new prices as well. |
|
| 1337 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1338 | + $TKT_values['TKT_ID'] = 0; |
|
| 1339 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1340 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1341 | + $update_prices = true; |
|
| 1342 | + } |
|
| 1343 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1344 | + // we actually do our saves a head of doing any add_relations to because its entirely possible |
|
| 1345 | + // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1346 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 1347 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1348 | + if (! empty($tkt['TKT_ID'])) { |
|
| 1349 | + $TKT = EE_Registry::instance() |
|
| 1350 | + ->load_model('Ticket', [$evtobj->get_timezone()]) |
|
| 1351 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1352 | + if ($TKT instanceof EE_Ticket) { |
|
| 1353 | + $ticket_sold = $TKT->count_related( |
|
| 1354 | + 'Registration', |
|
| 1355 | + [ |
|
| 1356 | + [ |
|
| 1357 | + 'STS_ID' => [ |
|
| 1358 | + 'NOT IN', |
|
| 1359 | + [EEM_Registration::status_id_incomplete], |
|
| 1360 | + ], |
|
| 1361 | + ], |
|
| 1362 | + ] |
|
| 1363 | + ) > 0; |
|
| 1364 | + // let's just check the total price for the existing ticket and determine if it matches the new |
|
| 1365 | + // total price. if they are different then we create a new ticket (if tickets sold) |
|
| 1366 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 1367 | + $create_new_TKT = $ticket_sold |
|
| 1368 | + && ! $TKT->deleted() |
|
| 1369 | + && EEH_Money::compare_floats( |
|
| 1370 | + $ticket_price, |
|
| 1371 | + $TKT->get('TKT_price'), |
|
| 1372 | + '!==' |
|
| 1373 | + ); |
|
| 1374 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1375 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1376 | + // set new values |
|
| 1377 | + foreach ($TKT_values as $field => $value) { |
|
| 1378 | + if ($field === 'TKT_qty') { |
|
| 1379 | + $TKT->set_qty($value); |
|
| 1380 | + } else { |
|
| 1381 | + $TKT->set($field, $value); |
|
| 1382 | + } |
|
| 1383 | + } |
|
| 1384 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 1385 | + // Otherwise we have to create a new ticket. |
|
| 1386 | + if ($create_new_TKT) { |
|
| 1387 | + // archive the old ticket first |
|
| 1388 | + $TKT->set('TKT_deleted', 1); |
|
| 1389 | + $TKT->save(); |
|
| 1390 | + // make sure this ticket is still recorded in our saved_tkts |
|
| 1391 | + // so we don't run it through the regular trash routine. |
|
| 1392 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1393 | + // create new ticket that's a copy of the existing except a new id of course |
|
| 1394 | + // (and not archived) AND has the new TKT_price associated with it. |
|
| 1395 | + $TKT = clone $TKT; |
|
| 1396 | + $TKT->set('TKT_ID', 0); |
|
| 1397 | + $TKT->set('TKT_deleted', 0); |
|
| 1398 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1399 | + $TKT->set('TKT_sold', 0); |
|
| 1400 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1401 | + $update_prices = true; |
|
| 1402 | + } |
|
| 1403 | + // make sure price is set if it hasn't been already |
|
| 1404 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1405 | + } |
|
| 1406 | + } else { |
|
| 1407 | + // no TKT_id so a new TKT |
|
| 1408 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1409 | + $TKT = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false); |
|
| 1410 | + if ($TKT instanceof EE_Ticket) { |
|
| 1411 | + // need to reset values to properly account for the date formats |
|
| 1412 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1413 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1414 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1415 | + // set new values |
|
| 1416 | + foreach ($TKT_values as $field => $value) { |
|
| 1417 | + if ($field === 'TKT_qty') { |
|
| 1418 | + $TKT->set_qty($value); |
|
| 1419 | + } else { |
|
| 1420 | + $TKT->set($field, $value); |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + $update_prices = true; |
|
| 1424 | + } |
|
| 1425 | + } |
|
| 1426 | + // cap ticket qty by datetime reg limits |
|
| 1427 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1428 | + // update ticket. |
|
| 1429 | + $TKT->save(); |
|
| 1430 | + // before going any further make sure our dates are setup correctly |
|
| 1431 | + // so that the end date is always equal or greater than the start date. |
|
| 1432 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1433 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1434 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1435 | + $TKT->save(); |
|
| 1436 | + } |
|
| 1437 | + // initially let's add the ticket to the dtt |
|
| 1438 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1439 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1440 | + // add prices to ticket |
|
| 1441 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1442 | + } |
|
| 1443 | + // however now we need to handle permanently deleting tickets via the ui. |
|
| 1444 | + // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
| 1445 | + // However, it does allow for deleting tickets that have no tickets sold, |
|
| 1446 | + // in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1447 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
| 1448 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1449 | + foreach ($tickets_removed as $id) { |
|
| 1450 | + $id = absint($id); |
|
| 1451 | + // get the ticket for this id |
|
| 1452 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1453 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 1454 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1455 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1456 | + foreach ($dtts as $dtt) { |
|
| 1457 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1458 | + } |
|
| 1459 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 1460 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1461 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1462 | + // finally let's delete this ticket |
|
| 1463 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1464 | + $tkt_to_remove->delete_permanently(); |
|
| 1465 | + } |
|
| 1466 | + return [$saved_dtt, $saved_tickets]; |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * This attaches a list of given prices to a ticket. |
|
| 1472 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) |
|
| 1473 | + * because if there is a change in price information on a ticket, a new ticket is created anyways |
|
| 1474 | + * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. |
|
| 1475 | + * |
|
| 1476 | + * @access private |
|
| 1477 | + * @param array $prices Array of prices from the form. |
|
| 1478 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1479 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1480 | + * @return void |
|
| 1481 | + * @throws EE_Error |
|
| 1482 | + * @throws InvalidArgumentException |
|
| 1483 | + * @throws InvalidDataTypeException |
|
| 1484 | + * @throws InvalidInterfaceException |
|
| 1485 | + * @throws ReflectionException |
|
| 1486 | + */ |
|
| 1487 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1488 | + { |
|
| 1489 | + foreach ($prices as $row => $prc) { |
|
| 1490 | + $PRC_values = [ |
|
| 1491 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1492 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1493 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1494 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1495 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1496 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
| 1497 | + 'PRC_order' => $row, |
|
| 1498 | + ]; |
|
| 1499 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1500 | + $PRC_values['PRC_ID'] = 0; |
|
| 1501 | + $PRC = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false); |
|
| 1502 | + } else { |
|
| 1503 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1504 | + // update this price with new values |
|
| 1505 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1506 | + $PRC->set($field, $newprc); |
|
| 1507 | + } |
|
| 1508 | + $PRC->save(); |
|
| 1509 | + } |
|
| 1510 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1511 | + } |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + |
|
| 1515 | + /** |
|
| 1516 | + * Add in our autosave ajax handlers |
|
| 1517 | + * |
|
| 1518 | + */ |
|
| 1519 | + protected function _ee_autosave_create_new() |
|
| 1520 | + { |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + |
|
| 1524 | + /** |
|
| 1525 | + * More autosave handlers. |
|
| 1526 | + */ |
|
| 1527 | + protected function _ee_autosave_edit() |
|
| 1528 | + { |
|
| 1529 | + } |
|
| 1530 | + |
|
| 1531 | + |
|
| 1532 | + /** |
|
| 1533 | + * _generate_publish_box_extra_content |
|
| 1534 | + * |
|
| 1535 | + * @throws DomainException |
|
| 1536 | + * @throws EE_Error |
|
| 1537 | + * @throws InvalidArgumentException |
|
| 1538 | + * @throws InvalidDataTypeException |
|
| 1539 | + * @throws InvalidInterfaceException |
|
| 1540 | + * @throws ReflectionException |
|
| 1541 | + */ |
|
| 1542 | + private function _generate_publish_box_extra_content() |
|
| 1543 | + { |
|
| 1544 | + // load formatter helper |
|
| 1545 | + // args for getting related registrations |
|
| 1546 | + $approved_query_args = [ |
|
| 1547 | + [ |
|
| 1548 | + 'REG_deleted' => 0, |
|
| 1549 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1550 | + ], |
|
| 1551 | + ]; |
|
| 1552 | + $not_approved_query_args = [ |
|
| 1553 | + [ |
|
| 1554 | + 'REG_deleted' => 0, |
|
| 1555 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1556 | + ], |
|
| 1557 | + ]; |
|
| 1558 | + $pending_payment_query_args = [ |
|
| 1559 | + [ |
|
| 1560 | + 'REG_deleted' => 0, |
|
| 1561 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1562 | + ], |
|
| 1563 | + ]; |
|
| 1564 | + // publish box |
|
| 1565 | + $publish_box_extra_args = [ |
|
| 1566 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1567 | + [ |
|
| 1568 | + 'action' => 'default', |
|
| 1569 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1570 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1571 | + ], |
|
| 1572 | + REG_ADMIN_URL |
|
| 1573 | + ), |
|
| 1574 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1575 | + [ |
|
| 1576 | + 'action' => 'default', |
|
| 1577 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1578 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1579 | + ], |
|
| 1580 | + REG_ADMIN_URL |
|
| 1581 | + ), |
|
| 1582 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1583 | + [ |
|
| 1584 | + 'action' => 'default', |
|
| 1585 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1586 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1587 | + ], |
|
| 1588 | + REG_ADMIN_URL |
|
| 1589 | + ), |
|
| 1590 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1591 | + 'Registration', |
|
| 1592 | + $approved_query_args |
|
| 1593 | + ), |
|
| 1594 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1595 | + 'Registration', |
|
| 1596 | + $not_approved_query_args |
|
| 1597 | + ), |
|
| 1598 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1599 | + 'Registration', |
|
| 1600 | + $pending_payment_query_args |
|
| 1601 | + ), |
|
| 1602 | + 'misc_pub_section_class' => apply_filters( |
|
| 1603 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1604 | + 'misc-pub-section' |
|
| 1605 | + ), |
|
| 1606 | + ]; |
|
| 1607 | + ob_start(); |
|
| 1608 | + do_action( |
|
| 1609 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1610 | + $this->_cpt_model_obj |
|
| 1611 | + ); |
|
| 1612 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1613 | + // load template |
|
| 1614 | + EEH_Template::display_template( |
|
| 1615 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1616 | + $publish_box_extra_args |
|
| 1617 | + ); |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + |
|
| 1621 | + /** |
|
| 1622 | + * @return EE_Event |
|
| 1623 | + */ |
|
| 1624 | + public function get_event_object() |
|
| 1625 | + { |
|
| 1626 | + return $this->_cpt_model_obj; |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + |
|
| 1631 | + |
|
| 1632 | + /** METABOXES * */ |
|
| 1633 | + /** |
|
| 1634 | + * _register_event_editor_meta_boxes |
|
| 1635 | + * add all metaboxes related to the event_editor |
|
| 1636 | + * |
|
| 1637 | + * @return void |
|
| 1638 | + * @throws EE_Error |
|
| 1639 | + * @throws InvalidArgumentException |
|
| 1640 | + * @throws InvalidDataTypeException |
|
| 1641 | + * @throws InvalidInterfaceException |
|
| 1642 | + * @throws ReflectionException |
|
| 1643 | + */ |
|
| 1644 | + protected function _register_event_editor_meta_boxes() |
|
| 1645 | + { |
|
| 1646 | + $this->verify_cpt_object(); |
|
| 1647 | + $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
| 1648 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1649 | + if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1650 | + add_meta_box( |
|
| 1651 | + 'espresso_event_editor_event_options', |
|
| 1652 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1653 | + [$this, 'registration_options_meta_box'], |
|
| 1654 | + $this->page_slug, |
|
| 1655 | + 'side' |
|
| 1656 | + ); |
|
| 1657 | + } |
|
| 1658 | + if (! $use_advanced_editor) { |
|
| 1659 | + add_meta_box( |
|
| 1660 | + 'espresso_event_editor_tickets', |
|
| 1661 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1662 | + [$this, 'ticket_metabox'], |
|
| 1663 | + $this->page_slug, |
|
| 1664 | + 'normal', |
|
| 1665 | + 'high' |
|
| 1666 | + ); |
|
| 1667 | + } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1668 | + add_action( |
|
| 1669 | + 'add_meta_boxes_espresso_events', |
|
| 1670 | + function () { |
|
| 1671 | + global $current_screen; |
|
| 1672 | + remove_meta_box('authordiv', $current_screen, 'normal'); |
|
| 1673 | + }, |
|
| 1674 | + 99 |
|
| 1675 | + ); |
|
| 1676 | + } |
|
| 1677 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1678 | + // where a metabox has a related management page in the admin |
|
| 1679 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1680 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + |
|
| 1684 | + /** |
|
| 1685 | + * @throws DomainException |
|
| 1686 | + * @throws EE_Error |
|
| 1687 | + * @throws InvalidArgumentException |
|
| 1688 | + * @throws InvalidDataTypeException |
|
| 1689 | + * @throws InvalidInterfaceException |
|
| 1690 | + * @throws ReflectionException |
|
| 1691 | + */ |
|
| 1692 | + public function ticket_metabox() |
|
| 1693 | + { |
|
| 1694 | + $existing_datetime_ids = $existing_ticket_ids = []; |
|
| 1695 | + // defaults for template args |
|
| 1696 | + $template_args = [ |
|
| 1697 | + 'existing_datetime_ids' => '', |
|
| 1698 | + 'event_datetime_help_link' => '', |
|
| 1699 | + 'ticket_options_help_link' => '', |
|
| 1700 | + 'time' => null, |
|
| 1701 | + 'ticket_rows' => '', |
|
| 1702 | + 'existing_ticket_ids' => '', |
|
| 1703 | + 'total_ticket_rows' => 1, |
|
| 1704 | + 'ticket_js_structure' => '', |
|
| 1705 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1706 | + 'disabled' => '', |
|
| 1707 | + ]; |
|
| 1708 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1709 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1710 | + /** |
|
| 1711 | + * 1. Start with retrieving Datetimes |
|
| 1712 | + * 2. Fore each datetime get related tickets |
|
| 1713 | + * 3. For each ticket get related prices |
|
| 1714 | + */ |
|
| 1715 | + /** @var EEM_Datetime $datetime_model */ |
|
| 1716 | + $datetime_model = EE_Registry::instance()->load_model('Datetime'); |
|
| 1717 | + /** @var EEM_Ticket $datetime_model */ |
|
| 1718 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1719 | + $times = $datetime_model->get_all_event_dates($event_id); |
|
| 1720 | + /** @type EE_Datetime $first_datetime */ |
|
| 1721 | + $first_datetime = reset($times); |
|
| 1722 | + // do we get related tickets? |
|
| 1723 | + if ( |
|
| 1724 | + $first_datetime instanceof EE_Datetime |
|
| 1725 | + && $first_datetime->ID() !== 0 |
|
| 1726 | + ) { |
|
| 1727 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1728 | + $template_args['time'] = $first_datetime; |
|
| 1729 | + $related_tickets = $first_datetime->tickets( |
|
| 1730 | + [ |
|
| 1731 | + ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
| 1732 | + 'default_where_conditions' => 'none', |
|
| 1733 | + ] |
|
| 1734 | + ); |
|
| 1735 | + if (! empty($related_tickets)) { |
|
| 1736 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1737 | + $row = 0; |
|
| 1738 | + foreach ($related_tickets as $ticket) { |
|
| 1739 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1740 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1741 | + $row++; |
|
| 1742 | + } |
|
| 1743 | + } else { |
|
| 1744 | + $template_args['total_ticket_rows'] = 1; |
|
| 1745 | + /** @type EE_Ticket $ticket */ |
|
| 1746 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1747 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1748 | + } |
|
| 1749 | + } else { |
|
| 1750 | + $template_args['time'] = $times[0]; |
|
| 1751 | + /** @type EE_Ticket[] $tickets */ |
|
| 1752 | + $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1753 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
| 1754 | + // NOTE: we're just sending the first default row |
|
| 1755 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1756 | + } |
|
| 1757 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1758 | + 'event_editor_event_datetimes_help_tab' |
|
| 1759 | + ); |
|
| 1760 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1761 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1762 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1763 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1764 | + $ticket_model->create_default_object(), |
|
| 1765 | + true |
|
| 1766 | + ); |
|
| 1767 | + $template = apply_filters( |
|
| 1768 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1769 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1770 | + ); |
|
| 1771 | + EEH_Template::display_template($template, $template_args); |
|
| 1772 | + } |
|
| 1773 | + |
|
| 1774 | + |
|
| 1775 | + /** |
|
| 1776 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1777 | + * |
|
| 1778 | + * @access private |
|
| 1779 | + * @param EE_Ticket $ticket the ticket object |
|
| 1780 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1781 | + * @param int $row |
|
| 1782 | + * @return string generated html for the ticket row. |
|
| 1783 | + * @throws DomainException |
|
| 1784 | + * @throws EE_Error |
|
| 1785 | + * @throws InvalidArgumentException |
|
| 1786 | + * @throws InvalidDataTypeException |
|
| 1787 | + * @throws InvalidInterfaceException |
|
| 1788 | + * @throws ReflectionException |
|
| 1789 | + */ |
|
| 1790 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1791 | + { |
|
| 1792 | + $template_args = [ |
|
| 1793 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1794 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1795 | + : '', |
|
| 1796 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1797 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1798 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1799 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1800 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1801 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1802 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1803 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1804 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1805 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1806 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1807 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1808 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1809 | + : ' disabled=disabled', |
|
| 1810 | + ]; |
|
| 1811 | + $price = $ticket->ID() !== 0 |
|
| 1812 | + ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
| 1813 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1814 | + $price_args = [ |
|
| 1815 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1816 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1817 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1818 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1819 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1820 | + ]; |
|
| 1821 | + // make sure we have default start and end dates if skeleton |
|
| 1822 | + // handle rows that should NOT be empty |
|
| 1823 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1824 | + // if empty then the start date will be now. |
|
| 1825 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1826 | + } |
|
| 1827 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1828 | + // get the earliest datetime (if present); |
|
| 1829 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1830 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1831 | + 'Datetime', |
|
| 1832 | + ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
| 1833 | + ) |
|
| 1834 | + : null; |
|
| 1835 | + if (! empty($earliest_dtt)) { |
|
| 1836 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1837 | + } else { |
|
| 1838 | + $template_args['TKT_end_date'] = date( |
|
| 1839 | + 'Y-m-d h:i a', |
|
| 1840 | + mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')) |
|
| 1841 | + ); |
|
| 1842 | + } |
|
| 1843 | + } |
|
| 1844 | + $template_args = array_merge($template_args, $price_args); |
|
| 1845 | + $template = apply_filters( |
|
| 1846 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1847 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1848 | + $ticket |
|
| 1849 | + ); |
|
| 1850 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1851 | + } |
|
| 1852 | + |
|
| 1853 | + |
|
| 1854 | + /** |
|
| 1855 | + * @throws DomainException |
|
| 1856 | + * @throws EE_Error |
|
| 1857 | + */ |
|
| 1858 | + public function registration_options_meta_box() |
|
| 1859 | + { |
|
| 1860 | + $yes_no_values = [ |
|
| 1861 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1862 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1863 | + ]; |
|
| 1864 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1865 | + [ |
|
| 1866 | + EEM_Registration::status_id_cancelled, |
|
| 1867 | + EEM_Registration::status_id_declined, |
|
| 1868 | + EEM_Registration::status_id_incomplete, |
|
| 1869 | + ], |
|
| 1870 | + true |
|
| 1871 | + ); |
|
| 1872 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1873 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1874 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1875 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1876 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1877 | + 'default_reg_status', |
|
| 1878 | + $default_reg_status_values, |
|
| 1879 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1880 | + ); |
|
| 1881 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1882 | + 'display_desc', |
|
| 1883 | + $yes_no_values, |
|
| 1884 | + $this->_cpt_model_obj->display_description() |
|
| 1885 | + ); |
|
| 1886 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1887 | + 'display_ticket_selector', |
|
| 1888 | + $yes_no_values, |
|
| 1889 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1890 | + '', |
|
| 1891 | + '', |
|
| 1892 | + false |
|
| 1893 | + ); |
|
| 1894 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1895 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1896 | + '', |
|
| 1897 | + $template_args, |
|
| 1898 | + $yes_no_values, |
|
| 1899 | + $default_reg_status_values |
|
| 1900 | + ); |
|
| 1901 | + EEH_Template::display_template( |
|
| 1902 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1903 | + $template_args |
|
| 1904 | + ); |
|
| 1905 | + } |
|
| 1906 | + |
|
| 1907 | + |
|
| 1908 | + /** |
|
| 1909 | + * _get_events() |
|
| 1910 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1911 | + * |
|
| 1912 | + * @access public |
|
| 1913 | + * @param int $per_page count of items per page (20 default); |
|
| 1914 | + * @param int $current_page what is the current page being viewed. |
|
| 1915 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1916 | + * If FALSE then we return an array of event objects |
|
| 1917 | + * that match the given _view and paging parameters. |
|
| 1918 | + * @return array|int an array of event objects. |
|
| 1919 | + * @throws EE_Error |
|
| 1920 | + * @throws InvalidArgumentException |
|
| 1921 | + * @throws InvalidDataTypeException |
|
| 1922 | + * @throws InvalidInterfaceException |
|
| 1923 | + * @throws ReflectionException |
|
| 1924 | + * @throws Exception |
|
| 1925 | + * @throws Exception |
|
| 1926 | + * @throws Exception |
|
| 1927 | + */ |
|
| 1928 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1929 | + { |
|
| 1930 | + $EEME = $this->_event_model(); |
|
| 1931 | + $offset = ($current_page - 1) * $per_page; |
|
| 1932 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1933 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1934 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 1935 | + $month_r = ''; |
|
| 1936 | + $year_r = ''; |
|
| 1937 | + if (isset($this->_req_data['month_range'])) { |
|
| 1938 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1939 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1940 | + // where PHP doesn't know what to assume for date. |
|
| 1941 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1942 | + $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1943 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1944 | + } |
|
| 1945 | + $where = []; |
|
| 1946 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1947 | + // determine what post_status our condition will have for the query. |
|
| 1948 | + switch ($status) { |
|
| 1949 | + case 'month': |
|
| 1950 | + case 'today': |
|
| 1951 | + case null: |
|
| 1952 | + case 'all': |
|
| 1953 | + break; |
|
| 1954 | + case 'draft': |
|
| 1955 | + $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
| 1956 | + break; |
|
| 1957 | + default: |
|
| 1958 | + $where['status'] = $status; |
|
| 1959 | + } |
|
| 1960 | + // categories? |
|
| 1961 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1962 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1963 | + if (! empty($category)) { |
|
| 1964 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
| 1965 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1966 | + } |
|
| 1967 | + // date where conditions |
|
| 1968 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1969 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
|
| 1970 | + $DateTime = new DateTime( |
|
| 1971 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1972 | + new DateTimeZone('UTC') |
|
| 1973 | + ); |
|
| 1974 | + $start = $DateTime->getTimestamp(); |
|
| 1975 | + // set the datetime to be the end of the month |
|
| 1976 | + $DateTime->setDate( |
|
| 1977 | + $year_r, |
|
| 1978 | + $month_r, |
|
| 1979 | + $DateTime->format('t') |
|
| 1980 | + )->setTime(23, 59, 59); |
|
| 1981 | + $end = $DateTime->getTimestamp(); |
|
| 1982 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1983 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') { |
|
| 1984 | + $DateTime = |
|
| 1985 | + new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1986 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1987 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1988 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1989 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') { |
|
| 1990 | + $now = date('Y-m-01'); |
|
| 1991 | + $DateTime = |
|
| 1992 | + new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1993 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1994 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1995 | + ->setTime(23, 59, 59) |
|
| 1996 | + ->format(implode(' ', $start_formats)); |
|
| 1997 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
| 1998 | + } |
|
| 1999 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 2000 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 2001 | + } elseif ( |
|
| 2002 | + ! isset($where['status']) |
|
| 2003 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events') |
|
| 2004 | + ) { |
|
| 2005 | + $where['OR'] = [ |
|
| 2006 | + 'status*restrict_private' => ['!=', 'private'], |
|
| 2007 | + 'AND' => [ |
|
| 2008 | + 'status*inclusive' => ['=', 'private'], |
|
| 2009 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 2010 | + ], |
|
| 2011 | + ]; |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + if ( |
|
| 2015 | + isset($this->_req_data['EVT_wp_user']) |
|
| 2016 | + && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id() |
|
| 2017 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 2018 | + ) { |
|
| 2019 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 2020 | + } |
|
| 2021 | + // search query handling |
|
| 2022 | + if (isset($this->_req_data['s'])) { |
|
| 2023 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2024 | + $where['OR'] = [ |
|
| 2025 | + 'EVT_name' => ['LIKE', $search_string], |
|
| 2026 | + 'EVT_desc' => ['LIKE', $search_string], |
|
| 2027 | + 'EVT_short_desc' => ['LIKE', $search_string], |
|
| 2028 | + ]; |
|
| 2029 | + } |
|
| 2030 | + // filter events by venue. |
|
| 2031 | + if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
| 2032 | + $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
| 2033 | + } |
|
| 2034 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 2035 | + $query_params = apply_filters( |
|
| 2036 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 2037 | + [ |
|
| 2038 | + $where, |
|
| 2039 | + 'limit' => $limit, |
|
| 2040 | + 'order_by' => $orderby, |
|
| 2041 | + 'order' => $order, |
|
| 2042 | + 'group_by' => 'EVT_ID', |
|
| 2043 | + ], |
|
| 2044 | + $this->_req_data |
|
| 2045 | + ); |
|
| 2046 | + |
|
| 2047 | + // let's first check if we have special requests coming in. |
|
| 2048 | + if (isset($this->_req_data['active_status'])) { |
|
| 2049 | + switch ($this->_req_data['active_status']) { |
|
| 2050 | + case 'upcoming': |
|
| 2051 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 2052 | + case 'expired': |
|
| 2053 | + return $EEME->get_expired_events($query_params, $count); |
|
| 2054 | + case 'active': |
|
| 2055 | + return $EEME->get_active_events($query_params, $count); |
|
| 2056 | + case 'inactive': |
|
| 2057 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 2058 | + } |
|
| 2059 | + } |
|
| 2060 | + |
|
| 2061 | + return $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 2062 | + } |
|
| 2063 | + |
|
| 2064 | + |
|
| 2065 | + /** |
|
| 2066 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 2067 | + * |
|
| 2068 | + * @param string $post_id |
|
| 2069 | + * @throws EE_Error |
|
| 2070 | + * @throws InvalidArgumentException |
|
| 2071 | + * @throws InvalidDataTypeException |
|
| 2072 | + * @throws InvalidInterfaceException |
|
| 2073 | + * @throws ReflectionException |
|
| 2074 | + */ |
|
| 2075 | + public function trash_cpt_item($post_id) |
|
| 2076 | + { |
|
| 2077 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 2078 | + $this->_trash_or_restore_event('trash', false); |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + |
|
| 2082 | + /** |
|
| 2083 | + * @param string $post_id |
|
| 2084 | + * @throws EE_Error |
|
| 2085 | + * @throws InvalidArgumentException |
|
| 2086 | + * @throws InvalidDataTypeException |
|
| 2087 | + * @throws InvalidInterfaceException |
|
| 2088 | + * @throws ReflectionException |
|
| 2089 | + */ |
|
| 2090 | + public function restore_cpt_item($post_id) |
|
| 2091 | + { |
|
| 2092 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 2093 | + $this->_trash_or_restore_event('draft', false); |
|
| 2094 | + } |
|
| 2095 | + |
|
| 2096 | + |
|
| 2097 | + /** |
|
| 2098 | + * @param string $post_id |
|
| 2099 | + * @throws EE_Error |
|
| 2100 | + * @throws InvalidArgumentException |
|
| 2101 | + * @throws InvalidDataTypeException |
|
| 2102 | + * @throws InvalidInterfaceException |
|
| 2103 | + * @throws ReflectionException |
|
| 2104 | + */ |
|
| 2105 | + public function delete_cpt_item($post_id) |
|
| 2106 | + { |
|
| 2107 | + throw new EE_Error( |
|
| 2108 | + esc_html__( |
|
| 2109 | + 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
| 2110 | + 'event_espresso' |
|
| 2111 | + ) |
|
| 2112 | + ); |
|
| 2113 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 2114 | + $this->_delete_event(); |
|
| 2115 | + } |
|
| 2116 | + |
|
| 2117 | + |
|
| 2118 | + /** |
|
| 2119 | + * _trash_or_restore_event |
|
| 2120 | + * |
|
| 2121 | + * @access protected |
|
| 2122 | + * @param string $event_status |
|
| 2123 | + * @param bool $redirect_after |
|
| 2124 | + * @throws EE_Error |
|
| 2125 | + * @throws InvalidArgumentException |
|
| 2126 | + * @throws InvalidDataTypeException |
|
| 2127 | + * @throws InvalidInterfaceException |
|
| 2128 | + * @throws ReflectionException |
|
| 2129 | + */ |
|
| 2130 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 2131 | + { |
|
| 2132 | + // determine the event id and set to array. |
|
| 2133 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 2134 | + // loop thru events |
|
| 2135 | + if ($EVT_ID) { |
|
| 2136 | + // clean status |
|
| 2137 | + $event_status = sanitize_key($event_status); |
|
| 2138 | + // grab status |
|
| 2139 | + if (! empty($event_status)) { |
|
| 2140 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2141 | + } else { |
|
| 2142 | + $success = false; |
|
| 2143 | + $msg = esc_html__( |
|
| 2144 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2145 | + 'event_espresso' |
|
| 2146 | + ); |
|
| 2147 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2148 | + } |
|
| 2149 | + } else { |
|
| 2150 | + $success = false; |
|
| 2151 | + $msg = esc_html__( |
|
| 2152 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2153 | + 'event_espresso' |
|
| 2154 | + ); |
|
| 2155 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2156 | + } |
|
| 2157 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2158 | + if ($redirect_after) { |
|
| 2159 | + $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
| 2160 | + } |
|
| 2161 | + } |
|
| 2162 | + |
|
| 2163 | + |
|
| 2164 | + /** |
|
| 2165 | + * _trash_or_restore_events |
|
| 2166 | + * |
|
| 2167 | + * @access protected |
|
| 2168 | + * @param string $event_status |
|
| 2169 | + * @return void |
|
| 2170 | + * @throws EE_Error |
|
| 2171 | + * @throws InvalidArgumentException |
|
| 2172 | + * @throws InvalidDataTypeException |
|
| 2173 | + * @throws InvalidInterfaceException |
|
| 2174 | + * @throws ReflectionException |
|
| 2175 | + */ |
|
| 2176 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 2177 | + { |
|
| 2178 | + // clean status |
|
| 2179 | + $event_status = sanitize_key($event_status); |
|
| 2180 | + // grab status |
|
| 2181 | + if (! empty($event_status)) { |
|
| 2182 | + $success = true; |
|
| 2183 | + // determine the event id and set to array. |
|
| 2184 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []; |
|
| 2185 | + // loop thru events |
|
| 2186 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2187 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 2188 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 2189 | + $success = $results !== false ? $success : false; |
|
| 2190 | + } else { |
|
| 2191 | + $msg = sprintf( |
|
| 2192 | + esc_html__( |
|
| 2193 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 2194 | + 'event_espresso' |
|
| 2195 | + ), |
|
| 2196 | + $EVT_ID |
|
| 2197 | + ); |
|
| 2198 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2199 | + $success = false; |
|
| 2200 | + } |
|
| 2201 | + } |
|
| 2202 | + } else { |
|
| 2203 | + $success = false; |
|
| 2204 | + $msg = esc_html__( |
|
| 2205 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 2206 | + 'event_espresso' |
|
| 2207 | + ); |
|
| 2208 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2209 | + } |
|
| 2210 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2211 | + $success = $success ? 2 : false; |
|
| 2212 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 2213 | + $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
| 2214 | + } |
|
| 2215 | + |
|
| 2216 | + |
|
| 2217 | + /** |
|
| 2218 | + * _trash_or_restore_events |
|
| 2219 | + * |
|
| 2220 | + * @access private |
|
| 2221 | + * @param int $EVT_ID |
|
| 2222 | + * @param string $event_status |
|
| 2223 | + * @return bool |
|
| 2224 | + * @throws EE_Error |
|
| 2225 | + * @throws InvalidArgumentException |
|
| 2226 | + * @throws InvalidDataTypeException |
|
| 2227 | + * @throws InvalidInterfaceException |
|
| 2228 | + * @throws ReflectionException |
|
| 2229 | + */ |
|
| 2230 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2231 | + { |
|
| 2232 | + // grab event id |
|
| 2233 | + if (! $EVT_ID) { |
|
| 2234 | + $msg = esc_html__( |
|
| 2235 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2236 | + 'event_espresso' |
|
| 2237 | + ); |
|
| 2238 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2239 | + return false; |
|
| 2240 | + } |
|
| 2241 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2242 | + // clean status |
|
| 2243 | + $event_status = sanitize_key($event_status); |
|
| 2244 | + // grab status |
|
| 2245 | + if (empty($event_status)) { |
|
| 2246 | + $msg = esc_html__( |
|
| 2247 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2248 | + 'event_espresso' |
|
| 2249 | + ); |
|
| 2250 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2251 | + return false; |
|
| 2252 | + } |
|
| 2253 | + // was event trashed or restored ? |
|
| 2254 | + switch ($event_status) { |
|
| 2255 | + case 'draft': |
|
| 2256 | + $action = 'restored from the trash'; |
|
| 2257 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2258 | + break; |
|
| 2259 | + case 'trash': |
|
| 2260 | + $action = 'moved to the trash'; |
|
| 2261 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2262 | + break; |
|
| 2263 | + default: |
|
| 2264 | + $action = 'updated'; |
|
| 2265 | + $hook = false; |
|
| 2266 | + } |
|
| 2267 | + // use class to change status |
|
| 2268 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2269 | + $success = $this->_cpt_model_obj->save(); |
|
| 2270 | + if ($success === false) { |
|
| 2271 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2272 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2273 | + return false; |
|
| 2274 | + } |
|
| 2275 | + if ($hook) { |
|
| 2276 | + do_action($hook); |
|
| 2277 | + } |
|
| 2278 | + return true; |
|
| 2279 | + } |
|
| 2280 | + |
|
| 2281 | + |
|
| 2282 | + /** |
|
| 2283 | + * @throws InvalidArgumentException |
|
| 2284 | + * @throws InvalidDataTypeException |
|
| 2285 | + * @throws InvalidInterfaceException |
|
| 2286 | + */ |
|
| 2287 | + protected function _delete_event() |
|
| 2288 | + { |
|
| 2289 | + $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []); |
|
| 2290 | + } |
|
| 2291 | + |
|
| 2292 | + |
|
| 2293 | + /** |
|
| 2294 | + * Gets the tree traversal batch persister. |
|
| 2295 | + * |
|
| 2296 | + * @return NodeGroupDao |
|
| 2297 | + * @throws InvalidArgumentException |
|
| 2298 | + * @throws InvalidDataTypeException |
|
| 2299 | + * @throws InvalidInterfaceException |
|
| 2300 | + * @since 4.10.12.p |
|
| 2301 | + */ |
|
| 2302 | + protected function getModelObjNodeGroupPersister() |
|
| 2303 | + { |
|
| 2304 | + if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2305 | + $this->model_obj_node_group_persister = |
|
| 2306 | + $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
| 2307 | + } |
|
| 2308 | + return $this->model_obj_node_group_persister; |
|
| 2309 | + } |
|
| 2310 | + |
|
| 2311 | + |
|
| 2312 | + /** |
|
| 2313 | + * @return void |
|
| 2314 | + * @throws InvalidArgumentException |
|
| 2315 | + * @throws InvalidDataTypeException |
|
| 2316 | + * @throws InvalidInterfaceException |
|
| 2317 | + */ |
|
| 2318 | + protected function _delete_events() |
|
| 2319 | + { |
|
| 2320 | + $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []); |
|
| 2321 | + } |
|
| 2322 | + |
|
| 2323 | + |
|
| 2324 | + protected function generateDeletionPreview($event_ids) |
|
| 2325 | + { |
|
| 2326 | + $event_ids = (array) $event_ids; |
|
| 2327 | + // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
| 2328 | + $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
| 2329 | + $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2330 | + [ |
|
| 2331 | + 'action' => 'preview_deletion', |
|
| 2332 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2333 | + ], |
|
| 2334 | + $this->_admin_base_url |
|
| 2335 | + ); |
|
| 2336 | + $event_ids = array_map( |
|
| 2337 | + 'intval', |
|
| 2338 | + $event_ids |
|
| 2339 | + ); |
|
| 2340 | + |
|
| 2341 | + EEH_URL::safeRedirectAndExit( |
|
| 2342 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2343 | + [ |
|
| 2344 | + 'page' => 'espresso_batch', |
|
| 2345 | + 'batch' => EED_Batch::batch_job, |
|
| 2346 | + 'EVT_IDs' => $event_ids, |
|
| 2347 | + 'deletion_job_code' => $deletion_job_code, |
|
| 2348 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
| 2349 | + 'return_url' => urlencode($return_url), |
|
| 2350 | + ], |
|
| 2351 | + admin_url() |
|
| 2352 | + ) |
|
| 2353 | + ); |
|
| 2354 | + } |
|
| 2355 | + |
|
| 2356 | + |
|
| 2357 | + /** |
|
| 2358 | + * Checks for a POST submission |
|
| 2359 | + * |
|
| 2360 | + * @since 4.10.12.p |
|
| 2361 | + */ |
|
| 2362 | + protected function confirmDeletion() |
|
| 2363 | + { |
|
| 2364 | + $deletion_redirect_logic = |
|
| 2365 | + $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
| 2366 | + $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
| 2367 | + } |
|
| 2368 | + |
|
| 2369 | + |
|
| 2370 | + /** |
|
| 2371 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
| 2372 | + * |
|
| 2373 | + * @throws EE_Error |
|
| 2374 | + * @since 4.10.12.p |
|
| 2375 | + */ |
|
| 2376 | + protected function previewDeletion() |
|
| 2377 | + { |
|
| 2378 | + $preview_deletion_logic = |
|
| 2379 | + $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
| 2380 | + $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
| 2381 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2382 | + } |
|
| 2383 | + |
|
| 2384 | + |
|
| 2385 | + /** |
|
| 2386 | + * get total number of events |
|
| 2387 | + * |
|
| 2388 | + * @access public |
|
| 2389 | + * @return int |
|
| 2390 | + * @throws EE_Error |
|
| 2391 | + * @throws InvalidArgumentException |
|
| 2392 | + * @throws InvalidDataTypeException |
|
| 2393 | + * @throws InvalidInterfaceException |
|
| 2394 | + */ |
|
| 2395 | + public function total_events() |
|
| 2396 | + { |
|
| 2397 | + return EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2398 | + } |
|
| 2399 | + |
|
| 2400 | + |
|
| 2401 | + /** |
|
| 2402 | + * get total number of draft events |
|
| 2403 | + * |
|
| 2404 | + * @access public |
|
| 2405 | + * @return int |
|
| 2406 | + * @throws EE_Error |
|
| 2407 | + * @throws InvalidArgumentException |
|
| 2408 | + * @throws InvalidDataTypeException |
|
| 2409 | + * @throws InvalidInterfaceException |
|
| 2410 | + */ |
|
| 2411 | + public function total_events_draft() |
|
| 2412 | + { |
|
| 2413 | + $where = [ |
|
| 2414 | + 'status' => ['IN', ['draft', 'auto-draft']], |
|
| 2415 | + ]; |
|
| 2416 | + return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2417 | + } |
|
| 2418 | + |
|
| 2419 | + |
|
| 2420 | + /** |
|
| 2421 | + * get total number of trashed events |
|
| 2422 | + * |
|
| 2423 | + * @access public |
|
| 2424 | + * @return int |
|
| 2425 | + * @throws EE_Error |
|
| 2426 | + * @throws InvalidArgumentException |
|
| 2427 | + * @throws InvalidDataTypeException |
|
| 2428 | + * @throws InvalidInterfaceException |
|
| 2429 | + */ |
|
| 2430 | + public function total_trashed_events() |
|
| 2431 | + { |
|
| 2432 | + $where = [ |
|
| 2433 | + 'status' => 'trash', |
|
| 2434 | + ]; |
|
| 2435 | + return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 2436 | + } |
|
| 2437 | + |
|
| 2438 | + |
|
| 2439 | + /** |
|
| 2440 | + * _default_event_settings |
|
| 2441 | + * This generates the Default Settings Tab |
|
| 2442 | + * |
|
| 2443 | + * @return void |
|
| 2444 | + * @throws DomainException |
|
| 2445 | + * @throws EE_Error |
|
| 2446 | + * @throws InvalidArgumentException |
|
| 2447 | + * @throws InvalidDataTypeException |
|
| 2448 | + * @throws InvalidInterfaceException |
|
| 2449 | + */ |
|
| 2450 | + protected function _default_event_settings() |
|
| 2451 | + { |
|
| 2452 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2453 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2454 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2455 | + $this->display_admin_page_with_sidebar(); |
|
| 2456 | + } |
|
| 2457 | + |
|
| 2458 | + |
|
| 2459 | + /** |
|
| 2460 | + * Return the form for event settings. |
|
| 2461 | + * |
|
| 2462 | + * @return EE_Form_Section_Proper |
|
| 2463 | + * @throws EE_Error |
|
| 2464 | + */ |
|
| 2465 | + protected function _default_event_settings_form() |
|
| 2466 | + { |
|
| 2467 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2468 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2469 | + // exclude |
|
| 2470 | + [ |
|
| 2471 | + EEM_Registration::status_id_cancelled, |
|
| 2472 | + EEM_Registration::status_id_declined, |
|
| 2473 | + EEM_Registration::status_id_incomplete, |
|
| 2474 | + EEM_Registration::status_id_wait_list, |
|
| 2475 | + ], |
|
| 2476 | + true |
|
| 2477 | + ); |
|
| 2478 | + return new EE_Form_Section_Proper( |
|
| 2479 | + [ |
|
| 2480 | + 'name' => 'update_default_event_settings', |
|
| 2481 | + 'html_id' => 'update_default_event_settings', |
|
| 2482 | + 'html_class' => 'form-table', |
|
| 2483 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2484 | + 'subsections' => apply_filters( |
|
| 2485 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2486 | + [ |
|
| 2487 | + 'default_reg_status' => new EE_Select_Input( |
|
| 2488 | + $registration_stati_for_selection, |
|
| 2489 | + [ |
|
| 2490 | + 'default' => isset($registration_config->default_STS_ID) |
|
| 2491 | + && array_key_exists( |
|
| 2492 | + $registration_config->default_STS_ID, |
|
| 2493 | + $registration_stati_for_selection |
|
| 2494 | + ) |
|
| 2495 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2496 | + : EEM_Registration::status_id_pending_payment, |
|
| 2497 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2498 | + . EEH_Template::get_help_tab_link( |
|
| 2499 | + 'default_settings_status_help_tab' |
|
| 2500 | + ), |
|
| 2501 | + 'html_help_text' => esc_html__( |
|
| 2502 | + '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.', |
|
| 2503 | + 'event_espresso' |
|
| 2504 | + ), |
|
| 2505 | + ] |
|
| 2506 | + ), |
|
| 2507 | + 'default_max_tickets' => new EE_Integer_Input( |
|
| 2508 | + [ |
|
| 2509 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2510 | + ? $registration_config->default_maximum_number_of_tickets |
|
| 2511 | + : EEM_Event::get_default_additional_limit(), |
|
| 2512 | + 'html_label_text' => esc_html__( |
|
| 2513 | + 'Default Maximum Tickets Allowed Per Order:', |
|
| 2514 | + 'event_espresso' |
|
| 2515 | + ) |
|
| 2516 | + . EEH_Template::get_help_tab_link( |
|
| 2517 | + 'default_maximum_tickets_help_tab"' |
|
| 2518 | + ), |
|
| 2519 | + 'html_help_text' => esc_html__( |
|
| 2520 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2521 | + 'event_espresso' |
|
| 2522 | + ), |
|
| 2523 | + ] |
|
| 2524 | + ), |
|
| 2525 | + ] |
|
| 2526 | + ), |
|
| 2527 | + ] |
|
| 2528 | + ); |
|
| 2529 | + } |
|
| 2530 | + |
|
| 2531 | + |
|
| 2532 | + /** |
|
| 2533 | + * @return void |
|
| 2534 | + * @throws EE_Error |
|
| 2535 | + * @throws InvalidArgumentException |
|
| 2536 | + * @throws InvalidDataTypeException |
|
| 2537 | + * @throws InvalidInterfaceException |
|
| 2538 | + */ |
|
| 2539 | + protected function _update_default_event_settings() |
|
| 2540 | + { |
|
| 2541 | + $form = $this->_default_event_settings_form(); |
|
| 2542 | + if ($form->was_submitted()) { |
|
| 2543 | + $form->receive_form_submission(); |
|
| 2544 | + if ($form->is_valid()) { |
|
| 2545 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2546 | + $valid_data = $form->valid_data(); |
|
| 2547 | + if (isset($valid_data['default_reg_status'])) { |
|
| 2548 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2549 | + } |
|
| 2550 | + if (isset($valid_data['default_max_tickets'])) { |
|
| 2551 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2552 | + } |
|
| 2553 | + do_action( |
|
| 2554 | + 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
| 2555 | + $valid_data, |
|
| 2556 | + EE_Registry::instance()->CFG, |
|
| 2557 | + $this |
|
| 2558 | + ); |
|
| 2559 | + // update because data was valid! |
|
| 2560 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2561 | + EE_Error::overwrite_success(); |
|
| 2562 | + EE_Error::add_success( |
|
| 2563 | + __('Default Event Settings were updated', 'event_espresso') |
|
| 2564 | + ); |
|
| 2565 | + } |
|
| 2566 | + } |
|
| 2567 | + $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
| 2568 | + } |
|
| 2569 | + |
|
| 2570 | + |
|
| 2571 | + /************* Templates ************* |
|
| 2880 | 2572 | * |
| 2881 | 2573 | * @throws EE_Error |
| 2882 | - * @throws InvalidArgumentException |
|
| 2883 | - * @throws InvalidDataTypeException |
|
| 2884 | - * @throws InvalidInterfaceException |
|
| 2885 | 2574 | */ |
| 2886 | - public function save_timezonestring_setting() |
|
| 2887 | - { |
|
| 2888 | - $timezone_string = isset($this->_req_data['timezone_selected']) |
|
| 2889 | - ? $this->_req_data['timezone_selected'] |
|
| 2890 | - : ''; |
|
| 2891 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2892 | - EE_Error::add_error( |
|
| 2893 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2894 | - __FILE__, |
|
| 2895 | - __FUNCTION__, |
|
| 2896 | - __LINE__ |
|
| 2897 | - ); |
|
| 2898 | - $this->_template_args['error'] = true; |
|
| 2899 | - $this->_return_json(); |
|
| 2900 | - } |
|
| 2901 | - |
|
| 2902 | - update_option('timezone_string', $timezone_string); |
|
| 2903 | - EE_Error::add_success( |
|
| 2904 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2905 | - ); |
|
| 2906 | - $this->_template_args['success'] = true; |
|
| 2907 | - $this->_return_json(true, ['action' => 'create_new']); |
|
| 2908 | - } |
|
| 2575 | + protected function _template_settings() |
|
| 2576 | + { |
|
| 2577 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2578 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2579 | + . EVENTS_ASSETS_URL |
|
| 2580 | + . '/images/' |
|
| 2581 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2582 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2583 | + . '" />'; |
|
| 2584 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 2585 | + . esc_html__( |
|
| 2586 | + '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.', |
|
| 2587 | + 'event_espresso' |
|
| 2588 | + ) . '</strong>'; |
|
| 2589 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2590 | + } |
|
| 2591 | + |
|
| 2592 | + |
|
| 2593 | + /** Event Category Stuff **/ |
|
| 2594 | + /** |
|
| 2595 | + * set the _category property with the category object for the loaded page. |
|
| 2596 | + * |
|
| 2597 | + * @access private |
|
| 2598 | + * @return void |
|
| 2599 | + */ |
|
| 2600 | + private function _set_category_object() |
|
| 2601 | + { |
|
| 2602 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2603 | + return; |
|
| 2604 | + } //already have the category object so get out. |
|
| 2605 | + // set default category object |
|
| 2606 | + $this->_set_empty_category_object(); |
|
| 2607 | + // only set if we've got an id |
|
| 2608 | + if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2609 | + return; |
|
| 2610 | + } |
|
| 2611 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2612 | + $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2613 | + if (! empty($term)) { |
|
| 2614 | + $this->_category->category_name = $term->name; |
|
| 2615 | + $this->_category->category_identifier = $term->slug; |
|
| 2616 | + $this->_category->category_desc = $term->description; |
|
| 2617 | + $this->_category->id = $term->term_id; |
|
| 2618 | + $this->_category->parent = $term->parent; |
|
| 2619 | + } |
|
| 2620 | + } |
|
| 2621 | + |
|
| 2622 | + |
|
| 2623 | + /** |
|
| 2624 | + * Clears out category properties. |
|
| 2625 | + */ |
|
| 2626 | + private function _set_empty_category_object() |
|
| 2627 | + { |
|
| 2628 | + $this->_category = new stdClass(); |
|
| 2629 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2630 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2631 | + } |
|
| 2632 | + |
|
| 2633 | + |
|
| 2634 | + /** |
|
| 2635 | + * @throws DomainException |
|
| 2636 | + * @throws EE_Error |
|
| 2637 | + * @throws InvalidArgumentException |
|
| 2638 | + * @throws InvalidDataTypeException |
|
| 2639 | + * @throws InvalidInterfaceException |
|
| 2640 | + */ |
|
| 2641 | + protected function _category_list_table() |
|
| 2642 | + { |
|
| 2643 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2644 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2645 | + $this->_admin_page_title .= ' '; |
|
| 2646 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 2647 | + 'add_category', |
|
| 2648 | + 'add_category', |
|
| 2649 | + [], |
|
| 2650 | + 'add-new-h2' |
|
| 2651 | + ); |
|
| 2652 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2653 | + } |
|
| 2654 | + |
|
| 2655 | + |
|
| 2656 | + /** |
|
| 2657 | + * Output category details view. |
|
| 2658 | + * |
|
| 2659 | + * @param string $view |
|
| 2660 | + * @throws DomainException |
|
| 2661 | + * @throws EE_Error |
|
| 2662 | + * @throws InvalidArgumentException |
|
| 2663 | + * @throws InvalidDataTypeException |
|
| 2664 | + * @throws InvalidInterfaceException |
|
| 2665 | + */ |
|
| 2666 | + protected function _category_details($view) |
|
| 2667 | + { |
|
| 2668 | + // load formatter helper |
|
| 2669 | + // load field generator helper |
|
| 2670 | + $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
| 2671 | + $this->_set_add_edit_form_tags($route); |
|
| 2672 | + $this->_set_category_object(); |
|
| 2673 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2674 | + $delete_action = 'delete_category'; |
|
| 2675 | + // custom redirect |
|
| 2676 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2677 | + ['action' => 'category_list'], |
|
| 2678 | + $this->_admin_base_url |
|
| 2679 | + ); |
|
| 2680 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2681 | + // take care of contents |
|
| 2682 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2683 | + $this->display_admin_page_with_sidebar(); |
|
| 2684 | + } |
|
| 2685 | + |
|
| 2686 | + |
|
| 2687 | + /** |
|
| 2688 | + * Output category details content. |
|
| 2689 | + * |
|
| 2690 | + * @throws DomainException |
|
| 2691 | + */ |
|
| 2692 | + protected function _category_details_content() |
|
| 2693 | + { |
|
| 2694 | + $editor_args['category_desc'] = [ |
|
| 2695 | + 'type' => 'wp_editor', |
|
| 2696 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2697 | + 'class' => 'my_editor_custom', |
|
| 2698 | + 'wpeditor_args' => ['media_buttons' => false], |
|
| 2699 | + ]; |
|
| 2700 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2701 | + $all_terms = get_terms( |
|
| 2702 | + [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
| 2703 | + ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
| 2704 | + ); |
|
| 2705 | + // setup category select for term parents. |
|
| 2706 | + $category_select_values[] = [ |
|
| 2707 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2708 | + 'id' => 0, |
|
| 2709 | + ]; |
|
| 2710 | + foreach ($all_terms as $term) { |
|
| 2711 | + $category_select_values[] = [ |
|
| 2712 | + 'text' => $term->name, |
|
| 2713 | + 'id' => $term->term_id, |
|
| 2714 | + ]; |
|
| 2715 | + } |
|
| 2716 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2717 | + 'category_parent', |
|
| 2718 | + $category_select_values, |
|
| 2719 | + $this->_category->parent |
|
| 2720 | + ); |
|
| 2721 | + $template_args = [ |
|
| 2722 | + 'category' => $this->_category, |
|
| 2723 | + 'category_select' => $category_select, |
|
| 2724 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2725 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2726 | + 'disable' => '', |
|
| 2727 | + 'disabled_message' => false, |
|
| 2728 | + ]; |
|
| 2729 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2730 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2731 | + } |
|
| 2732 | + |
|
| 2733 | + |
|
| 2734 | + /** |
|
| 2735 | + * Handles deleting categories. |
|
| 2736 | + * |
|
| 2737 | + * @throws EE_Error |
|
| 2738 | + */ |
|
| 2739 | + protected function _delete_categories() |
|
| 2740 | + { |
|
| 2741 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2742 | + : (array) $this->_req_data['category_id']; |
|
| 2743 | + foreach ($cat_ids as $cat_id) { |
|
| 2744 | + $this->_delete_category($cat_id); |
|
| 2745 | + } |
|
| 2746 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2747 | + $query_args = [ |
|
| 2748 | + 'action' => 'category_list', |
|
| 2749 | + ]; |
|
| 2750 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2751 | + } |
|
| 2752 | + |
|
| 2753 | + |
|
| 2754 | + /** |
|
| 2755 | + * Handles deleting specific category. |
|
| 2756 | + * |
|
| 2757 | + * @param int $cat_id |
|
| 2758 | + */ |
|
| 2759 | + protected function _delete_category($cat_id) |
|
| 2760 | + { |
|
| 2761 | + $cat_id = absint($cat_id); |
|
| 2762 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
| 2763 | + } |
|
| 2764 | + |
|
| 2765 | + |
|
| 2766 | + /** |
|
| 2767 | + * Handles triggering the update or insertion of a new category. |
|
| 2768 | + * |
|
| 2769 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
| 2770 | + * @throws EE_Error |
|
| 2771 | + * @throws InvalidArgumentException |
|
| 2772 | + * @throws InvalidDataTypeException |
|
| 2773 | + * @throws InvalidInterfaceException |
|
| 2774 | + */ |
|
| 2775 | + protected function _insert_or_update_category($new_category) |
|
| 2776 | + { |
|
| 2777 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2778 | + $success = 0; // we already have a success message so lets not send another. |
|
| 2779 | + if ($cat_id) { |
|
| 2780 | + $query_args = [ |
|
| 2781 | + 'action' => 'edit_category', |
|
| 2782 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2783 | + ]; |
|
| 2784 | + } else { |
|
| 2785 | + $query_args = ['action' => 'add_category']; |
|
| 2786 | + } |
|
| 2787 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2788 | + } |
|
| 2789 | + |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * Inserts or updates category |
|
| 2793 | + * |
|
| 2794 | + * @param bool $update (true indicates we're updating a category). |
|
| 2795 | + * @return bool|mixed|string |
|
| 2796 | + */ |
|
| 2797 | + private function _insert_category($update = false) |
|
| 2798 | + { |
|
| 2799 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2800 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2801 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2802 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2803 | + if (empty($category_name)) { |
|
| 2804 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2805 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2806 | + return false; |
|
| 2807 | + } |
|
| 2808 | + $term_args = [ |
|
| 2809 | + 'name' => $category_name, |
|
| 2810 | + 'description' => $category_desc, |
|
| 2811 | + 'parent' => $category_parent, |
|
| 2812 | + ]; |
|
| 2813 | + // was the category_identifier input disabled? |
|
| 2814 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2815 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2816 | + } |
|
| 2817 | + $insert_ids = $update |
|
| 2818 | + ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
| 2819 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
| 2820 | + if (! is_array($insert_ids)) { |
|
| 2821 | + $msg = esc_html__( |
|
| 2822 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2823 | + 'event_espresso' |
|
| 2824 | + ); |
|
| 2825 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2826 | + } else { |
|
| 2827 | + $cat_id = $insert_ids['term_id']; |
|
| 2828 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2829 | + EE_Error::add_success($msg); |
|
| 2830 | + } |
|
| 2831 | + return $cat_id; |
|
| 2832 | + } |
|
| 2833 | + |
|
| 2834 | + |
|
| 2835 | + /** |
|
| 2836 | + * Gets categories or count of categories matching the arguments in the request. |
|
| 2837 | + * |
|
| 2838 | + * @param int $per_page |
|
| 2839 | + * @param int $current_page |
|
| 2840 | + * @param bool $count |
|
| 2841 | + * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
| 2842 | + * @throws EE_Error |
|
| 2843 | + * @throws InvalidArgumentException |
|
| 2844 | + * @throws InvalidDataTypeException |
|
| 2845 | + * @throws InvalidInterfaceException |
|
| 2846 | + */ |
|
| 2847 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2848 | + { |
|
| 2849 | + // testing term stuff |
|
| 2850 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2851 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2852 | + $limit = ($current_page - 1) * $per_page; |
|
| 2853 | + $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
| 2854 | + if (isset($this->_req_data['s'])) { |
|
| 2855 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2856 | + $where['OR'] = [ |
|
| 2857 | + 'Term.name' => ['LIKE', $sstr], |
|
| 2858 | + 'description' => ['LIKE', $sstr], |
|
| 2859 | + ]; |
|
| 2860 | + } |
|
| 2861 | + $query_params = [ |
|
| 2862 | + $where, |
|
| 2863 | + 'order_by' => [$orderby => $order], |
|
| 2864 | + 'limit' => $limit . ',' . $per_page, |
|
| 2865 | + 'force_join' => ['Term'], |
|
| 2866 | + ]; |
|
| 2867 | + return $count |
|
| 2868 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2869 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2870 | + } |
|
| 2871 | + |
|
| 2872 | + /* end category stuff */ |
|
| 2873 | + |
|
| 2874 | + |
|
| 2875 | + /**************/ |
|
| 2876 | + |
|
| 2877 | + |
|
| 2878 | + /** |
|
| 2879 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
| 2880 | + * |
|
| 2881 | + * @throws EE_Error |
|
| 2882 | + * @throws InvalidArgumentException |
|
| 2883 | + * @throws InvalidDataTypeException |
|
| 2884 | + * @throws InvalidInterfaceException |
|
| 2885 | + */ |
|
| 2886 | + public function save_timezonestring_setting() |
|
| 2887 | + { |
|
| 2888 | + $timezone_string = isset($this->_req_data['timezone_selected']) |
|
| 2889 | + ? $this->_req_data['timezone_selected'] |
|
| 2890 | + : ''; |
|
| 2891 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
| 2892 | + EE_Error::add_error( |
|
| 2893 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
| 2894 | + __FILE__, |
|
| 2895 | + __FUNCTION__, |
|
| 2896 | + __LINE__ |
|
| 2897 | + ); |
|
| 2898 | + $this->_template_args['error'] = true; |
|
| 2899 | + $this->_return_json(); |
|
| 2900 | + } |
|
| 2901 | + |
|
| 2902 | + update_option('timezone_string', $timezone_string); |
|
| 2903 | + EE_Error::add_success( |
|
| 2904 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
| 2905 | + ); |
|
| 2906 | + $this->_template_args['success'] = true; |
|
| 2907 | + $this->_return_json(true, ['action' => 'create_new']); |
|
| 2908 | + } |
|
| 2909 | 2909 | } |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | ]; |
| 535 | 535 | // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated |
| 536 | 536 | $domain = $this->loader->getShared('EventEspresso\core\domain\Domain'); |
| 537 | - if (! $domain->isCaffeinated()) { |
|
| 537 | + if ( ! $domain->isCaffeinated()) { |
|
| 538 | 538 | $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
| 539 | 539 | $this->_page_config['edit']['qtips'] = ['EE_Event_Editor_Decaf_Tips']; |
| 540 | 540 | } |
@@ -593,13 +593,13 @@ discard block |
||
| 593 | 593 | { |
| 594 | 594 | wp_register_style( |
| 595 | 595 | 'events-admin-css', |
| 596 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 596 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 597 | 597 | [], |
| 598 | 598 | EVENT_ESPRESSO_VERSION |
| 599 | 599 | ); |
| 600 | 600 | wp_register_style( |
| 601 | 601 | 'ee-cat-admin', |
| 602 | - EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
| 602 | + EVENTS_ASSETS_URL.'ee-cat-admin.css', |
|
| 603 | 603 | [], |
| 604 | 604 | EVENT_ESPRESSO_VERSION |
| 605 | 605 | ); |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | // scripts |
| 609 | 609 | wp_register_script( |
| 610 | 610 | 'event_editor_js', |
| 611 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 611 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 612 | 612 | ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
| 613 | 613 | EVENT_ESPRESSO_VERSION, |
| 614 | 614 | true |
@@ -634,16 +634,16 @@ discard block |
||
| 634 | 634 | wp_enqueue_style('espresso-ui-theme'); |
| 635 | 635 | wp_register_style( |
| 636 | 636 | 'event-editor-css', |
| 637 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 637 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 638 | 638 | ['ee-admin-css'], |
| 639 | 639 | EVENT_ESPRESSO_VERSION |
| 640 | 640 | ); |
| 641 | 641 | wp_enqueue_style('event-editor-css'); |
| 642 | 642 | // scripts |
| 643 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 643 | + if ( ! $this->admin_config->useAdvancedEditor()) { |
|
| 644 | 644 | wp_register_script( |
| 645 | 645 | 'event-datetime-metabox', |
| 646 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 646 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 647 | 647 | ['event_editor_js', 'ee-datepicker'], |
| 648 | 648 | EVENT_ESPRESSO_VERSION |
| 649 | 649 | ); |
@@ -713,15 +713,15 @@ discard block |
||
| 713 | 713 | public function verify_event_edit($event = null, $req_type = '') |
| 714 | 714 | { |
| 715 | 715 | // don't need to do this when processing |
| 716 | - if (! empty($req_type)) { |
|
| 716 | + if ( ! empty($req_type)) { |
|
| 717 | 717 | return; |
| 718 | 718 | } |
| 719 | 719 | // no event? |
| 720 | - if (! $event instanceof EE_Event) { |
|
| 720 | + if ( ! $event instanceof EE_Event) { |
|
| 721 | 721 | $event = $this->_cpt_model_obj; |
| 722 | 722 | } |
| 723 | 723 | // STILL no event? |
| 724 | - if (! $event instanceof EE_Event) { |
|
| 724 | + if ( ! $event instanceof EE_Event) { |
|
| 725 | 725 | return; |
| 726 | 726 | } |
| 727 | 727 | $orig_status = $event->status(); |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | ); |
| 762 | 762 | } |
| 763 | 763 | // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
| 764 | - if (! $event->tickets_on_sale()) { |
|
| 764 | + if ( ! $event->tickets_on_sale()) { |
|
| 765 | 765 | return; |
| 766 | 766 | } |
| 767 | 767 | // made it here so show warning |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | { |
| 810 | 810 | $has_timezone_string = get_option('timezone_string'); |
| 811 | 811 | // only nag them about setting their timezone if it's their first event, and they haven't already done it |
| 812 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 812 | + if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
| 813 | 813 | EE_Error::add_attention( |
| 814 | 814 | sprintf( |
| 815 | 815 | __( |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | */ |
| 877 | 877 | protected function _event_legend_items() |
| 878 | 878 | { |
| 879 | - $items = [ |
|
| 879 | + $items = [ |
|
| 880 | 880 | 'view_details' => [ |
| 881 | 881 | 'class' => 'dashicons dashicons-search', |
| 882 | 882 | 'desc' => esc_html__('View Event', 'event_espresso'), |
@@ -893,31 +893,31 @@ discard block |
||
| 893 | 893 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 894 | 894 | $statuses = [ |
| 895 | 895 | 'sold_out_status' => [ |
| 896 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 896 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
| 897 | 897 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 898 | 898 | ], |
| 899 | 899 | 'active_status' => [ |
| 900 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 900 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
| 901 | 901 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 902 | 902 | ], |
| 903 | 903 | 'upcoming_status' => [ |
| 904 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 904 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
| 905 | 905 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 906 | 906 | ], |
| 907 | 907 | 'postponed_status' => [ |
| 908 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 908 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
| 909 | 909 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 910 | 910 | ], |
| 911 | 911 | 'cancelled_status' => [ |
| 912 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 912 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
| 913 | 913 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 914 | 914 | ], |
| 915 | 915 | 'expired_status' => [ |
| 916 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 916 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
| 917 | 917 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 918 | 918 | ], |
| 919 | 919 | 'inactive_status' => [ |
| 920 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 920 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
| 921 | 921 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 922 | 922 | ], |
| 923 | 923 | ]; |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | */ |
| 937 | 937 | private function _event_model() |
| 938 | 938 | { |
| 939 | - if (! $this->_event_model instanceof EEM_Event) { |
|
| 939 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 940 | 940 | $this->_event_model = EE_Registry::instance()->load_model('Event'); |
| 941 | 941 | } |
| 942 | 942 | return $this->_event_model; |
@@ -956,8 +956,8 @@ discard block |
||
| 956 | 956 | public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
| 957 | 957 | { |
| 958 | 958 | // make sure this is only when editing |
| 959 | - if (! empty($id)) { |
|
| 960 | - $post = get_post($id); |
|
| 959 | + if ( ! empty($id)) { |
|
| 960 | + $post = get_post($id); |
|
| 961 | 961 | $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
| 962 | 962 | . esc_html__('Shortcode', 'event_espresso') |
| 963 | 963 | . '</a> '; |
@@ -992,13 +992,13 @@ discard block |
||
| 992 | 992 | 'button' |
| 993 | 993 | ); |
| 994 | 994 | $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
| 995 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 995 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 996 | 996 | 'create_new', |
| 997 | 997 | 'add', |
| 998 | 998 | [], |
| 999 | 999 | 'add-new-h2' |
| 1000 | 1000 | ); |
| 1001 | - $this->_template_args['after_list_table'] = array_merge( |
|
| 1001 | + $this->_template_args['after_list_table'] = array_merge( |
|
| 1002 | 1002 | (array) $this->_template_args['after_list_table'], |
| 1003 | 1003 | $after_list_table |
| 1004 | 1004 | ); |
@@ -1057,12 +1057,12 @@ discard block |
||
| 1057 | 1057 | : null, |
| 1058 | 1058 | ]; |
| 1059 | 1059 | // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
| 1060 | - if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1061 | - $event_values['EVT_display_ticket_selector'] = |
|
| 1060 | + if ( ! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1061 | + $event_values['EVT_display_ticket_selector'] = |
|
| 1062 | 1062 | ! empty($this->_req_data['display_ticket_selector']) |
| 1063 | 1063 | ? 1 |
| 1064 | 1064 | : 0; |
| 1065 | - $event_values['EVT_additional_limit'] = min( |
|
| 1065 | + $event_values['EVT_additional_limit'] = min( |
|
| 1066 | 1066 | apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
| 1067 | 1067 | ! empty($this->_req_data['additional_limit']) |
| 1068 | 1068 | ? absint($this->_req_data['additional_limit']) |
@@ -1094,7 +1094,7 @@ discard block |
||
| 1094 | 1094 | 'status*1' => $this->_req_data['original_post_status'], |
| 1095 | 1095 | ], |
| 1096 | 1096 | ]; |
| 1097 | - $event = $this->_event_model()->get_one([$get_one_where]); |
|
| 1097 | + $event = $this->_event_model()->get_one([$get_one_where]); |
|
| 1098 | 1098 | // the following are default callbacks for event attachment updates |
| 1099 | 1099 | // that can be overridden by caffeinated functionality and/or addons. |
| 1100 | 1100 | $event_update_callbacks = apply_filters( |
@@ -1104,7 +1104,7 @@ discard block |
||
| 1104 | 1104 | [$this, '_default_tickets_update'], |
| 1105 | 1105 | ] |
| 1106 | 1106 | ); |
| 1107 | - $att_success = true; |
|
| 1107 | + $att_success = true; |
|
| 1108 | 1108 | foreach ($event_update_callbacks as $e_callback) { |
| 1109 | 1109 | $_success = is_callable($e_callback) |
| 1110 | 1110 | ? $e_callback($event, $this->_req_data) |
@@ -1171,7 +1171,7 @@ discard block |
||
| 1171 | 1171 | */ |
| 1172 | 1172 | protected function _default_venue_update(EE_Event $evtobj, $data) |
| 1173 | 1173 | { |
| 1174 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1174 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1175 | 1175 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
| 1176 | 1176 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
| 1177 | 1177 | // very important. If we don't have a venue name... |
@@ -1201,7 +1201,7 @@ discard block |
||
| 1201 | 1201 | 'status' => 'publish', |
| 1202 | 1202 | ]; |
| 1203 | 1203 | // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
| 1204 | - if (! empty($venue_id)) { |
|
| 1204 | + if ( ! empty($venue_id)) { |
|
| 1205 | 1205 | $update_where = [$venue_model->primary_key_name() => $venue_id]; |
| 1206 | 1206 | $rows_affected = $venue_model->update($venue_array, [$update_where]); |
| 1207 | 1207 | // we've gotta make sure that the venue is always attached to a revision.. |
@@ -1253,7 +1253,7 @@ discard block |
||
| 1253 | 1253 | ]; |
| 1254 | 1254 | // if we have an id then let's get existing object first and then set the new values. |
| 1255 | 1255 | // Otherwise we instantiate a new object for save. |
| 1256 | - if (! empty($dtt['DTT_ID'])) { |
|
| 1256 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1257 | 1257 | $DTM = EE_Registry::instance() |
| 1258 | 1258 | ->load_model('Datetime', [$evtobj->get_timezone()]) |
| 1259 | 1259 | ->get_one_by_ID($dtt['DTT_ID']); |
@@ -1264,7 +1264,7 @@ discard block |
||
| 1264 | 1264 | } |
| 1265 | 1265 | // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it. |
| 1266 | 1266 | // We need to do this so we dont' TRASH the parent DTT. |
| 1267 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
| 1267 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1268 | 1268 | } else { |
| 1269 | 1269 | $DTM = EE_Registry::instance()->load_class( |
| 1270 | 1270 | 'Datetime', |
@@ -1299,15 +1299,15 @@ discard block |
||
| 1299 | 1299 | foreach ($data['edit_tickets'] as $row => $tkt) { |
| 1300 | 1300 | $incoming_date_formats = ['Y-m-d', 'h:i a']; |
| 1301 | 1301 | $update_prices = false; |
| 1302 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
| 1303 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] |
|
| 1302 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1303 | + ? $data['edit_prices'][$row][1]['PRC_amount'] |
|
| 1304 | 1304 | : 0; |
| 1305 | 1305 | // trim inputs to ensure any excess whitespace is removed. |
| 1306 | 1306 | $tkt = array_map('trim', $tkt); |
| 1307 | 1307 | if (empty($tkt['TKT_start_date'])) { |
| 1308 | 1308 | // let's use now in the set timezone. |
| 1309 | 1309 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
| 1310 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1310 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
| 1311 | 1311 | } |
| 1312 | 1312 | if (empty($tkt['TKT_end_date'])) { |
| 1313 | 1313 | // use the start date of the first datetime |
@@ -1345,7 +1345,7 @@ discard block |
||
| 1345 | 1345 | // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
| 1346 | 1346 | // keep in mind that if the TKT has been sold (and we have changed pricing information), |
| 1347 | 1347 | // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
| 1348 | - if (! empty($tkt['TKT_ID'])) { |
|
| 1348 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1349 | 1349 | $TKT = EE_Registry::instance() |
| 1350 | 1350 | ->load_model('Ticket', [$evtobj->get_timezone()]) |
| 1351 | 1351 | ->get_one_by_ID($tkt['TKT_ID']); |
@@ -1389,7 +1389,7 @@ discard block |
||
| 1389 | 1389 | $TKT->save(); |
| 1390 | 1390 | // make sure this ticket is still recorded in our saved_tkts |
| 1391 | 1391 | // so we don't run it through the regular trash routine. |
| 1392 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1392 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1393 | 1393 | // create new ticket that's a copy of the existing except a new id of course |
| 1394 | 1394 | // (and not archived) AND has the new TKT_price associated with it. |
| 1395 | 1395 | $TKT = clone $TKT; |
@@ -1436,9 +1436,9 @@ discard block |
||
| 1436 | 1436 | } |
| 1437 | 1437 | // initially let's add the ticket to the dtt |
| 1438 | 1438 | $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
| 1439 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
| 1439 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1440 | 1440 | // add prices to ticket |
| 1441 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
| 1441 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1442 | 1442 | } |
| 1443 | 1443 | // however now we need to handle permanently deleting tickets via the ui. |
| 1444 | 1444 | // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
@@ -1543,13 +1543,13 @@ discard block |
||
| 1543 | 1543 | { |
| 1544 | 1544 | // load formatter helper |
| 1545 | 1545 | // args for getting related registrations |
| 1546 | - $approved_query_args = [ |
|
| 1546 | + $approved_query_args = [ |
|
| 1547 | 1547 | [ |
| 1548 | 1548 | 'REG_deleted' => 0, |
| 1549 | 1549 | 'STS_ID' => EEM_Registration::status_id_approved, |
| 1550 | 1550 | ], |
| 1551 | 1551 | ]; |
| 1552 | - $not_approved_query_args = [ |
|
| 1552 | + $not_approved_query_args = [ |
|
| 1553 | 1553 | [ |
| 1554 | 1554 | 'REG_deleted' => 0, |
| 1555 | 1555 | 'STS_ID' => EEM_Registration::status_id_not_approved, |
@@ -1612,7 +1612,7 @@ discard block |
||
| 1612 | 1612 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1613 | 1613 | // load template |
| 1614 | 1614 | EEH_Template::display_template( |
| 1615 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1615 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1616 | 1616 | $publish_box_extra_args |
| 1617 | 1617 | ); |
| 1618 | 1618 | } |
@@ -1646,7 +1646,7 @@ discard block |
||
| 1646 | 1646 | $this->verify_cpt_object(); |
| 1647 | 1647 | $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
| 1648 | 1648 | // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
| 1649 | - if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1649 | + if ( ! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
| 1650 | 1650 | add_meta_box( |
| 1651 | 1651 | 'espresso_event_editor_event_options', |
| 1652 | 1652 | esc_html__('Event Registration Options', 'event_espresso'), |
@@ -1655,7 +1655,7 @@ discard block |
||
| 1655 | 1655 | 'side' |
| 1656 | 1656 | ); |
| 1657 | 1657 | } |
| 1658 | - if (! $use_advanced_editor) { |
|
| 1658 | + if ( ! $use_advanced_editor) { |
|
| 1659 | 1659 | add_meta_box( |
| 1660 | 1660 | 'espresso_event_editor_tickets', |
| 1661 | 1661 | esc_html__('Event Datetime & Ticket', 'event_espresso'), |
@@ -1667,7 +1667,7 @@ discard block |
||
| 1667 | 1667 | } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
| 1668 | 1668 | add_action( |
| 1669 | 1669 | 'add_meta_boxes_espresso_events', |
| 1670 | - function () { |
|
| 1670 | + function() { |
|
| 1671 | 1671 | global $current_screen; |
| 1672 | 1672 | remove_meta_box('authordiv', $current_screen, 'normal'); |
| 1673 | 1673 | }, |
@@ -1705,7 +1705,7 @@ discard block |
||
| 1705 | 1705 | 'trash_icon' => 'ee-lock-icon', |
| 1706 | 1706 | 'disabled' => '', |
| 1707 | 1707 | ]; |
| 1708 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1708 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1709 | 1709 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1710 | 1710 | /** |
| 1711 | 1711 | * 1. Start with retrieving Datetimes |
@@ -1732,24 +1732,24 @@ discard block |
||
| 1732 | 1732 | 'default_where_conditions' => 'none', |
| 1733 | 1733 | ] |
| 1734 | 1734 | ); |
| 1735 | - if (! empty($related_tickets)) { |
|
| 1735 | + if ( ! empty($related_tickets)) { |
|
| 1736 | 1736 | $template_args['total_ticket_rows'] = count($related_tickets); |
| 1737 | 1737 | $row = 0; |
| 1738 | 1738 | foreach ($related_tickets as $ticket) { |
| 1739 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1739 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1740 | 1740 | $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
| 1741 | 1741 | $row++; |
| 1742 | 1742 | } |
| 1743 | 1743 | } else { |
| 1744 | 1744 | $template_args['total_ticket_rows'] = 1; |
| 1745 | 1745 | /** @type EE_Ticket $ticket */ |
| 1746 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1746 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1747 | 1747 | $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
| 1748 | 1748 | } |
| 1749 | 1749 | } else { |
| 1750 | 1750 | $template_args['time'] = $times[0]; |
| 1751 | 1751 | /** @type EE_Ticket[] $tickets */ |
| 1752 | - $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1752 | + $tickets = $ticket_model->get_all_default_tickets(); |
|
| 1753 | 1753 | $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
| 1754 | 1754 | // NOTE: we're just sending the first default row |
| 1755 | 1755 | // (decaf can't manage default tickets so this should be sufficient); |
@@ -1764,9 +1764,9 @@ discard block |
||
| 1764 | 1764 | $ticket_model->create_default_object(), |
| 1765 | 1765 | true |
| 1766 | 1766 | ); |
| 1767 | - $template = apply_filters( |
|
| 1767 | + $template = apply_filters( |
|
| 1768 | 1768 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1769 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1769 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1770 | 1770 | ); |
| 1771 | 1771 | EEH_Template::display_template($template, $template_args); |
| 1772 | 1772 | } |
@@ -1790,7 +1790,7 @@ discard block |
||
| 1790 | 1790 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1791 | 1791 | { |
| 1792 | 1792 | $template_args = [ |
| 1793 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1793 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1794 | 1794 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1795 | 1795 | : '', |
| 1796 | 1796 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1802,10 +1802,10 @@ discard block |
||
| 1802 | 1802 | 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
| 1803 | 1803 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
| 1804 | 1804 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
| 1805 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1806 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1805 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1806 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1807 | 1807 | ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
| 1808 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1808 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1809 | 1809 | : ' disabled=disabled', |
| 1810 | 1810 | ]; |
| 1811 | 1811 | $price = $ticket->ID() !== 0 |
@@ -1832,7 +1832,7 @@ discard block |
||
| 1832 | 1832 | ['order_by' => ['DTT_EVT_start' => 'ASC']] |
| 1833 | 1833 | ) |
| 1834 | 1834 | : null; |
| 1835 | - if (! empty($earliest_dtt)) { |
|
| 1835 | + if ( ! empty($earliest_dtt)) { |
|
| 1836 | 1836 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
| 1837 | 1837 | } else { |
| 1838 | 1838 | $template_args['TKT_end_date'] = date( |
@@ -1844,7 +1844,7 @@ discard block |
||
| 1844 | 1844 | $template_args = array_merge($template_args, $price_args); |
| 1845 | 1845 | $template = apply_filters( |
| 1846 | 1846 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1847 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1847 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1848 | 1848 | $ticket |
| 1849 | 1849 | ); |
| 1850 | 1850 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1857,7 +1857,7 @@ discard block |
||
| 1857 | 1857 | */ |
| 1858 | 1858 | public function registration_options_meta_box() |
| 1859 | 1859 | { |
| 1860 | - $yes_no_values = [ |
|
| 1860 | + $yes_no_values = [ |
|
| 1861 | 1861 | ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
| 1862 | 1862 | ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
| 1863 | 1863 | ]; |
@@ -1878,12 +1878,12 @@ discard block |
||
| 1878 | 1878 | $default_reg_status_values, |
| 1879 | 1879 | $this->_cpt_model_obj->default_registration_status() |
| 1880 | 1880 | ); |
| 1881 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1881 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1882 | 1882 | 'display_desc', |
| 1883 | 1883 | $yes_no_values, |
| 1884 | 1884 | $this->_cpt_model_obj->display_description() |
| 1885 | 1885 | ); |
| 1886 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1886 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1887 | 1887 | 'display_ticket_selector', |
| 1888 | 1888 | $yes_no_values, |
| 1889 | 1889 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -1899,7 +1899,7 @@ discard block |
||
| 1899 | 1899 | $default_reg_status_values |
| 1900 | 1900 | ); |
| 1901 | 1901 | EEH_Template::display_template( |
| 1902 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1902 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1903 | 1903 | $template_args |
| 1904 | 1904 | ); |
| 1905 | 1905 | } |
@@ -1929,7 +1929,7 @@ discard block |
||
| 1929 | 1929 | { |
| 1930 | 1930 | $EEME = $this->_event_model(); |
| 1931 | 1931 | $offset = ($current_page - 1) * $per_page; |
| 1932 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1932 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1933 | 1933 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
| 1934 | 1934 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
| 1935 | 1935 | $month_r = ''; |
@@ -1960,7 +1960,7 @@ discard block |
||
| 1960 | 1960 | // categories? |
| 1961 | 1961 | $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
| 1962 | 1962 | ? $this->_req_data['EVT_CAT'] : null; |
| 1963 | - if (! empty($category)) { |
|
| 1963 | + if ( ! empty($category)) { |
|
| 1964 | 1964 | $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
| 1965 | 1965 | $where['Term_Taxonomy.term_id'] = $category; |
| 1966 | 1966 | } |
@@ -1968,10 +1968,10 @@ discard block |
||
| 1968 | 1968 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1969 | 1969 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
| 1970 | 1970 | $DateTime = new DateTime( |
| 1971 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1971 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1972 | 1972 | new DateTimeZone('UTC') |
| 1973 | 1973 | ); |
| 1974 | - $start = $DateTime->getTimestamp(); |
|
| 1974 | + $start = $DateTime->getTimestamp(); |
|
| 1975 | 1975 | // set the datetime to be the end of the month |
| 1976 | 1976 | $DateTime->setDate( |
| 1977 | 1977 | $year_r, |
@@ -1996,7 +1996,7 @@ discard block |
||
| 1996 | 1996 | ->format(implode(' ', $start_formats)); |
| 1997 | 1997 | $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
| 1998 | 1998 | } |
| 1999 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1999 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 2000 | 2000 | $where['EVT_wp_user'] = get_current_user_id(); |
| 2001 | 2001 | } elseif ( |
| 2002 | 2002 | ! isset($where['status']) |
@@ -2020,7 +2020,7 @@ discard block |
||
| 2020 | 2020 | } |
| 2021 | 2021 | // search query handling |
| 2022 | 2022 | if (isset($this->_req_data['s'])) { |
| 2023 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2023 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 2024 | 2024 | $where['OR'] = [ |
| 2025 | 2025 | 'EVT_name' => ['LIKE', $search_string], |
| 2026 | 2026 | 'EVT_desc' => ['LIKE', $search_string], |
@@ -2136,7 +2136,7 @@ discard block |
||
| 2136 | 2136 | // clean status |
| 2137 | 2137 | $event_status = sanitize_key($event_status); |
| 2138 | 2138 | // grab status |
| 2139 | - if (! empty($event_status)) { |
|
| 2139 | + if ( ! empty($event_status)) { |
|
| 2140 | 2140 | $success = $this->_change_event_status($EVT_ID, $event_status); |
| 2141 | 2141 | } else { |
| 2142 | 2142 | $success = false; |
@@ -2178,7 +2178,7 @@ discard block |
||
| 2178 | 2178 | // clean status |
| 2179 | 2179 | $event_status = sanitize_key($event_status); |
| 2180 | 2180 | // grab status |
| 2181 | - if (! empty($event_status)) { |
|
| 2181 | + if ( ! empty($event_status)) { |
|
| 2182 | 2182 | $success = true; |
| 2183 | 2183 | // determine the event id and set to array. |
| 2184 | 2184 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []; |
@@ -2230,7 +2230,7 @@ discard block |
||
| 2230 | 2230 | private function _change_event_status($EVT_ID = 0, $event_status = '') |
| 2231 | 2231 | { |
| 2232 | 2232 | // grab event id |
| 2233 | - if (! $EVT_ID) { |
|
| 2233 | + if ( ! $EVT_ID) { |
|
| 2234 | 2234 | $msg = esc_html__( |
| 2235 | 2235 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
| 2236 | 2236 | 'event_espresso' |
@@ -2301,7 +2301,7 @@ discard block |
||
| 2301 | 2301 | */ |
| 2302 | 2302 | protected function getModelObjNodeGroupPersister() |
| 2303 | 2303 | { |
| 2304 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2304 | + if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
| 2305 | 2305 | $this->model_obj_node_group_persister = |
| 2306 | 2306 | $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
| 2307 | 2307 | } |
@@ -2333,7 +2333,7 @@ discard block |
||
| 2333 | 2333 | ], |
| 2334 | 2334 | $this->_admin_base_url |
| 2335 | 2335 | ); |
| 2336 | - $event_ids = array_map( |
|
| 2336 | + $event_ids = array_map( |
|
| 2337 | 2337 | 'intval', |
| 2338 | 2338 | $event_ids |
| 2339 | 2339 | ); |
@@ -2585,7 +2585,7 @@ discard block |
||
| 2585 | 2585 | . esc_html__( |
| 2586 | 2586 | '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.', |
| 2587 | 2587 | 'event_espresso' |
| 2588 | - ) . '</strong>'; |
|
| 2588 | + ).'</strong>'; |
|
| 2589 | 2589 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2590 | 2590 | } |
| 2591 | 2591 | |
@@ -2605,12 +2605,12 @@ discard block |
||
| 2605 | 2605 | // set default category object |
| 2606 | 2606 | $this->_set_empty_category_object(); |
| 2607 | 2607 | // only set if we've got an id |
| 2608 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2608 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2609 | 2609 | return; |
| 2610 | 2610 | } |
| 2611 | 2611 | $category_id = absint($this->_req_data['EVT_CAT_ID']); |
| 2612 | 2612 | $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
| 2613 | - if (! empty($term)) { |
|
| 2613 | + if ( ! empty($term)) { |
|
| 2614 | 2614 | $this->_category->category_name = $term->name; |
| 2615 | 2615 | $this->_category->category_identifier = $term->slug; |
| 2616 | 2616 | $this->_category->category_desc = $term->description; |
@@ -2718,7 +2718,7 @@ discard block |
||
| 2718 | 2718 | $category_select_values, |
| 2719 | 2719 | $this->_category->parent |
| 2720 | 2720 | ); |
| 2721 | - $template_args = [ |
|
| 2721 | + $template_args = [ |
|
| 2722 | 2722 | 'category' => $this->_category, |
| 2723 | 2723 | 'category_select' => $category_select, |
| 2724 | 2724 | 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
@@ -2726,7 +2726,7 @@ discard block |
||
| 2726 | 2726 | 'disable' => '', |
| 2727 | 2727 | 'disabled_message' => false, |
| 2728 | 2728 | ]; |
| 2729 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2729 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2730 | 2730 | return EEH_Template::display_template($template, $template_args, true); |
| 2731 | 2731 | } |
| 2732 | 2732 | |
@@ -2817,7 +2817,7 @@ discard block |
||
| 2817 | 2817 | $insert_ids = $update |
| 2818 | 2818 | ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
| 2819 | 2819 | : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
| 2820 | - if (! is_array($insert_ids)) { |
|
| 2820 | + if ( ! is_array($insert_ids)) { |
|
| 2821 | 2821 | $msg = esc_html__( |
| 2822 | 2822 | 'An error occurred and the category has not been saved to the database.', |
| 2823 | 2823 | 'event_espresso' |
@@ -2852,7 +2852,7 @@ discard block |
||
| 2852 | 2852 | $limit = ($current_page - 1) * $per_page; |
| 2853 | 2853 | $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
| 2854 | 2854 | if (isset($this->_req_data['s'])) { |
| 2855 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2855 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2856 | 2856 | $where['OR'] = [ |
| 2857 | 2857 | 'Term.name' => ['LIKE', $sstr], |
| 2858 | 2858 | 'description' => ['LIKE', $sstr], |
@@ -2861,7 +2861,7 @@ discard block |
||
| 2861 | 2861 | $query_params = [ |
| 2862 | 2862 | $where, |
| 2863 | 2863 | 'order_by' => [$orderby => $order], |
| 2864 | - 'limit' => $limit . ',' . $per_page, |
|
| 2864 | + 'limit' => $limit.','.$per_page, |
|
| 2865 | 2865 | 'force_join' => ['Term'], |
| 2866 | 2866 | ]; |
| 2867 | 2867 | return $count |
@@ -16,1436 +16,1436 @@ |
||
| 16 | 16 | class Extend_Events_Admin_Page extends Events_Admin_Page |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var EE_Admin_Config |
|
| 21 | - */ |
|
| 22 | - protected $admin_config; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var AdvancedEditorAdminFormSection |
|
| 26 | - */ |
|
| 27 | - protected $advanced_editor_admin_form; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Extend_Events_Admin_Page constructor. |
|
| 32 | - * |
|
| 33 | - * @param bool $routing |
|
| 34 | - * @throws ReflectionException |
|
| 35 | - */ |
|
| 36 | - public function __construct($routing = true) |
|
| 37 | - { |
|
| 38 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 39 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 40 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 41 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 42 | - } |
|
| 43 | - parent::__construct($routing); |
|
| 44 | - $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Sets routes. |
|
| 50 | - * |
|
| 51 | - * @throws EE_Error |
|
| 52 | - * @throws InvalidArgumentException |
|
| 53 | - * @throws InvalidDataTypeException |
|
| 54 | - * @throws InvalidInterfaceException |
|
| 55 | - * @throws Exception |
|
| 56 | - */ |
|
| 57 | - protected function _extend_page_config() |
|
| 58 | - { |
|
| 59 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 60 | - // is there a evt_id in the request? |
|
| 61 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 62 | - ? $this->_req_data['EVT_ID'] |
|
| 63 | - : 0; |
|
| 64 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 65 | - // tkt_id? |
|
| 66 | - $tkt_id = |
|
| 67 | - ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
| 68 | - ? $this->_req_data['TKT_ID'] |
|
| 69 | - : 0; |
|
| 70 | - $new_page_routes = [ |
|
| 71 | - 'duplicate_event' => [ |
|
| 72 | - 'func' => '_duplicate_event', |
|
| 73 | - 'capability' => 'ee_edit_event', |
|
| 74 | - 'obj_id' => $evt_id, |
|
| 75 | - 'noheader' => true, |
|
| 76 | - ], |
|
| 77 | - 'import_page' => [ |
|
| 78 | - 'func' => '_import_page', |
|
| 79 | - 'capability' => 'import', |
|
| 80 | - ], |
|
| 81 | - 'import' => [ |
|
| 82 | - 'func' => '_import_events', |
|
| 83 | - 'capability' => 'import', |
|
| 84 | - 'noheader' => true, |
|
| 85 | - ], |
|
| 86 | - 'import_events' => [ |
|
| 87 | - 'func' => '_import_events', |
|
| 88 | - 'capability' => 'import', |
|
| 89 | - 'noheader' => true, |
|
| 90 | - ], |
|
| 91 | - 'export_events' => [ |
|
| 92 | - 'func' => '_events_export', |
|
| 93 | - 'capability' => 'export', |
|
| 94 | - 'noheader' => true, |
|
| 95 | - ], |
|
| 96 | - 'export_categories' => [ |
|
| 97 | - 'func' => '_categories_export', |
|
| 98 | - 'capability' => 'export', |
|
| 99 | - 'noheader' => true, |
|
| 100 | - ], |
|
| 101 | - 'sample_export_file' => [ |
|
| 102 | - 'func' => '_sample_export_file', |
|
| 103 | - 'capability' => 'export', |
|
| 104 | - 'noheader' => true, |
|
| 105 | - ], |
|
| 106 | - 'update_template_settings' => [ |
|
| 107 | - 'func' => '_update_template_settings', |
|
| 108 | - 'capability' => 'manage_options', |
|
| 109 | - 'noheader' => true, |
|
| 110 | - ], |
|
| 111 | - 'ticket_list_table' => [ |
|
| 112 | - 'func' => '_tickets_overview_list_table', |
|
| 113 | - 'capability' => 'ee_read_default_tickets', |
|
| 114 | - ], |
|
| 115 | - ]; |
|
| 116 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 117 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 118 | - // don't load these meta boxes if using the advanced editor |
|
| 119 | - if ( |
|
| 120 | - ! $this->admin_config->useAdvancedEditor() |
|
| 121 | - || ! $this->feature->allowed('use_default_ticket_manager') |
|
| 122 | - ) { |
|
| 123 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 124 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 125 | - |
|
| 126 | - $legacy_editor_page_routes = [ |
|
| 127 | - 'trash_ticket' => [ |
|
| 128 | - 'func' => '_trash_or_restore_ticket', |
|
| 129 | - 'capability' => 'ee_delete_default_ticket', |
|
| 130 | - 'obj_id' => $tkt_id, |
|
| 131 | - 'noheader' => true, |
|
| 132 | - 'args' => ['trash' => true], |
|
| 133 | - ], |
|
| 134 | - 'trash_tickets' => [ |
|
| 135 | - 'func' => '_trash_or_restore_ticket', |
|
| 136 | - 'capability' => 'ee_delete_default_tickets', |
|
| 137 | - 'noheader' => true, |
|
| 138 | - 'args' => ['trash' => true], |
|
| 139 | - ], |
|
| 140 | - 'restore_ticket' => [ |
|
| 141 | - 'func' => '_trash_or_restore_ticket', |
|
| 142 | - 'capability' => 'ee_delete_default_ticket', |
|
| 143 | - 'obj_id' => $tkt_id, |
|
| 144 | - 'noheader' => true, |
|
| 145 | - ], |
|
| 146 | - 'restore_tickets' => [ |
|
| 147 | - 'func' => '_trash_or_restore_ticket', |
|
| 148 | - 'capability' => 'ee_delete_default_tickets', |
|
| 149 | - 'noheader' => true, |
|
| 150 | - ], |
|
| 151 | - 'delete_ticket' => [ |
|
| 152 | - 'func' => '_delete_ticket', |
|
| 153 | - 'capability' => 'ee_delete_default_ticket', |
|
| 154 | - 'obj_id' => $tkt_id, |
|
| 155 | - 'noheader' => true, |
|
| 156 | - ], |
|
| 157 | - 'delete_tickets' => [ |
|
| 158 | - 'func' => '_delete_ticket', |
|
| 159 | - 'capability' => 'ee_delete_default_tickets', |
|
| 160 | - 'noheader' => true, |
|
| 161 | - ], |
|
| 162 | - ]; |
|
| 163 | - $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 167 | - // partial route/config override |
|
| 168 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 169 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 170 | - // add tickets tab but only if there are more than one default ticket! |
|
| 171 | - $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 172 | - [['TKT_is_default' => 1]], |
|
| 173 | - 'TKT_ID', |
|
| 174 | - true |
|
| 175 | - ); |
|
| 176 | - if ($tkt_count > 1) { |
|
| 177 | - $new_page_config = [ |
|
| 178 | - 'ticket_list_table' => [ |
|
| 179 | - 'nav' => [ |
|
| 180 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 181 | - 'order' => 60, |
|
| 182 | - ], |
|
| 183 | - 'list_table' => 'Tickets_List_Table', |
|
| 184 | - 'require_nonce' => false, |
|
| 185 | - ], |
|
| 186 | - ]; |
|
| 187 | - } |
|
| 188 | - // template settings |
|
| 189 | - $new_page_config['template_settings'] = [ |
|
| 190 | - 'nav' => [ |
|
| 191 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 192 | - 'order' => 30, |
|
| 193 | - ], |
|
| 194 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 195 | - 'help_tabs' => [ |
|
| 196 | - 'general_settings_templates_help_tab' => [ |
|
| 197 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 198 | - 'filename' => 'general_settings_templates', |
|
| 199 | - ], |
|
| 200 | - ], |
|
| 201 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 202 | - // 'help_tour' => ['Templates_Help_Tour'], |
|
| 203 | - 'require_nonce' => false, |
|
| 204 | - ]; |
|
| 205 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 206 | - // add filters and actions |
|
| 207 | - // modifying _views |
|
| 208 | - add_filter( |
|
| 209 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 210 | - [$this, 'add_additional_datetime_button'], |
|
| 211 | - 10, |
|
| 212 | - 2 |
|
| 213 | - ); |
|
| 214 | - add_filter( |
|
| 215 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 216 | - [$this, 'add_datetime_clone_button'], |
|
| 217 | - 10, |
|
| 218 | - 2 |
|
| 219 | - ); |
|
| 220 | - add_filter( |
|
| 221 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
| 222 | - [$this, 'datetime_timezones_template'], |
|
| 223 | - 10, |
|
| 224 | - 2 |
|
| 225 | - ); |
|
| 226 | - // filters for event list table |
|
| 227 | - add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2); |
|
| 228 | - add_filter( |
|
| 229 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 230 | - [$this, 'extra_list_table_actions'], |
|
| 231 | - 10, |
|
| 232 | - 2 |
|
| 233 | - ); |
|
| 234 | - // legend item |
|
| 235 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']); |
|
| 236 | - add_action('admin_init', [$this, 'admin_init']); |
|
| 237 | - // load additional handlers |
|
| 238 | - $this->handleActionRequest(); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - private function getRequestAction() |
|
| 243 | - { |
|
| 244 | - return isset($this->_req_data['action']) ? sanitize_key($this->_req_data['action']) : null; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @throws Exception |
|
| 250 | - */ |
|
| 251 | - private function handleActionRequest() |
|
| 252 | - { |
|
| 253 | - $action = $this->getRequestAction(); |
|
| 254 | - if ($action) { |
|
| 255 | - // setup Advanced Editor ??? |
|
| 256 | - if ($action === 'default_event_settings' || $action === 'update_default_event_settings') { |
|
| 257 | - $this->advanced_editor_admin_form = $this->loader->getShared( |
|
| 258 | - 'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection' |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * admin_init |
|
| 267 | - */ |
|
| 268 | - public function admin_init() |
|
| 269 | - { |
|
| 270 | - EE_Registry::$i18n_js_strings = array_merge( |
|
| 271 | - EE_Registry::$i18n_js_strings, |
|
| 272 | - [ |
|
| 273 | - 'image_confirm' => esc_html__( |
|
| 274 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 275 | - 'event_espresso' |
|
| 276 | - ), |
|
| 277 | - 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
| 278 | - 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
| 279 | - 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
| 280 | - 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
| 281 | - 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
| 282 | - ] |
|
| 283 | - ); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Add per page screen options to the default ticket list table view. |
|
| 289 | - * |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - * @throws InvalidDataTypeException |
|
| 292 | - * @throws InvalidInterfaceException |
|
| 293 | - */ |
|
| 294 | - protected function _add_screen_options_ticket_list_table() |
|
| 295 | - { |
|
| 296 | - $this->_per_page_screen_option(); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param string $return |
|
| 302 | - * @param int $id |
|
| 303 | - * @param string $new_title |
|
| 304 | - * @param string $new_slug |
|
| 305 | - * @return string |
|
| 306 | - */ |
|
| 307 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 308 | - { |
|
| 309 | - $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
| 310 | - // make sure this is only when editing |
|
| 311 | - if (! empty($id)) { |
|
| 312 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 313 | - ['action' => 'duplicate_event', 'EVT_ID' => $id], |
|
| 314 | - $this->_admin_base_url |
|
| 315 | - ); |
|
| 316 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 317 | - $return .= '<a href="' |
|
| 318 | - . $href |
|
| 319 | - . '" title="' |
|
| 320 | - . $title |
|
| 321 | - . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
| 322 | - . $title |
|
| 323 | - . '</a>'; |
|
| 324 | - } |
|
| 325 | - return $return; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Set the list table views for the default ticket list table view. |
|
| 331 | - */ |
|
| 332 | - public function _set_list_table_views_ticket_list_table() |
|
| 333 | - { |
|
| 334 | - $this->_views = [ |
|
| 335 | - 'all' => [ |
|
| 336 | - 'slug' => 'all', |
|
| 337 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 338 | - 'count' => 0, |
|
| 339 | - 'bulk_action' => [ |
|
| 340 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 341 | - ], |
|
| 342 | - ], |
|
| 343 | - 'trashed' => [ |
|
| 344 | - 'slug' => 'trashed', |
|
| 345 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 346 | - 'count' => 0, |
|
| 347 | - 'bulk_action' => [ |
|
| 348 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 349 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 350 | - ], |
|
| 351 | - ], |
|
| 352 | - ]; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Enqueue scripts and styles for the event editor. |
|
| 358 | - */ |
|
| 359 | - public function load_scripts_styles_edit() |
|
| 360 | - { |
|
| 361 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 362 | - wp_register_script( |
|
| 363 | - 'ee-event-editor-heartbeat', |
|
| 364 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 365 | - ['ee_admin_js', 'heartbeat'], |
|
| 366 | - EVENT_ESPRESSO_VERSION, |
|
| 367 | - true |
|
| 368 | - ); |
|
| 369 | - wp_enqueue_script('ee-accounting'); |
|
| 370 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 371 | - } |
|
| 372 | - wp_enqueue_script('event_editor_js'); |
|
| 373 | - // styles |
|
| 374 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Returns template for the additional datetime. |
|
| 380 | - * |
|
| 381 | - * @param $template |
|
| 382 | - * @param $template_args |
|
| 383 | - * @return mixed |
|
| 384 | - * @throws DomainException |
|
| 385 | - */ |
|
| 386 | - public function add_additional_datetime_button($template, $template_args) |
|
| 387 | - { |
|
| 388 | - return EEH_Template::display_template( |
|
| 389 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 390 | - $template_args, |
|
| 391 | - true |
|
| 392 | - ); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Returns the template for cloning a datetime. |
|
| 398 | - * |
|
| 399 | - * @param $template |
|
| 400 | - * @param $template_args |
|
| 401 | - * @return mixed |
|
| 402 | - * @throws DomainException |
|
| 403 | - */ |
|
| 404 | - public function add_datetime_clone_button($template, $template_args) |
|
| 405 | - { |
|
| 406 | - return EEH_Template::display_template( |
|
| 407 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 408 | - $template_args, |
|
| 409 | - true |
|
| 410 | - ); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Returns the template for datetime timezones. |
|
| 416 | - * |
|
| 417 | - * @param $template |
|
| 418 | - * @param $template_args |
|
| 419 | - * @return mixed |
|
| 420 | - * @throws DomainException |
|
| 421 | - */ |
|
| 422 | - public function datetime_timezones_template($template, $template_args) |
|
| 423 | - { |
|
| 424 | - return EEH_Template::display_template( |
|
| 425 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 426 | - $template_args, |
|
| 427 | - true |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * Sets the views for the default list table view. |
|
| 434 | - * |
|
| 435 | - * @throws EE_Error |
|
| 436 | - */ |
|
| 437 | - protected function _set_list_table_views_default() |
|
| 438 | - { |
|
| 439 | - parent::_set_list_table_views_default(); |
|
| 440 | - $new_views = [ |
|
| 441 | - 'today' => [ |
|
| 442 | - 'slug' => 'today', |
|
| 443 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
| 444 | - 'count' => $this->total_events_today(), |
|
| 445 | - 'bulk_action' => [ |
|
| 446 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 447 | - ], |
|
| 448 | - ], |
|
| 449 | - 'month' => [ |
|
| 450 | - 'slug' => 'month', |
|
| 451 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 452 | - 'count' => $this->total_events_this_month(), |
|
| 453 | - 'bulk_action' => [ |
|
| 454 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 455 | - ], |
|
| 456 | - ], |
|
| 457 | - ]; |
|
| 458 | - $this->_views = array_merge($this->_views, $new_views); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Returns the extra action links for the default list table view. |
|
| 464 | - * |
|
| 465 | - * @param array $action_links |
|
| 466 | - * @param EE_Event $event |
|
| 467 | - * @return array |
|
| 468 | - * @throws EE_Error |
|
| 469 | - * @throws InvalidArgumentException |
|
| 470 | - * @throws InvalidDataTypeException |
|
| 471 | - * @throws InvalidInterfaceException |
|
| 472 | - * @throws ReflectionException |
|
| 473 | - */ |
|
| 474 | - public function extra_list_table_actions(array $action_links, EE_Event $event) |
|
| 475 | - { |
|
| 476 | - if ( |
|
| 477 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 478 | - 'ee_read_registrations', |
|
| 479 | - 'espresso_registrations_reports', |
|
| 480 | - $event->ID() |
|
| 481 | - ) |
|
| 482 | - ) { |
|
| 483 | - $reports_query_args = [ |
|
| 484 | - 'action' => 'reports', |
|
| 485 | - 'EVT_ID' => $event->ID(), |
|
| 486 | - ]; |
|
| 487 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
| 488 | - $action_links[] = '<a href="' |
|
| 489 | - . $reports_link |
|
| 490 | - . '" title="' |
|
| 491 | - . esc_attr__('View Report', 'event_espresso') |
|
| 492 | - . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
| 493 | - . "\n\t"; |
|
| 494 | - } |
|
| 495 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 496 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 497 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 498 | - 'see_notifications_for', |
|
| 499 | - null, |
|
| 500 | - ['EVT_ID' => $event->ID()] |
|
| 501 | - ); |
|
| 502 | - } |
|
| 503 | - return $action_links; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * @param $items |
|
| 509 | - * @return mixed |
|
| 510 | - */ |
|
| 511 | - public function additional_legend_items($items) |
|
| 512 | - { |
|
| 513 | - if ( |
|
| 514 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 515 | - 'ee_read_registrations', |
|
| 516 | - 'espresso_registrations_reports' |
|
| 517 | - ) |
|
| 518 | - ) { |
|
| 519 | - $items['reports'] = [ |
|
| 520 | - 'class' => 'dashicons dashicons-chart-bar', |
|
| 521 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 522 | - ]; |
|
| 523 | - } |
|
| 524 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 525 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 526 | - // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset |
|
| 527 | - // (can only use numeric offsets when treating strings as arrays) |
|
| 528 | - if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) { |
|
| 529 | - $items['view_related_messages'] = [ |
|
| 530 | - 'class' => $related_for_icon['css_class'], |
|
| 531 | - 'desc' => $related_for_icon['label'], |
|
| 532 | - ]; |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - return $items; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * This is the callback method for the duplicate event route |
|
| 541 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 542 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 543 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 544 | - * After duplication the redirect is to the new event edit page. |
|
| 545 | - * |
|
| 546 | - * @return void |
|
| 547 | - * @throws EE_Error If EE_Event is not available with given ID |
|
| 548 | - * @throws InvalidArgumentException |
|
| 549 | - * @throws InvalidDataTypeException |
|
| 550 | - * @throws InvalidInterfaceException |
|
| 551 | - * @throws ReflectionException |
|
| 552 | - * @access protected |
|
| 553 | - */ |
|
| 554 | - protected function _duplicate_event() |
|
| 555 | - { |
|
| 556 | - // first make sure the ID for the event is in the request. |
|
| 557 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 558 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
| 559 | - EE_Error::add_error( |
|
| 560 | - esc_html__( |
|
| 561 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 562 | - 'event_espresso' |
|
| 563 | - ), |
|
| 564 | - __FILE__, |
|
| 565 | - __FUNCTION__, |
|
| 566 | - __LINE__ |
|
| 567 | - ); |
|
| 568 | - $this->_redirect_after_action(false, '', '', [], true); |
|
| 569 | - return; |
|
| 570 | - } |
|
| 571 | - // k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 572 | - $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
| 573 | - if (! $orig_event instanceof EE_Event) { |
|
| 574 | - throw new EE_Error( |
|
| 575 | - sprintf( |
|
| 576 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 577 | - $this->_req_data['EVT_ID'] |
|
| 578 | - ) |
|
| 579 | - ); |
|
| 580 | - } |
|
| 581 | - // k now let's clone the $orig_event before getting relations |
|
| 582 | - $new_event = clone $orig_event; |
|
| 583 | - // original datetimes |
|
| 584 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 585 | - // other original relations |
|
| 586 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 587 | - // reset the ID and modify other details to make it clear this is a dupe |
|
| 588 | - $new_event->set('EVT_ID', 0); |
|
| 589 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 590 | - $new_event->set('EVT_name', $new_name); |
|
| 591 | - $new_event->set( |
|
| 592 | - 'EVT_slug', |
|
| 593 | - wp_unique_post_slug( |
|
| 594 | - sanitize_title($orig_event->name()), |
|
| 595 | - 0, |
|
| 596 | - 'publish', |
|
| 597 | - 'espresso_events', |
|
| 598 | - 0 |
|
| 599 | - ) |
|
| 600 | - ); |
|
| 601 | - $new_event->set('status', 'draft'); |
|
| 602 | - // duplicate discussion settings |
|
| 603 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 604 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 605 | - // save the new event |
|
| 606 | - $new_event->save(); |
|
| 607 | - // venues |
|
| 608 | - foreach ($orig_ven as $ven) { |
|
| 609 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
| 610 | - } |
|
| 611 | - $new_event->save(); |
|
| 612 | - // now we need to get the question group relations and handle that |
|
| 613 | - // first primary question groups |
|
| 614 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
| 615 | - 'Question_Group', |
|
| 616 | - [['Event_Question_Group.EQG_primary' => true]] |
|
| 617 | - ); |
|
| 618 | - if (! empty($orig_primary_qgs)) { |
|
| 619 | - foreach ($orig_primary_qgs as $id => $obj) { |
|
| 620 | - if ($obj instanceof EE_Question_Group) { |
|
| 621 | - $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - // next additional attendee question groups |
|
| 626 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
| 627 | - 'Question_Group', |
|
| 628 | - [['Event_Question_Group.EQG_additional' => true]] |
|
| 629 | - ); |
|
| 630 | - if (! empty($orig_additional_qgs)) { |
|
| 631 | - foreach ($orig_additional_qgs as $id => $obj) { |
|
| 632 | - if ($obj instanceof EE_Question_Group) { |
|
| 633 | - $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $new_event->save(); |
|
| 639 | - |
|
| 640 | - // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 641 | - $cloned_tickets = []; |
|
| 642 | - foreach ($orig_datetimes as $orig_dtt) { |
|
| 643 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
| 644 | - continue; |
|
| 645 | - } |
|
| 646 | - $new_dtt = clone $orig_dtt; |
|
| 647 | - $orig_tkts = $orig_dtt->tickets(); |
|
| 648 | - // save new dtt then add to event |
|
| 649 | - $new_dtt->set('DTT_ID', 0); |
|
| 650 | - $new_dtt->set('DTT_sold', 0); |
|
| 651 | - $new_dtt->set_reserved(0); |
|
| 652 | - $new_dtt->save(); |
|
| 653 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 654 | - $new_event->save(); |
|
| 655 | - // now let's get the ticket relations setup. |
|
| 656 | - foreach ((array) $orig_tkts as $orig_tkt) { |
|
| 657 | - // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 658 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
| 659 | - continue; |
|
| 660 | - } |
|
| 661 | - // is this ticket archived? If it is then let's skip |
|
| 662 | - if ($orig_tkt->get('TKT_deleted')) { |
|
| 663 | - continue; |
|
| 664 | - } |
|
| 665 | - // does this original ticket already exist in the clone_tickets cache? |
|
| 666 | - // If so we'll just use the new ticket from it. |
|
| 667 | - if (isset($cloned_tickets[ $orig_tkt->ID() ])) { |
|
| 668 | - $new_tkt = $cloned_tickets[ $orig_tkt->ID() ]; |
|
| 669 | - } else { |
|
| 670 | - $new_tkt = clone $orig_tkt; |
|
| 671 | - // get relations on the $orig_tkt that we need to setup. |
|
| 672 | - $orig_prices = $orig_tkt->prices(); |
|
| 673 | - $new_tkt->set('TKT_ID', 0); |
|
| 674 | - $new_tkt->set('TKT_sold', 0); |
|
| 675 | - $new_tkt->set('TKT_reserved', 0); |
|
| 676 | - $new_tkt->save(); // make sure new ticket has ID. |
|
| 677 | - // price relations on new ticket need to be setup. |
|
| 678 | - foreach ($orig_prices as $orig_price) { |
|
| 679 | - $new_price = clone $orig_price; |
|
| 680 | - $new_price->set('PRC_ID', 0); |
|
| 681 | - $new_price->save(); |
|
| 682 | - $new_tkt->_add_relation_to($new_price, 'Price'); |
|
| 683 | - $new_tkt->save(); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - do_action( |
|
| 687 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
| 688 | - $orig_tkt, |
|
| 689 | - $new_tkt, |
|
| 690 | - $orig_prices, |
|
| 691 | - $orig_event, |
|
| 692 | - $orig_dtt, |
|
| 693 | - $new_dtt |
|
| 694 | - ); |
|
| 695 | - } |
|
| 696 | - // k now we can add the new ticket as a relation to the new datetime |
|
| 697 | - // and make sure its added to our cached $cloned_tickets array |
|
| 698 | - // for use with later datetimes that have the same ticket. |
|
| 699 | - $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
| 700 | - $new_dtt->save(); |
|
| 701 | - $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt; |
|
| 702 | - } |
|
| 703 | - } |
|
| 704 | - // clone taxonomy information |
|
| 705 | - $taxonomies_to_clone_with = apply_filters( |
|
| 706 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 707 | - ['espresso_event_categories', 'espresso_event_type', 'post_tag'] |
|
| 708 | - ); |
|
| 709 | - // get terms for original event (notice) |
|
| 710 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 711 | - // loop through terms and add them to new event. |
|
| 712 | - foreach ($orig_terms as $term) { |
|
| 713 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - // duplicate other core WP_Post items for this event. |
|
| 717 | - // post thumbnail (feature image). |
|
| 718 | - $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
| 719 | - if ($feature_image_id) { |
|
| 720 | - update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - // duplicate page_template setting |
|
| 724 | - $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
| 725 | - if ($page_template) { |
|
| 726 | - update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 730 | - // now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 731 | - if ($new_event->ID()) { |
|
| 732 | - $redirect_args = [ |
|
| 733 | - 'post' => $new_event->ID(), |
|
| 734 | - 'action' => 'edit', |
|
| 735 | - ]; |
|
| 736 | - EE_Error::add_success( |
|
| 737 | - esc_html__( |
|
| 738 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 739 | - 'event_espresso' |
|
| 740 | - ) |
|
| 741 | - ); |
|
| 742 | - } else { |
|
| 743 | - $redirect_args = [ |
|
| 744 | - 'action' => 'default', |
|
| 745 | - ]; |
|
| 746 | - EE_Error::add_error( |
|
| 747 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 748 | - __FILE__, |
|
| 749 | - __FUNCTION__, |
|
| 750 | - __LINE__ |
|
| 751 | - ); |
|
| 752 | - } |
|
| 753 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * Generates output for the import page. |
|
| 759 | - * |
|
| 760 | - * @throws DomainException |
|
| 761 | - * @throws EE_Error |
|
| 762 | - * @throws InvalidArgumentException |
|
| 763 | - * @throws InvalidDataTypeException |
|
| 764 | - * @throws InvalidInterfaceException |
|
| 765 | - */ |
|
| 766 | - protected function _import_page() |
|
| 767 | - { |
|
| 768 | - $title = esc_html__('Import', 'event_espresso'); |
|
| 769 | - $intro = esc_html__( |
|
| 770 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 771 | - 'event_espresso' |
|
| 772 | - ); |
|
| 773 | - $form_url = EVENTS_ADMIN_URL; |
|
| 774 | - $action = 'import_events'; |
|
| 775 | - $type = 'csv'; |
|
| 776 | - $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
| 777 | - $title, |
|
| 778 | - $intro, |
|
| 779 | - $form_url, |
|
| 780 | - $action, |
|
| 781 | - $type |
|
| 782 | - ); |
|
| 783 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 784 | - ['action' => 'sample_export_file'], |
|
| 785 | - $this->_admin_base_url |
|
| 786 | - ); |
|
| 787 | - $content = EEH_Template::display_template( |
|
| 788 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 789 | - $this->_template_args, |
|
| 790 | - true |
|
| 791 | - ); |
|
| 792 | - $this->_template_args['admin_page_content'] = $content; |
|
| 793 | - $this->display_admin_page_with_sidebar(); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * _import_events |
|
| 799 | - * This handles displaying the screen and running imports for importing events. |
|
| 800 | - * |
|
| 801 | - * @return void |
|
| 802 | - * @throws EE_Error |
|
| 803 | - * @throws InvalidArgumentException |
|
| 804 | - * @throws InvalidDataTypeException |
|
| 805 | - * @throws InvalidInterfaceException |
|
| 806 | - */ |
|
| 807 | - protected function _import_events() |
|
| 808 | - { |
|
| 809 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 810 | - $success = EE_Import::instance()->import(); |
|
| 811 | - $this->_redirect_after_action($success, 'Import File', 'ran', ['action' => 'import_page'], true); |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * _events_export |
|
| 817 | - * Will export all (or just the given event) to a Excel compatible file. |
|
| 818 | - * |
|
| 819 | - * @access protected |
|
| 820 | - * @return void |
|
| 821 | - */ |
|
| 822 | - protected function _events_export() |
|
| 823 | - { |
|
| 824 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 825 | - $event_ids = $this->_req_data['EVT_ID']; |
|
| 826 | - } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
| 827 | - $event_ids = $this->_req_data['EVT_IDs']; |
|
| 828 | - } else { |
|
| 829 | - $event_ids = null; |
|
| 830 | - } |
|
| 831 | - // todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 832 | - $new_request_args = [ |
|
| 833 | - 'export' => 'report', |
|
| 834 | - 'action' => 'all_event_data', |
|
| 835 | - 'EVT_ID' => $event_ids, |
|
| 836 | - ]; |
|
| 837 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 838 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 839 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 840 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 841 | - if ($EE_Export instanceof EE_Export) { |
|
| 842 | - $EE_Export->export(); |
|
| 843 | - } |
|
| 844 | - } |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * handle category exports() |
|
| 850 | - * |
|
| 851 | - * @return void |
|
| 852 | - */ |
|
| 853 | - protected function _categories_export() |
|
| 854 | - { |
|
| 855 | - // todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 856 | - $new_request_args = [ |
|
| 857 | - 'export' => 'report', |
|
| 858 | - 'action' => 'categories', |
|
| 859 | - 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
| 860 | - ]; |
|
| 861 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 862 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 863 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 864 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 865 | - if ($EE_Export instanceof EE_Export) { |
|
| 866 | - $EE_Export->export(); |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * Creates a sample CSV file for importing |
|
| 874 | - */ |
|
| 875 | - protected function _sample_export_file() |
|
| 876 | - { |
|
| 877 | - $EE_Export = EE_Export::instance(); |
|
| 878 | - if ($EE_Export instanceof EE_Export) { |
|
| 879 | - $EE_Export->export(); |
|
| 880 | - } |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - |
|
| 884 | - /************* Template Settings *************/ |
|
| 885 | - /** |
|
| 886 | - * Generates template settings page output |
|
| 887 | - * |
|
| 888 | - * @throws DomainException |
|
| 889 | - * @throws EE_Error |
|
| 890 | - * @throws InvalidArgumentException |
|
| 891 | - * @throws InvalidDataTypeException |
|
| 892 | - * @throws InvalidInterfaceException |
|
| 893 | - */ |
|
| 894 | - protected function _template_settings() |
|
| 895 | - { |
|
| 896 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 897 | - /** |
|
| 898 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 899 | - * from General_Settings_Admin_Page to here. |
|
| 900 | - */ |
|
| 901 | - $this->_template_args = apply_filters( |
|
| 902 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 903 | - $this->_template_args |
|
| 904 | - ); |
|
| 905 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 906 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 907 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 908 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 909 | - $this->_template_args, |
|
| 910 | - true |
|
| 911 | - ); |
|
| 912 | - $this->display_admin_page_with_sidebar(); |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - /** |
|
| 917 | - * Handler for updating template settings. |
|
| 918 | - * |
|
| 919 | - * @throws EE_Error |
|
| 920 | - * @throws InvalidArgumentException |
|
| 921 | - * @throws InvalidDataTypeException |
|
| 922 | - * @throws InvalidInterfaceException |
|
| 923 | - */ |
|
| 924 | - protected function _update_template_settings() |
|
| 925 | - { |
|
| 926 | - /** |
|
| 927 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 928 | - * from General_Settings_Admin_Page to here. |
|
| 929 | - */ |
|
| 930 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 931 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 932 | - EE_Registry::instance()->CFG->template_settings, |
|
| 933 | - $this->_req_data |
|
| 934 | - ); |
|
| 935 | - // update custom post type slugs and detect if we need to flush rewrite rules |
|
| 936 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 937 | - EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
| 938 | - ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
| 939 | - : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events'); |
|
| 940 | - $what = 'Template Settings'; |
|
| 941 | - $success = $this->_update_espresso_configuration( |
|
| 942 | - $what, |
|
| 943 | - EE_Registry::instance()->CFG->template_settings, |
|
| 944 | - __FILE__, |
|
| 945 | - __FUNCTION__, |
|
| 946 | - __LINE__ |
|
| 947 | - ); |
|
| 948 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) { |
|
| 949 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 950 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
| 951 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 952 | - ); |
|
| 953 | - $rewrite_rules->flush(); |
|
| 954 | - } |
|
| 955 | - $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']); |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * _premium_event_editor_meta_boxes |
|
| 961 | - * add all metaboxes related to the event_editor |
|
| 962 | - * |
|
| 963 | - * @access protected |
|
| 964 | - * @return void |
|
| 965 | - * @throws EE_Error |
|
| 966 | - * @throws InvalidArgumentException |
|
| 967 | - * @throws InvalidDataTypeException |
|
| 968 | - * @throws InvalidInterfaceException |
|
| 969 | - * @throws ReflectionException |
|
| 970 | - */ |
|
| 971 | - protected function _premium_event_editor_meta_boxes() |
|
| 972 | - { |
|
| 973 | - $this->verify_cpt_object(); |
|
| 974 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 975 | - if ( |
|
| 976 | - ! $this->admin_config->useAdvancedEditor() |
|
| 977 | - || ! $this->feature->allowed('use_reg_options_meta_box') |
|
| 978 | - ) { |
|
| 979 | - add_meta_box( |
|
| 980 | - 'espresso_event_editor_event_options', |
|
| 981 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 982 | - [$this, 'registration_options_meta_box'], |
|
| 983 | - $this->page_slug, |
|
| 984 | - 'side', |
|
| 985 | - 'core' |
|
| 986 | - ); |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - |
|
| 991 | - /** |
|
| 992 | - * override caf metabox |
|
| 993 | - * |
|
| 994 | - * @return void |
|
| 995 | - * @throws DomainException |
|
| 996 | - * @throws EE_Error |
|
| 997 | - */ |
|
| 998 | - public function registration_options_meta_box() |
|
| 999 | - { |
|
| 1000 | - $yes_no_values = [ |
|
| 1001 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1002 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1003 | - ]; |
|
| 1004 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1005 | - [ |
|
| 1006 | - EEM_Registration::status_id_cancelled, |
|
| 1007 | - EEM_Registration::status_id_declined, |
|
| 1008 | - EEM_Registration::status_id_incomplete, |
|
| 1009 | - EEM_Registration::status_id_wait_list, |
|
| 1010 | - ], |
|
| 1011 | - true |
|
| 1012 | - ); |
|
| 1013 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1014 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1015 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1016 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1017 | - 'default_reg_status', |
|
| 1018 | - $default_reg_status_values, |
|
| 1019 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1020 | - ); |
|
| 1021 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1022 | - 'display_desc', |
|
| 1023 | - $yes_no_values, |
|
| 1024 | - $this->_cpt_model_obj->display_description() |
|
| 1025 | - ); |
|
| 1026 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1027 | - 'display_ticket_selector', |
|
| 1028 | - $yes_no_values, |
|
| 1029 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1030 | - '', |
|
| 1031 | - '', |
|
| 1032 | - false |
|
| 1033 | - ); |
|
| 1034 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1035 | - 'EVT_default_registration_status', |
|
| 1036 | - $default_reg_status_values, |
|
| 1037 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1038 | - ); |
|
| 1039 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1040 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1041 | - '', |
|
| 1042 | - $template_args, |
|
| 1043 | - $yes_no_values, |
|
| 1044 | - $default_reg_status_values |
|
| 1045 | - ); |
|
| 1046 | - EEH_Template::display_template( |
|
| 1047 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1048 | - $template_args |
|
| 1049 | - ); |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - /** |
|
| 1055 | - * wp_list_table_mods for caf |
|
| 1056 | - * ============================ |
|
| 1057 | - */ |
|
| 1058 | - /** |
|
| 1059 | - * hook into list table filters and provide filters for caffeinated list table |
|
| 1060 | - * |
|
| 1061 | - * @param array $old_filters any existing filters present |
|
| 1062 | - * @param array $list_table_obj the list table object |
|
| 1063 | - * @return array new filters |
|
| 1064 | - * @throws EE_Error |
|
| 1065 | - * @throws InvalidArgumentException |
|
| 1066 | - * @throws InvalidDataTypeException |
|
| 1067 | - * @throws InvalidInterfaceException |
|
| 1068 | - * @throws ReflectionException |
|
| 1069 | - */ |
|
| 1070 | - public function list_table_filters($old_filters, $list_table_obj) |
|
| 1071 | - { |
|
| 1072 | - $filters = []; |
|
| 1073 | - // first month/year filters |
|
| 1074 | - $filters[] = $this->espresso_event_months_dropdown(); |
|
| 1075 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1076 | - // active status dropdown |
|
| 1077 | - if ($status !== 'draft') { |
|
| 1078 | - $filters[] = $this->active_status_dropdown( |
|
| 1079 | - isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
| 1080 | - ); |
|
| 1081 | - $filters[] = $this->venuesDropdown( |
|
| 1082 | - isset($this->_req_data['venue']) ? $this->_req_data['venue'] : '' |
|
| 1083 | - ); |
|
| 1084 | - } |
|
| 1085 | - // category filter |
|
| 1086 | - $filters[] = $this->category_dropdown(); |
|
| 1087 | - return array_merge($old_filters, $filters); |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - |
|
| 1091 | - /** |
|
| 1092 | - * espresso_event_months_dropdown |
|
| 1093 | - * |
|
| 1094 | - * @access public |
|
| 1095 | - * @return string dropdown listing month/year selections for events. |
|
| 1096 | - */ |
|
| 1097 | - public function espresso_event_months_dropdown() |
|
| 1098 | - { |
|
| 1099 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 1100 | - // Note we need to include any other filters that are set! |
|
| 1101 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1102 | - // categories? |
|
| 1103 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1104 | - ? $this->_req_data['EVT_CAT'] |
|
| 1105 | - : null; |
|
| 1106 | - // active status? |
|
| 1107 | - $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
| 1108 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 1109 | - return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - |
|
| 1113 | - /** |
|
| 1114 | - * returns a list of "active" statuses on the event |
|
| 1115 | - * |
|
| 1116 | - * @param string $current_value whatever the current active status is |
|
| 1117 | - * @return string |
|
| 1118 | - */ |
|
| 1119 | - public function active_status_dropdown($current_value = '') |
|
| 1120 | - { |
|
| 1121 | - $select_name = 'active_status'; |
|
| 1122 | - $values = [ |
|
| 1123 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 1124 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
| 1125 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 1126 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 1127 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 1128 | - ]; |
|
| 1129 | - |
|
| 1130 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * returns a list of "venues" |
|
| 1136 | - * |
|
| 1137 | - * @param string $current_value whatever the current active status is |
|
| 1138 | - * @return string |
|
| 1139 | - * @throws EE_Error |
|
| 1140 | - * @throws InvalidArgumentException |
|
| 1141 | - * @throws InvalidDataTypeException |
|
| 1142 | - * @throws InvalidInterfaceException |
|
| 1143 | - * @throws ReflectionException |
|
| 1144 | - */ |
|
| 1145 | - protected function venuesDropdown($current_value = '') |
|
| 1146 | - { |
|
| 1147 | - $select_name = 'venue'; |
|
| 1148 | - $values = [ |
|
| 1149 | - '' => esc_html__('All Venues', 'event_espresso'), |
|
| 1150 | - ]; |
|
| 1151 | - // populate the list of venues. |
|
| 1152 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1153 | - $venues = $venue_model->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
|
| 1154 | - |
|
| 1155 | - foreach ($venues as $venue) { |
|
| 1156 | - $values[ $venue->ID() ] = $venue->name(); |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - |
|
| 1163 | - /** |
|
| 1164 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
| 1165 | - * |
|
| 1166 | - * @access public |
|
| 1167 | - * @return string html |
|
| 1168 | - */ |
|
| 1169 | - public function category_dropdown() |
|
| 1170 | - { |
|
| 1171 | - $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 1172 | - return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - |
|
| 1176 | - /** |
|
| 1177 | - * get total number of events today |
|
| 1178 | - * |
|
| 1179 | - * @access public |
|
| 1180 | - * @return int |
|
| 1181 | - * @throws EE_Error |
|
| 1182 | - * @throws InvalidArgumentException |
|
| 1183 | - * @throws InvalidDataTypeException |
|
| 1184 | - * @throws InvalidInterfaceException |
|
| 1185 | - */ |
|
| 1186 | - public function total_events_today() |
|
| 1187 | - { |
|
| 1188 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1189 | - 'DTT_EVT_start', |
|
| 1190 | - date('Y-m-d') . ' 00:00:00', |
|
| 1191 | - 'Y-m-d H:i:s', |
|
| 1192 | - 'UTC' |
|
| 1193 | - ); |
|
| 1194 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1195 | - 'DTT_EVT_start', |
|
| 1196 | - date('Y-m-d') . ' 23:59:59', |
|
| 1197 | - 'Y-m-d H:i:s', |
|
| 1198 | - 'UTC' |
|
| 1199 | - ); |
|
| 1200 | - $where = [ |
|
| 1201 | - 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
| 1202 | - ]; |
|
| 1203 | - return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - |
|
| 1207 | - /** |
|
| 1208 | - * get total number of events this month |
|
| 1209 | - * |
|
| 1210 | - * @access public |
|
| 1211 | - * @return int |
|
| 1212 | - * @throws EE_Error |
|
| 1213 | - * @throws InvalidArgumentException |
|
| 1214 | - * @throws InvalidDataTypeException |
|
| 1215 | - * @throws InvalidInterfaceException |
|
| 1216 | - */ |
|
| 1217 | - public function total_events_this_month() |
|
| 1218 | - { |
|
| 1219 | - // Dates |
|
| 1220 | - $this_year_r = date('Y'); |
|
| 1221 | - $this_month_r = date('m'); |
|
| 1222 | - $days_this_month = date('t'); |
|
| 1223 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1224 | - 'DTT_EVT_start', |
|
| 1225 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1226 | - 'Y-m-d H:i:s', |
|
| 1227 | - 'UTC' |
|
| 1228 | - ); |
|
| 1229 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1230 | - 'DTT_EVT_start', |
|
| 1231 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1232 | - 'Y-m-d H:i:s', |
|
| 1233 | - 'UTC' |
|
| 1234 | - ); |
|
| 1235 | - $where = [ |
|
| 1236 | - 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
| 1237 | - ]; |
|
| 1238 | - return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - /** DEFAULT TICKETS STUFF **/ |
|
| 1243 | - |
|
| 1244 | - /** |
|
| 1245 | - * Output default tickets list table view. |
|
| 1246 | - * |
|
| 1247 | - * @throws DomainException |
|
| 1248 | - * @throws EE_Error |
|
| 1249 | - * @throws InvalidArgumentException |
|
| 1250 | - * @throws InvalidDataTypeException |
|
| 1251 | - * @throws InvalidInterfaceException |
|
| 1252 | - */ |
|
| 1253 | - public function _tickets_overview_list_table() |
|
| 1254 | - { |
|
| 1255 | - if ( |
|
| 1256 | - $this->admin_config->useAdvancedEditor() |
|
| 1257 | - && $this->feature->allowed('use_default_ticket_manager') |
|
| 1258 | - ) { |
|
| 1259 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1260 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1261 | - EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php', |
|
| 1262 | - [], |
|
| 1263 | - true |
|
| 1264 | - ); |
|
| 1265 | - $this->display_admin_page_with_no_sidebar(); |
|
| 1266 | - } else { |
|
| 1267 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1268 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * @param int $per_page |
|
| 1275 | - * @param bool $count |
|
| 1276 | - * @param bool $trashed |
|
| 1277 | - * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1278 | - * @throws EE_Error |
|
| 1279 | - * @throws InvalidArgumentException |
|
| 1280 | - * @throws InvalidDataTypeException |
|
| 1281 | - * @throws InvalidInterfaceException |
|
| 1282 | - */ |
|
| 1283 | - public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
| 1284 | - { |
|
| 1285 | - $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
| 1286 | - $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
| 1287 | - switch ($orderby) { |
|
| 1288 | - case 'TKT_name': |
|
| 1289 | - $orderby = ['TKT_name' => $order]; |
|
| 1290 | - break; |
|
| 1291 | - case 'TKT_price': |
|
| 1292 | - $orderby = ['TKT_price' => $order]; |
|
| 1293 | - break; |
|
| 1294 | - case 'TKT_uses': |
|
| 1295 | - $orderby = ['TKT_uses' => $order]; |
|
| 1296 | - break; |
|
| 1297 | - case 'TKT_min': |
|
| 1298 | - $orderby = ['TKT_min' => $order]; |
|
| 1299 | - break; |
|
| 1300 | - case 'TKT_max': |
|
| 1301 | - $orderby = ['TKT_max' => $order]; |
|
| 1302 | - break; |
|
| 1303 | - case 'TKT_qty': |
|
| 1304 | - $orderby = ['TKT_qty' => $order]; |
|
| 1305 | - break; |
|
| 1306 | - } |
|
| 1307 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1308 | - ? $this->_req_data['paged'] |
|
| 1309 | - : 1; |
|
| 1310 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1311 | - ? $this->_req_data['perpage'] |
|
| 1312 | - : $per_page; |
|
| 1313 | - $_where = [ |
|
| 1314 | - 'TKT_is_default' => 1, |
|
| 1315 | - 'TKT_deleted' => $trashed, |
|
| 1316 | - ]; |
|
| 1317 | - $offset = ($current_page - 1) * $per_page; |
|
| 1318 | - $limit = [$offset, $per_page]; |
|
| 1319 | - if (isset($this->_req_data['s'])) { |
|
| 1320 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1321 | - $_where['OR'] = [ |
|
| 1322 | - 'TKT_name' => ['LIKE', $sstr], |
|
| 1323 | - 'TKT_description' => ['LIKE', $sstr], |
|
| 1324 | - ]; |
|
| 1325 | - } |
|
| 1326 | - $query_params = [ |
|
| 1327 | - $_where, |
|
| 1328 | - 'order_by' => $orderby, |
|
| 1329 | - 'limit' => $limit, |
|
| 1330 | - 'group_by' => 'TKT_ID', |
|
| 1331 | - ]; |
|
| 1332 | - if ($count) { |
|
| 1333 | - return EEM_Ticket::instance()->count_deleted_and_undeleted([$_where]); |
|
| 1334 | - } |
|
| 1335 | - return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * @param bool $trash |
|
| 1341 | - * @throws EE_Error |
|
| 1342 | - * @throws InvalidArgumentException |
|
| 1343 | - * @throws InvalidDataTypeException |
|
| 1344 | - * @throws InvalidInterfaceException |
|
| 1345 | - */ |
|
| 1346 | - protected function _trash_or_restore_ticket($trash = false) |
|
| 1347 | - { |
|
| 1348 | - $success = 1; |
|
| 1349 | - $TKT = EEM_Ticket::instance(); |
|
| 1350 | - // checkboxes? |
|
| 1351 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1352 | - // if array has more than one element then success message should be plural |
|
| 1353 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1354 | - // cycle thru the boxes |
|
| 1355 | - foreach ($this->_req_data['checkbox'] as $TKT_ID) { |
|
| 1356 | - if ($trash) { |
|
| 1357 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1358 | - $success = 0; |
|
| 1359 | - } |
|
| 1360 | - } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1361 | - $success = 0; |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - } else { |
|
| 1365 | - // grab single id and trash |
|
| 1366 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1367 | - if ($trash) { |
|
| 1368 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1369 | - $success = 0; |
|
| 1370 | - } |
|
| 1371 | - } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1372 | - $success = 0; |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1376 | - $query_args = [ |
|
| 1377 | - 'action' => 'ticket_list_table', |
|
| 1378 | - 'status' => $trash ? '' : 'trashed', |
|
| 1379 | - ]; |
|
| 1380 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - |
|
| 1384 | - /** |
|
| 1385 | - * Handles trashing default ticket. |
|
| 1386 | - * |
|
| 1387 | - * @throws EE_Error |
|
| 1388 | - * @throws InvalidArgumentException |
|
| 1389 | - * @throws InvalidDataTypeException |
|
| 1390 | - * @throws InvalidInterfaceException |
|
| 1391 | - * @throws ReflectionException |
|
| 1392 | - */ |
|
| 1393 | - protected function _delete_ticket() |
|
| 1394 | - { |
|
| 1395 | - $success = 1; |
|
| 1396 | - // checkboxes? |
|
| 1397 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1398 | - // if array has more than one element then success message should be plural |
|
| 1399 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1400 | - // cycle thru the boxes |
|
| 1401 | - foreach ($this->_req_data['checkbox'] as $TKT_ID) { |
|
| 1402 | - // delete |
|
| 1403 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1404 | - $success = 0; |
|
| 1405 | - } |
|
| 1406 | - } |
|
| 1407 | - } else { |
|
| 1408 | - // grab single id and trash |
|
| 1409 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1410 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1411 | - $success = 0; |
|
| 1412 | - } |
|
| 1413 | - } |
|
| 1414 | - $action_desc = 'deleted'; |
|
| 1415 | - // fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1416 | - $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1417 | - [['TKT_is_default' => 1]], |
|
| 1418 | - 'TKT_ID', |
|
| 1419 | - true |
|
| 1420 | - ); |
|
| 1421 | - $query_args = $ticket_count |
|
| 1422 | - ? [] |
|
| 1423 | - : [ |
|
| 1424 | - 'action' => 'ticket_list_table', |
|
| 1425 | - 'status' => 'trashed', |
|
| 1426 | - ]; |
|
| 1427 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - |
|
| 1431 | - /** |
|
| 1432 | - * @param int $TKT_ID |
|
| 1433 | - * @return bool|int |
|
| 1434 | - * @throws EE_Error |
|
| 1435 | - * @throws InvalidArgumentException |
|
| 1436 | - * @throws InvalidDataTypeException |
|
| 1437 | - * @throws InvalidInterfaceException |
|
| 1438 | - * @throws ReflectionException |
|
| 1439 | - */ |
|
| 1440 | - protected function _delete_the_ticket($TKT_ID) |
|
| 1441 | - { |
|
| 1442 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1443 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1444 | - return false; |
|
| 1445 | - } |
|
| 1446 | - $ticket->_remove_relations('Datetime'); |
|
| 1447 | - // delete all related prices first |
|
| 1448 | - $ticket->delete_related_permanently('Price'); |
|
| 1449 | - return $ticket->delete_permanently(); |
|
| 1450 | - } |
|
| 19 | + /** |
|
| 20 | + * @var EE_Admin_Config |
|
| 21 | + */ |
|
| 22 | + protected $admin_config; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var AdvancedEditorAdminFormSection |
|
| 26 | + */ |
|
| 27 | + protected $advanced_editor_admin_form; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Extend_Events_Admin_Page constructor. |
|
| 32 | + * |
|
| 33 | + * @param bool $routing |
|
| 34 | + * @throws ReflectionException |
|
| 35 | + */ |
|
| 36 | + public function __construct($routing = true) |
|
| 37 | + { |
|
| 38 | + if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 39 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 40 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 41 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 42 | + } |
|
| 43 | + parent::__construct($routing); |
|
| 44 | + $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Sets routes. |
|
| 50 | + * |
|
| 51 | + * @throws EE_Error |
|
| 52 | + * @throws InvalidArgumentException |
|
| 53 | + * @throws InvalidDataTypeException |
|
| 54 | + * @throws InvalidInterfaceException |
|
| 55 | + * @throws Exception |
|
| 56 | + */ |
|
| 57 | + protected function _extend_page_config() |
|
| 58 | + { |
|
| 59 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 60 | + // is there a evt_id in the request? |
|
| 61 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 62 | + ? $this->_req_data['EVT_ID'] |
|
| 63 | + : 0; |
|
| 64 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 65 | + // tkt_id? |
|
| 66 | + $tkt_id = |
|
| 67 | + ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
| 68 | + ? $this->_req_data['TKT_ID'] |
|
| 69 | + : 0; |
|
| 70 | + $new_page_routes = [ |
|
| 71 | + 'duplicate_event' => [ |
|
| 72 | + 'func' => '_duplicate_event', |
|
| 73 | + 'capability' => 'ee_edit_event', |
|
| 74 | + 'obj_id' => $evt_id, |
|
| 75 | + 'noheader' => true, |
|
| 76 | + ], |
|
| 77 | + 'import_page' => [ |
|
| 78 | + 'func' => '_import_page', |
|
| 79 | + 'capability' => 'import', |
|
| 80 | + ], |
|
| 81 | + 'import' => [ |
|
| 82 | + 'func' => '_import_events', |
|
| 83 | + 'capability' => 'import', |
|
| 84 | + 'noheader' => true, |
|
| 85 | + ], |
|
| 86 | + 'import_events' => [ |
|
| 87 | + 'func' => '_import_events', |
|
| 88 | + 'capability' => 'import', |
|
| 89 | + 'noheader' => true, |
|
| 90 | + ], |
|
| 91 | + 'export_events' => [ |
|
| 92 | + 'func' => '_events_export', |
|
| 93 | + 'capability' => 'export', |
|
| 94 | + 'noheader' => true, |
|
| 95 | + ], |
|
| 96 | + 'export_categories' => [ |
|
| 97 | + 'func' => '_categories_export', |
|
| 98 | + 'capability' => 'export', |
|
| 99 | + 'noheader' => true, |
|
| 100 | + ], |
|
| 101 | + 'sample_export_file' => [ |
|
| 102 | + 'func' => '_sample_export_file', |
|
| 103 | + 'capability' => 'export', |
|
| 104 | + 'noheader' => true, |
|
| 105 | + ], |
|
| 106 | + 'update_template_settings' => [ |
|
| 107 | + 'func' => '_update_template_settings', |
|
| 108 | + 'capability' => 'manage_options', |
|
| 109 | + 'noheader' => true, |
|
| 110 | + ], |
|
| 111 | + 'ticket_list_table' => [ |
|
| 112 | + 'func' => '_tickets_overview_list_table', |
|
| 113 | + 'capability' => 'ee_read_default_tickets', |
|
| 114 | + ], |
|
| 115 | + ]; |
|
| 116 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 117 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
| 118 | + // don't load these meta boxes if using the advanced editor |
|
| 119 | + if ( |
|
| 120 | + ! $this->admin_config->useAdvancedEditor() |
|
| 121 | + || ! $this->feature->allowed('use_default_ticket_manager') |
|
| 122 | + ) { |
|
| 123 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 124 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
| 125 | + |
|
| 126 | + $legacy_editor_page_routes = [ |
|
| 127 | + 'trash_ticket' => [ |
|
| 128 | + 'func' => '_trash_or_restore_ticket', |
|
| 129 | + 'capability' => 'ee_delete_default_ticket', |
|
| 130 | + 'obj_id' => $tkt_id, |
|
| 131 | + 'noheader' => true, |
|
| 132 | + 'args' => ['trash' => true], |
|
| 133 | + ], |
|
| 134 | + 'trash_tickets' => [ |
|
| 135 | + 'func' => '_trash_or_restore_ticket', |
|
| 136 | + 'capability' => 'ee_delete_default_tickets', |
|
| 137 | + 'noheader' => true, |
|
| 138 | + 'args' => ['trash' => true], |
|
| 139 | + ], |
|
| 140 | + 'restore_ticket' => [ |
|
| 141 | + 'func' => '_trash_or_restore_ticket', |
|
| 142 | + 'capability' => 'ee_delete_default_ticket', |
|
| 143 | + 'obj_id' => $tkt_id, |
|
| 144 | + 'noheader' => true, |
|
| 145 | + ], |
|
| 146 | + 'restore_tickets' => [ |
|
| 147 | + 'func' => '_trash_or_restore_ticket', |
|
| 148 | + 'capability' => 'ee_delete_default_tickets', |
|
| 149 | + 'noheader' => true, |
|
| 150 | + ], |
|
| 151 | + 'delete_ticket' => [ |
|
| 152 | + 'func' => '_delete_ticket', |
|
| 153 | + 'capability' => 'ee_delete_default_ticket', |
|
| 154 | + 'obj_id' => $tkt_id, |
|
| 155 | + 'noheader' => true, |
|
| 156 | + ], |
|
| 157 | + 'delete_tickets' => [ |
|
| 158 | + 'func' => '_delete_ticket', |
|
| 159 | + 'capability' => 'ee_delete_default_tickets', |
|
| 160 | + 'noheader' => true, |
|
| 161 | + ], |
|
| 162 | + ]; |
|
| 163 | + $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 167 | + // partial route/config override |
|
| 168 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
| 169 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
| 170 | + // add tickets tab but only if there are more than one default ticket! |
|
| 171 | + $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 172 | + [['TKT_is_default' => 1]], |
|
| 173 | + 'TKT_ID', |
|
| 174 | + true |
|
| 175 | + ); |
|
| 176 | + if ($tkt_count > 1) { |
|
| 177 | + $new_page_config = [ |
|
| 178 | + 'ticket_list_table' => [ |
|
| 179 | + 'nav' => [ |
|
| 180 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
| 181 | + 'order' => 60, |
|
| 182 | + ], |
|
| 183 | + 'list_table' => 'Tickets_List_Table', |
|
| 184 | + 'require_nonce' => false, |
|
| 185 | + ], |
|
| 186 | + ]; |
|
| 187 | + } |
|
| 188 | + // template settings |
|
| 189 | + $new_page_config['template_settings'] = [ |
|
| 190 | + 'nav' => [ |
|
| 191 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 192 | + 'order' => 30, |
|
| 193 | + ], |
|
| 194 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']), |
|
| 195 | + 'help_tabs' => [ |
|
| 196 | + 'general_settings_templates_help_tab' => [ |
|
| 197 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 198 | + 'filename' => 'general_settings_templates', |
|
| 199 | + ], |
|
| 200 | + ], |
|
| 201 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 202 | + // 'help_tour' => ['Templates_Help_Tour'], |
|
| 203 | + 'require_nonce' => false, |
|
| 204 | + ]; |
|
| 205 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 206 | + // add filters and actions |
|
| 207 | + // modifying _views |
|
| 208 | + add_filter( |
|
| 209 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
| 210 | + [$this, 'add_additional_datetime_button'], |
|
| 211 | + 10, |
|
| 212 | + 2 |
|
| 213 | + ); |
|
| 214 | + add_filter( |
|
| 215 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
| 216 | + [$this, 'add_datetime_clone_button'], |
|
| 217 | + 10, |
|
| 218 | + 2 |
|
| 219 | + ); |
|
| 220 | + add_filter( |
|
| 221 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
| 222 | + [$this, 'datetime_timezones_template'], |
|
| 223 | + 10, |
|
| 224 | + 2 |
|
| 225 | + ); |
|
| 226 | + // filters for event list table |
|
| 227 | + add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2); |
|
| 228 | + add_filter( |
|
| 229 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 230 | + [$this, 'extra_list_table_actions'], |
|
| 231 | + 10, |
|
| 232 | + 2 |
|
| 233 | + ); |
|
| 234 | + // legend item |
|
| 235 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']); |
|
| 236 | + add_action('admin_init', [$this, 'admin_init']); |
|
| 237 | + // load additional handlers |
|
| 238 | + $this->handleActionRequest(); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + private function getRequestAction() |
|
| 243 | + { |
|
| 244 | + return isset($this->_req_data['action']) ? sanitize_key($this->_req_data['action']) : null; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @throws Exception |
|
| 250 | + */ |
|
| 251 | + private function handleActionRequest() |
|
| 252 | + { |
|
| 253 | + $action = $this->getRequestAction(); |
|
| 254 | + if ($action) { |
|
| 255 | + // setup Advanced Editor ??? |
|
| 256 | + if ($action === 'default_event_settings' || $action === 'update_default_event_settings') { |
|
| 257 | + $this->advanced_editor_admin_form = $this->loader->getShared( |
|
| 258 | + 'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection' |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * admin_init |
|
| 267 | + */ |
|
| 268 | + public function admin_init() |
|
| 269 | + { |
|
| 270 | + EE_Registry::$i18n_js_strings = array_merge( |
|
| 271 | + EE_Registry::$i18n_js_strings, |
|
| 272 | + [ |
|
| 273 | + 'image_confirm' => esc_html__( |
|
| 274 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 275 | + 'event_espresso' |
|
| 276 | + ), |
|
| 277 | + 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
| 278 | + 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
| 279 | + 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
| 280 | + 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
| 281 | + 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
| 282 | + ] |
|
| 283 | + ); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Add per page screen options to the default ticket list table view. |
|
| 289 | + * |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + * @throws InvalidDataTypeException |
|
| 292 | + * @throws InvalidInterfaceException |
|
| 293 | + */ |
|
| 294 | + protected function _add_screen_options_ticket_list_table() |
|
| 295 | + { |
|
| 296 | + $this->_per_page_screen_option(); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param string $return |
|
| 302 | + * @param int $id |
|
| 303 | + * @param string $new_title |
|
| 304 | + * @param string $new_slug |
|
| 305 | + * @return string |
|
| 306 | + */ |
|
| 307 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 308 | + { |
|
| 309 | + $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
| 310 | + // make sure this is only when editing |
|
| 311 | + if (! empty($id)) { |
|
| 312 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 313 | + ['action' => 'duplicate_event', 'EVT_ID' => $id], |
|
| 314 | + $this->_admin_base_url |
|
| 315 | + ); |
|
| 316 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 317 | + $return .= '<a href="' |
|
| 318 | + . $href |
|
| 319 | + . '" title="' |
|
| 320 | + . $title |
|
| 321 | + . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
| 322 | + . $title |
|
| 323 | + . '</a>'; |
|
| 324 | + } |
|
| 325 | + return $return; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Set the list table views for the default ticket list table view. |
|
| 331 | + */ |
|
| 332 | + public function _set_list_table_views_ticket_list_table() |
|
| 333 | + { |
|
| 334 | + $this->_views = [ |
|
| 335 | + 'all' => [ |
|
| 336 | + 'slug' => 'all', |
|
| 337 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 338 | + 'count' => 0, |
|
| 339 | + 'bulk_action' => [ |
|
| 340 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 341 | + ], |
|
| 342 | + ], |
|
| 343 | + 'trashed' => [ |
|
| 344 | + 'slug' => 'trashed', |
|
| 345 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 346 | + 'count' => 0, |
|
| 347 | + 'bulk_action' => [ |
|
| 348 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 349 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 350 | + ], |
|
| 351 | + ], |
|
| 352 | + ]; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Enqueue scripts and styles for the event editor. |
|
| 358 | + */ |
|
| 359 | + public function load_scripts_styles_edit() |
|
| 360 | + { |
|
| 361 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
| 362 | + wp_register_script( |
|
| 363 | + 'ee-event-editor-heartbeat', |
|
| 364 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 365 | + ['ee_admin_js', 'heartbeat'], |
|
| 366 | + EVENT_ESPRESSO_VERSION, |
|
| 367 | + true |
|
| 368 | + ); |
|
| 369 | + wp_enqueue_script('ee-accounting'); |
|
| 370 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
| 371 | + } |
|
| 372 | + wp_enqueue_script('event_editor_js'); |
|
| 373 | + // styles |
|
| 374 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Returns template for the additional datetime. |
|
| 380 | + * |
|
| 381 | + * @param $template |
|
| 382 | + * @param $template_args |
|
| 383 | + * @return mixed |
|
| 384 | + * @throws DomainException |
|
| 385 | + */ |
|
| 386 | + public function add_additional_datetime_button($template, $template_args) |
|
| 387 | + { |
|
| 388 | + return EEH_Template::display_template( |
|
| 389 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 390 | + $template_args, |
|
| 391 | + true |
|
| 392 | + ); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Returns the template for cloning a datetime. |
|
| 398 | + * |
|
| 399 | + * @param $template |
|
| 400 | + * @param $template_args |
|
| 401 | + * @return mixed |
|
| 402 | + * @throws DomainException |
|
| 403 | + */ |
|
| 404 | + public function add_datetime_clone_button($template, $template_args) |
|
| 405 | + { |
|
| 406 | + return EEH_Template::display_template( |
|
| 407 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 408 | + $template_args, |
|
| 409 | + true |
|
| 410 | + ); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Returns the template for datetime timezones. |
|
| 416 | + * |
|
| 417 | + * @param $template |
|
| 418 | + * @param $template_args |
|
| 419 | + * @return mixed |
|
| 420 | + * @throws DomainException |
|
| 421 | + */ |
|
| 422 | + public function datetime_timezones_template($template, $template_args) |
|
| 423 | + { |
|
| 424 | + return EEH_Template::display_template( |
|
| 425 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 426 | + $template_args, |
|
| 427 | + true |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * Sets the views for the default list table view. |
|
| 434 | + * |
|
| 435 | + * @throws EE_Error |
|
| 436 | + */ |
|
| 437 | + protected function _set_list_table_views_default() |
|
| 438 | + { |
|
| 439 | + parent::_set_list_table_views_default(); |
|
| 440 | + $new_views = [ |
|
| 441 | + 'today' => [ |
|
| 442 | + 'slug' => 'today', |
|
| 443 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
| 444 | + 'count' => $this->total_events_today(), |
|
| 445 | + 'bulk_action' => [ |
|
| 446 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 447 | + ], |
|
| 448 | + ], |
|
| 449 | + 'month' => [ |
|
| 450 | + 'slug' => 'month', |
|
| 451 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 452 | + 'count' => $this->total_events_this_month(), |
|
| 453 | + 'bulk_action' => [ |
|
| 454 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 455 | + ], |
|
| 456 | + ], |
|
| 457 | + ]; |
|
| 458 | + $this->_views = array_merge($this->_views, $new_views); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Returns the extra action links for the default list table view. |
|
| 464 | + * |
|
| 465 | + * @param array $action_links |
|
| 466 | + * @param EE_Event $event |
|
| 467 | + * @return array |
|
| 468 | + * @throws EE_Error |
|
| 469 | + * @throws InvalidArgumentException |
|
| 470 | + * @throws InvalidDataTypeException |
|
| 471 | + * @throws InvalidInterfaceException |
|
| 472 | + * @throws ReflectionException |
|
| 473 | + */ |
|
| 474 | + public function extra_list_table_actions(array $action_links, EE_Event $event) |
|
| 475 | + { |
|
| 476 | + if ( |
|
| 477 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 478 | + 'ee_read_registrations', |
|
| 479 | + 'espresso_registrations_reports', |
|
| 480 | + $event->ID() |
|
| 481 | + ) |
|
| 482 | + ) { |
|
| 483 | + $reports_query_args = [ |
|
| 484 | + 'action' => 'reports', |
|
| 485 | + 'EVT_ID' => $event->ID(), |
|
| 486 | + ]; |
|
| 487 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
| 488 | + $action_links[] = '<a href="' |
|
| 489 | + . $reports_link |
|
| 490 | + . '" title="' |
|
| 491 | + . esc_attr__('View Report', 'event_espresso') |
|
| 492 | + . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
| 493 | + . "\n\t"; |
|
| 494 | + } |
|
| 495 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 496 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 497 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
| 498 | + 'see_notifications_for', |
|
| 499 | + null, |
|
| 500 | + ['EVT_ID' => $event->ID()] |
|
| 501 | + ); |
|
| 502 | + } |
|
| 503 | + return $action_links; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * @param $items |
|
| 509 | + * @return mixed |
|
| 510 | + */ |
|
| 511 | + public function additional_legend_items($items) |
|
| 512 | + { |
|
| 513 | + if ( |
|
| 514 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 515 | + 'ee_read_registrations', |
|
| 516 | + 'espresso_registrations_reports' |
|
| 517 | + ) |
|
| 518 | + ) { |
|
| 519 | + $items['reports'] = [ |
|
| 520 | + 'class' => 'dashicons dashicons-chart-bar', |
|
| 521 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
| 522 | + ]; |
|
| 523 | + } |
|
| 524 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 525 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 526 | + // $related_for_icon can sometimes be a string so 'css_class' would be an illegal offset |
|
| 527 | + // (can only use numeric offsets when treating strings as arrays) |
|
| 528 | + if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) { |
|
| 529 | + $items['view_related_messages'] = [ |
|
| 530 | + 'class' => $related_for_icon['css_class'], |
|
| 531 | + 'desc' => $related_for_icon['label'], |
|
| 532 | + ]; |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + return $items; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * This is the callback method for the duplicate event route |
|
| 541 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
| 542 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
| 543 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
| 544 | + * After duplication the redirect is to the new event edit page. |
|
| 545 | + * |
|
| 546 | + * @return void |
|
| 547 | + * @throws EE_Error If EE_Event is not available with given ID |
|
| 548 | + * @throws InvalidArgumentException |
|
| 549 | + * @throws InvalidDataTypeException |
|
| 550 | + * @throws InvalidInterfaceException |
|
| 551 | + * @throws ReflectionException |
|
| 552 | + * @access protected |
|
| 553 | + */ |
|
| 554 | + protected function _duplicate_event() |
|
| 555 | + { |
|
| 556 | + // first make sure the ID for the event is in the request. |
|
| 557 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
| 558 | + if (! isset($this->_req_data['EVT_ID'])) { |
|
| 559 | + EE_Error::add_error( |
|
| 560 | + esc_html__( |
|
| 561 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
| 562 | + 'event_espresso' |
|
| 563 | + ), |
|
| 564 | + __FILE__, |
|
| 565 | + __FUNCTION__, |
|
| 566 | + __LINE__ |
|
| 567 | + ); |
|
| 568 | + $this->_redirect_after_action(false, '', '', [], true); |
|
| 569 | + return; |
|
| 570 | + } |
|
| 571 | + // k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
| 572 | + $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
| 573 | + if (! $orig_event instanceof EE_Event) { |
|
| 574 | + throw new EE_Error( |
|
| 575 | + sprintf( |
|
| 576 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
| 577 | + $this->_req_data['EVT_ID'] |
|
| 578 | + ) |
|
| 579 | + ); |
|
| 580 | + } |
|
| 581 | + // k now let's clone the $orig_event before getting relations |
|
| 582 | + $new_event = clone $orig_event; |
|
| 583 | + // original datetimes |
|
| 584 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
| 585 | + // other original relations |
|
| 586 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
| 587 | + // reset the ID and modify other details to make it clear this is a dupe |
|
| 588 | + $new_event->set('EVT_ID', 0); |
|
| 589 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 590 | + $new_event->set('EVT_name', $new_name); |
|
| 591 | + $new_event->set( |
|
| 592 | + 'EVT_slug', |
|
| 593 | + wp_unique_post_slug( |
|
| 594 | + sanitize_title($orig_event->name()), |
|
| 595 | + 0, |
|
| 596 | + 'publish', |
|
| 597 | + 'espresso_events', |
|
| 598 | + 0 |
|
| 599 | + ) |
|
| 600 | + ); |
|
| 601 | + $new_event->set('status', 'draft'); |
|
| 602 | + // duplicate discussion settings |
|
| 603 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
| 604 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
| 605 | + // save the new event |
|
| 606 | + $new_event->save(); |
|
| 607 | + // venues |
|
| 608 | + foreach ($orig_ven as $ven) { |
|
| 609 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
| 610 | + } |
|
| 611 | + $new_event->save(); |
|
| 612 | + // now we need to get the question group relations and handle that |
|
| 613 | + // first primary question groups |
|
| 614 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
| 615 | + 'Question_Group', |
|
| 616 | + [['Event_Question_Group.EQG_primary' => true]] |
|
| 617 | + ); |
|
| 618 | + if (! empty($orig_primary_qgs)) { |
|
| 619 | + foreach ($orig_primary_qgs as $id => $obj) { |
|
| 620 | + if ($obj instanceof EE_Question_Group) { |
|
| 621 | + $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + // next additional attendee question groups |
|
| 626 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
| 627 | + 'Question_Group', |
|
| 628 | + [['Event_Question_Group.EQG_additional' => true]] |
|
| 629 | + ); |
|
| 630 | + if (! empty($orig_additional_qgs)) { |
|
| 631 | + foreach ($orig_additional_qgs as $id => $obj) { |
|
| 632 | + if ($obj instanceof EE_Question_Group) { |
|
| 633 | + $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $new_event->save(); |
|
| 639 | + |
|
| 640 | + // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
| 641 | + $cloned_tickets = []; |
|
| 642 | + foreach ($orig_datetimes as $orig_dtt) { |
|
| 643 | + if (! $orig_dtt instanceof EE_Datetime) { |
|
| 644 | + continue; |
|
| 645 | + } |
|
| 646 | + $new_dtt = clone $orig_dtt; |
|
| 647 | + $orig_tkts = $orig_dtt->tickets(); |
|
| 648 | + // save new dtt then add to event |
|
| 649 | + $new_dtt->set('DTT_ID', 0); |
|
| 650 | + $new_dtt->set('DTT_sold', 0); |
|
| 651 | + $new_dtt->set_reserved(0); |
|
| 652 | + $new_dtt->save(); |
|
| 653 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
| 654 | + $new_event->save(); |
|
| 655 | + // now let's get the ticket relations setup. |
|
| 656 | + foreach ((array) $orig_tkts as $orig_tkt) { |
|
| 657 | + // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
| 658 | + if (! $orig_tkt instanceof EE_Ticket) { |
|
| 659 | + continue; |
|
| 660 | + } |
|
| 661 | + // is this ticket archived? If it is then let's skip |
|
| 662 | + if ($orig_tkt->get('TKT_deleted')) { |
|
| 663 | + continue; |
|
| 664 | + } |
|
| 665 | + // does this original ticket already exist in the clone_tickets cache? |
|
| 666 | + // If so we'll just use the new ticket from it. |
|
| 667 | + if (isset($cloned_tickets[ $orig_tkt->ID() ])) { |
|
| 668 | + $new_tkt = $cloned_tickets[ $orig_tkt->ID() ]; |
|
| 669 | + } else { |
|
| 670 | + $new_tkt = clone $orig_tkt; |
|
| 671 | + // get relations on the $orig_tkt that we need to setup. |
|
| 672 | + $orig_prices = $orig_tkt->prices(); |
|
| 673 | + $new_tkt->set('TKT_ID', 0); |
|
| 674 | + $new_tkt->set('TKT_sold', 0); |
|
| 675 | + $new_tkt->set('TKT_reserved', 0); |
|
| 676 | + $new_tkt->save(); // make sure new ticket has ID. |
|
| 677 | + // price relations on new ticket need to be setup. |
|
| 678 | + foreach ($orig_prices as $orig_price) { |
|
| 679 | + $new_price = clone $orig_price; |
|
| 680 | + $new_price->set('PRC_ID', 0); |
|
| 681 | + $new_price->save(); |
|
| 682 | + $new_tkt->_add_relation_to($new_price, 'Price'); |
|
| 683 | + $new_tkt->save(); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + do_action( |
|
| 687 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
| 688 | + $orig_tkt, |
|
| 689 | + $new_tkt, |
|
| 690 | + $orig_prices, |
|
| 691 | + $orig_event, |
|
| 692 | + $orig_dtt, |
|
| 693 | + $new_dtt |
|
| 694 | + ); |
|
| 695 | + } |
|
| 696 | + // k now we can add the new ticket as a relation to the new datetime |
|
| 697 | + // and make sure its added to our cached $cloned_tickets array |
|
| 698 | + // for use with later datetimes that have the same ticket. |
|
| 699 | + $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
| 700 | + $new_dtt->save(); |
|
| 701 | + $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt; |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | + // clone taxonomy information |
|
| 705 | + $taxonomies_to_clone_with = apply_filters( |
|
| 706 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
| 707 | + ['espresso_event_categories', 'espresso_event_type', 'post_tag'] |
|
| 708 | + ); |
|
| 709 | + // get terms for original event (notice) |
|
| 710 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
| 711 | + // loop through terms and add them to new event. |
|
| 712 | + foreach ($orig_terms as $term) { |
|
| 713 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + // duplicate other core WP_Post items for this event. |
|
| 717 | + // post thumbnail (feature image). |
|
| 718 | + $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
| 719 | + if ($feature_image_id) { |
|
| 720 | + update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + // duplicate page_template setting |
|
| 724 | + $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
| 725 | + if ($page_template) { |
|
| 726 | + update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
| 730 | + // now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
| 731 | + if ($new_event->ID()) { |
|
| 732 | + $redirect_args = [ |
|
| 733 | + 'post' => $new_event->ID(), |
|
| 734 | + 'action' => 'edit', |
|
| 735 | + ]; |
|
| 736 | + EE_Error::add_success( |
|
| 737 | + esc_html__( |
|
| 738 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
| 739 | + 'event_espresso' |
|
| 740 | + ) |
|
| 741 | + ); |
|
| 742 | + } else { |
|
| 743 | + $redirect_args = [ |
|
| 744 | + 'action' => 'default', |
|
| 745 | + ]; |
|
| 746 | + EE_Error::add_error( |
|
| 747 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
| 748 | + __FILE__, |
|
| 749 | + __FUNCTION__, |
|
| 750 | + __LINE__ |
|
| 751 | + ); |
|
| 752 | + } |
|
| 753 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * Generates output for the import page. |
|
| 759 | + * |
|
| 760 | + * @throws DomainException |
|
| 761 | + * @throws EE_Error |
|
| 762 | + * @throws InvalidArgumentException |
|
| 763 | + * @throws InvalidDataTypeException |
|
| 764 | + * @throws InvalidInterfaceException |
|
| 765 | + */ |
|
| 766 | + protected function _import_page() |
|
| 767 | + { |
|
| 768 | + $title = esc_html__('Import', 'event_espresso'); |
|
| 769 | + $intro = esc_html__( |
|
| 770 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
| 771 | + 'event_espresso' |
|
| 772 | + ); |
|
| 773 | + $form_url = EVENTS_ADMIN_URL; |
|
| 774 | + $action = 'import_events'; |
|
| 775 | + $type = 'csv'; |
|
| 776 | + $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
| 777 | + $title, |
|
| 778 | + $intro, |
|
| 779 | + $form_url, |
|
| 780 | + $action, |
|
| 781 | + $type |
|
| 782 | + ); |
|
| 783 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 784 | + ['action' => 'sample_export_file'], |
|
| 785 | + $this->_admin_base_url |
|
| 786 | + ); |
|
| 787 | + $content = EEH_Template::display_template( |
|
| 788 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 789 | + $this->_template_args, |
|
| 790 | + true |
|
| 791 | + ); |
|
| 792 | + $this->_template_args['admin_page_content'] = $content; |
|
| 793 | + $this->display_admin_page_with_sidebar(); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * _import_events |
|
| 799 | + * This handles displaying the screen and running imports for importing events. |
|
| 800 | + * |
|
| 801 | + * @return void |
|
| 802 | + * @throws EE_Error |
|
| 803 | + * @throws InvalidArgumentException |
|
| 804 | + * @throws InvalidDataTypeException |
|
| 805 | + * @throws InvalidInterfaceException |
|
| 806 | + */ |
|
| 807 | + protected function _import_events() |
|
| 808 | + { |
|
| 809 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 810 | + $success = EE_Import::instance()->import(); |
|
| 811 | + $this->_redirect_after_action($success, 'Import File', 'ran', ['action' => 'import_page'], true); |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * _events_export |
|
| 817 | + * Will export all (or just the given event) to a Excel compatible file. |
|
| 818 | + * |
|
| 819 | + * @access protected |
|
| 820 | + * @return void |
|
| 821 | + */ |
|
| 822 | + protected function _events_export() |
|
| 823 | + { |
|
| 824 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 825 | + $event_ids = $this->_req_data['EVT_ID']; |
|
| 826 | + } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
| 827 | + $event_ids = $this->_req_data['EVT_IDs']; |
|
| 828 | + } else { |
|
| 829 | + $event_ids = null; |
|
| 830 | + } |
|
| 831 | + // todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 832 | + $new_request_args = [ |
|
| 833 | + 'export' => 'report', |
|
| 834 | + 'action' => 'all_event_data', |
|
| 835 | + 'EVT_ID' => $event_ids, |
|
| 836 | + ]; |
|
| 837 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 838 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 839 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 840 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 841 | + if ($EE_Export instanceof EE_Export) { |
|
| 842 | + $EE_Export->export(); |
|
| 843 | + } |
|
| 844 | + } |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * handle category exports() |
|
| 850 | + * |
|
| 851 | + * @return void |
|
| 852 | + */ |
|
| 853 | + protected function _categories_export() |
|
| 854 | + { |
|
| 855 | + // todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
| 856 | + $new_request_args = [ |
|
| 857 | + 'export' => 'report', |
|
| 858 | + 'action' => 'categories', |
|
| 859 | + 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
| 860 | + ]; |
|
| 861 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 862 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 863 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 864 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 865 | + if ($EE_Export instanceof EE_Export) { |
|
| 866 | + $EE_Export->export(); |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * Creates a sample CSV file for importing |
|
| 874 | + */ |
|
| 875 | + protected function _sample_export_file() |
|
| 876 | + { |
|
| 877 | + $EE_Export = EE_Export::instance(); |
|
| 878 | + if ($EE_Export instanceof EE_Export) { |
|
| 879 | + $EE_Export->export(); |
|
| 880 | + } |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + |
|
| 884 | + /************* Template Settings *************/ |
|
| 885 | + /** |
|
| 886 | + * Generates template settings page output |
|
| 887 | + * |
|
| 888 | + * @throws DomainException |
|
| 889 | + * @throws EE_Error |
|
| 890 | + * @throws InvalidArgumentException |
|
| 891 | + * @throws InvalidDataTypeException |
|
| 892 | + * @throws InvalidInterfaceException |
|
| 893 | + */ |
|
| 894 | + protected function _template_settings() |
|
| 895 | + { |
|
| 896 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 897 | + /** |
|
| 898 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 899 | + * from General_Settings_Admin_Page to here. |
|
| 900 | + */ |
|
| 901 | + $this->_template_args = apply_filters( |
|
| 902 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
| 903 | + $this->_template_args |
|
| 904 | + ); |
|
| 905 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
| 906 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 907 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 908 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 909 | + $this->_template_args, |
|
| 910 | + true |
|
| 911 | + ); |
|
| 912 | + $this->display_admin_page_with_sidebar(); |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + /** |
|
| 917 | + * Handler for updating template settings. |
|
| 918 | + * |
|
| 919 | + * @throws EE_Error |
|
| 920 | + * @throws InvalidArgumentException |
|
| 921 | + * @throws InvalidDataTypeException |
|
| 922 | + * @throws InvalidInterfaceException |
|
| 923 | + */ |
|
| 924 | + protected function _update_template_settings() |
|
| 925 | + { |
|
| 926 | + /** |
|
| 927 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
| 928 | + * from General_Settings_Admin_Page to here. |
|
| 929 | + */ |
|
| 930 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
| 931 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
| 932 | + EE_Registry::instance()->CFG->template_settings, |
|
| 933 | + $this->_req_data |
|
| 934 | + ); |
|
| 935 | + // update custom post type slugs and detect if we need to flush rewrite rules |
|
| 936 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
| 937 | + EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
| 938 | + ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
| 939 | + : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events'); |
|
| 940 | + $what = 'Template Settings'; |
|
| 941 | + $success = $this->_update_espresso_configuration( |
|
| 942 | + $what, |
|
| 943 | + EE_Registry::instance()->CFG->template_settings, |
|
| 944 | + __FILE__, |
|
| 945 | + __FUNCTION__, |
|
| 946 | + __LINE__ |
|
| 947 | + ); |
|
| 948 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug !== $old_slug) { |
|
| 949 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
| 950 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
| 951 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
| 952 | + ); |
|
| 953 | + $rewrite_rules->flush(); |
|
| 954 | + } |
|
| 955 | + $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']); |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * _premium_event_editor_meta_boxes |
|
| 961 | + * add all metaboxes related to the event_editor |
|
| 962 | + * |
|
| 963 | + * @access protected |
|
| 964 | + * @return void |
|
| 965 | + * @throws EE_Error |
|
| 966 | + * @throws InvalidArgumentException |
|
| 967 | + * @throws InvalidDataTypeException |
|
| 968 | + * @throws InvalidInterfaceException |
|
| 969 | + * @throws ReflectionException |
|
| 970 | + */ |
|
| 971 | + protected function _premium_event_editor_meta_boxes() |
|
| 972 | + { |
|
| 973 | + $this->verify_cpt_object(); |
|
| 974 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 975 | + if ( |
|
| 976 | + ! $this->admin_config->useAdvancedEditor() |
|
| 977 | + || ! $this->feature->allowed('use_reg_options_meta_box') |
|
| 978 | + ) { |
|
| 979 | + add_meta_box( |
|
| 980 | + 'espresso_event_editor_event_options', |
|
| 981 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 982 | + [$this, 'registration_options_meta_box'], |
|
| 983 | + $this->page_slug, |
|
| 984 | + 'side', |
|
| 985 | + 'core' |
|
| 986 | + ); |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + |
|
| 991 | + /** |
|
| 992 | + * override caf metabox |
|
| 993 | + * |
|
| 994 | + * @return void |
|
| 995 | + * @throws DomainException |
|
| 996 | + * @throws EE_Error |
|
| 997 | + */ |
|
| 998 | + public function registration_options_meta_box() |
|
| 999 | + { |
|
| 1000 | + $yes_no_values = [ |
|
| 1001 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
| 1002 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
| 1003 | + ]; |
|
| 1004 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1005 | + [ |
|
| 1006 | + EEM_Registration::status_id_cancelled, |
|
| 1007 | + EEM_Registration::status_id_declined, |
|
| 1008 | + EEM_Registration::status_id_incomplete, |
|
| 1009 | + EEM_Registration::status_id_wait_list, |
|
| 1010 | + ], |
|
| 1011 | + true |
|
| 1012 | + ); |
|
| 1013 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1014 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1015 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1016 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1017 | + 'default_reg_status', |
|
| 1018 | + $default_reg_status_values, |
|
| 1019 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1020 | + ); |
|
| 1021 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1022 | + 'display_desc', |
|
| 1023 | + $yes_no_values, |
|
| 1024 | + $this->_cpt_model_obj->display_description() |
|
| 1025 | + ); |
|
| 1026 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1027 | + 'display_ticket_selector', |
|
| 1028 | + $yes_no_values, |
|
| 1029 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1030 | + '', |
|
| 1031 | + '', |
|
| 1032 | + false |
|
| 1033 | + ); |
|
| 1034 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1035 | + 'EVT_default_registration_status', |
|
| 1036 | + $default_reg_status_values, |
|
| 1037 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1038 | + ); |
|
| 1039 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1040 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1041 | + '', |
|
| 1042 | + $template_args, |
|
| 1043 | + $yes_no_values, |
|
| 1044 | + $default_reg_status_values |
|
| 1045 | + ); |
|
| 1046 | + EEH_Template::display_template( |
|
| 1047 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1048 | + $template_args |
|
| 1049 | + ); |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + /** |
|
| 1055 | + * wp_list_table_mods for caf |
|
| 1056 | + * ============================ |
|
| 1057 | + */ |
|
| 1058 | + /** |
|
| 1059 | + * hook into list table filters and provide filters for caffeinated list table |
|
| 1060 | + * |
|
| 1061 | + * @param array $old_filters any existing filters present |
|
| 1062 | + * @param array $list_table_obj the list table object |
|
| 1063 | + * @return array new filters |
|
| 1064 | + * @throws EE_Error |
|
| 1065 | + * @throws InvalidArgumentException |
|
| 1066 | + * @throws InvalidDataTypeException |
|
| 1067 | + * @throws InvalidInterfaceException |
|
| 1068 | + * @throws ReflectionException |
|
| 1069 | + */ |
|
| 1070 | + public function list_table_filters($old_filters, $list_table_obj) |
|
| 1071 | + { |
|
| 1072 | + $filters = []; |
|
| 1073 | + // first month/year filters |
|
| 1074 | + $filters[] = $this->espresso_event_months_dropdown(); |
|
| 1075 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1076 | + // active status dropdown |
|
| 1077 | + if ($status !== 'draft') { |
|
| 1078 | + $filters[] = $this->active_status_dropdown( |
|
| 1079 | + isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
| 1080 | + ); |
|
| 1081 | + $filters[] = $this->venuesDropdown( |
|
| 1082 | + isset($this->_req_data['venue']) ? $this->_req_data['venue'] : '' |
|
| 1083 | + ); |
|
| 1084 | + } |
|
| 1085 | + // category filter |
|
| 1086 | + $filters[] = $this->category_dropdown(); |
|
| 1087 | + return array_merge($old_filters, $filters); |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + |
|
| 1091 | + /** |
|
| 1092 | + * espresso_event_months_dropdown |
|
| 1093 | + * |
|
| 1094 | + * @access public |
|
| 1095 | + * @return string dropdown listing month/year selections for events. |
|
| 1096 | + */ |
|
| 1097 | + public function espresso_event_months_dropdown() |
|
| 1098 | + { |
|
| 1099 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
| 1100 | + // Note we need to include any other filters that are set! |
|
| 1101 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1102 | + // categories? |
|
| 1103 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1104 | + ? $this->_req_data['EVT_CAT'] |
|
| 1105 | + : null; |
|
| 1106 | + // active status? |
|
| 1107 | + $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
| 1108 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
| 1109 | + return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + |
|
| 1113 | + /** |
|
| 1114 | + * returns a list of "active" statuses on the event |
|
| 1115 | + * |
|
| 1116 | + * @param string $current_value whatever the current active status is |
|
| 1117 | + * @return string |
|
| 1118 | + */ |
|
| 1119 | + public function active_status_dropdown($current_value = '') |
|
| 1120 | + { |
|
| 1121 | + $select_name = 'active_status'; |
|
| 1122 | + $values = [ |
|
| 1123 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
| 1124 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
| 1125 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
| 1126 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
| 1127 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
| 1128 | + ]; |
|
| 1129 | + |
|
| 1130 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * returns a list of "venues" |
|
| 1136 | + * |
|
| 1137 | + * @param string $current_value whatever the current active status is |
|
| 1138 | + * @return string |
|
| 1139 | + * @throws EE_Error |
|
| 1140 | + * @throws InvalidArgumentException |
|
| 1141 | + * @throws InvalidDataTypeException |
|
| 1142 | + * @throws InvalidInterfaceException |
|
| 1143 | + * @throws ReflectionException |
|
| 1144 | + */ |
|
| 1145 | + protected function venuesDropdown($current_value = '') |
|
| 1146 | + { |
|
| 1147 | + $select_name = 'venue'; |
|
| 1148 | + $values = [ |
|
| 1149 | + '' => esc_html__('All Venues', 'event_espresso'), |
|
| 1150 | + ]; |
|
| 1151 | + // populate the list of venues. |
|
| 1152 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1153 | + $venues = $venue_model->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
|
| 1154 | + |
|
| 1155 | + foreach ($venues as $venue) { |
|
| 1156 | + $values[ $venue->ID() ] = $venue->name(); |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
| 1165 | + * |
|
| 1166 | + * @access public |
|
| 1167 | + * @return string html |
|
| 1168 | + */ |
|
| 1169 | + public function category_dropdown() |
|
| 1170 | + { |
|
| 1171 | + $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
| 1172 | + return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * get total number of events today |
|
| 1178 | + * |
|
| 1179 | + * @access public |
|
| 1180 | + * @return int |
|
| 1181 | + * @throws EE_Error |
|
| 1182 | + * @throws InvalidArgumentException |
|
| 1183 | + * @throws InvalidDataTypeException |
|
| 1184 | + * @throws InvalidInterfaceException |
|
| 1185 | + */ |
|
| 1186 | + public function total_events_today() |
|
| 1187 | + { |
|
| 1188 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1189 | + 'DTT_EVT_start', |
|
| 1190 | + date('Y-m-d') . ' 00:00:00', |
|
| 1191 | + 'Y-m-d H:i:s', |
|
| 1192 | + 'UTC' |
|
| 1193 | + ); |
|
| 1194 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1195 | + 'DTT_EVT_start', |
|
| 1196 | + date('Y-m-d') . ' 23:59:59', |
|
| 1197 | + 'Y-m-d H:i:s', |
|
| 1198 | + 'UTC' |
|
| 1199 | + ); |
|
| 1200 | + $where = [ |
|
| 1201 | + 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
| 1202 | + ]; |
|
| 1203 | + return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + |
|
| 1207 | + /** |
|
| 1208 | + * get total number of events this month |
|
| 1209 | + * |
|
| 1210 | + * @access public |
|
| 1211 | + * @return int |
|
| 1212 | + * @throws EE_Error |
|
| 1213 | + * @throws InvalidArgumentException |
|
| 1214 | + * @throws InvalidDataTypeException |
|
| 1215 | + * @throws InvalidInterfaceException |
|
| 1216 | + */ |
|
| 1217 | + public function total_events_this_month() |
|
| 1218 | + { |
|
| 1219 | + // Dates |
|
| 1220 | + $this_year_r = date('Y'); |
|
| 1221 | + $this_month_r = date('m'); |
|
| 1222 | + $days_this_month = date('t'); |
|
| 1223 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1224 | + 'DTT_EVT_start', |
|
| 1225 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1226 | + 'Y-m-d H:i:s', |
|
| 1227 | + 'UTC' |
|
| 1228 | + ); |
|
| 1229 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1230 | + 'DTT_EVT_start', |
|
| 1231 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1232 | + 'Y-m-d H:i:s', |
|
| 1233 | + 'UTC' |
|
| 1234 | + ); |
|
| 1235 | + $where = [ |
|
| 1236 | + 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
|
| 1237 | + ]; |
|
| 1238 | + return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + /** DEFAULT TICKETS STUFF **/ |
|
| 1243 | + |
|
| 1244 | + /** |
|
| 1245 | + * Output default tickets list table view. |
|
| 1246 | + * |
|
| 1247 | + * @throws DomainException |
|
| 1248 | + * @throws EE_Error |
|
| 1249 | + * @throws InvalidArgumentException |
|
| 1250 | + * @throws InvalidDataTypeException |
|
| 1251 | + * @throws InvalidInterfaceException |
|
| 1252 | + */ |
|
| 1253 | + public function _tickets_overview_list_table() |
|
| 1254 | + { |
|
| 1255 | + if ( |
|
| 1256 | + $this->admin_config->useAdvancedEditor() |
|
| 1257 | + && $this->feature->allowed('use_default_ticket_manager') |
|
| 1258 | + ) { |
|
| 1259 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
| 1260 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1261 | + EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php', |
|
| 1262 | + [], |
|
| 1263 | + true |
|
| 1264 | + ); |
|
| 1265 | + $this->display_admin_page_with_no_sidebar(); |
|
| 1266 | + } else { |
|
| 1267 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
| 1268 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * @param int $per_page |
|
| 1275 | + * @param bool $count |
|
| 1276 | + * @param bool $trashed |
|
| 1277 | + * @return EE_Soft_Delete_Base_Class[]|int |
|
| 1278 | + * @throws EE_Error |
|
| 1279 | + * @throws InvalidArgumentException |
|
| 1280 | + * @throws InvalidDataTypeException |
|
| 1281 | + * @throws InvalidInterfaceException |
|
| 1282 | + */ |
|
| 1283 | + public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
| 1284 | + { |
|
| 1285 | + $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
| 1286 | + $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
| 1287 | + switch ($orderby) { |
|
| 1288 | + case 'TKT_name': |
|
| 1289 | + $orderby = ['TKT_name' => $order]; |
|
| 1290 | + break; |
|
| 1291 | + case 'TKT_price': |
|
| 1292 | + $orderby = ['TKT_price' => $order]; |
|
| 1293 | + break; |
|
| 1294 | + case 'TKT_uses': |
|
| 1295 | + $orderby = ['TKT_uses' => $order]; |
|
| 1296 | + break; |
|
| 1297 | + case 'TKT_min': |
|
| 1298 | + $orderby = ['TKT_min' => $order]; |
|
| 1299 | + break; |
|
| 1300 | + case 'TKT_max': |
|
| 1301 | + $orderby = ['TKT_max' => $order]; |
|
| 1302 | + break; |
|
| 1303 | + case 'TKT_qty': |
|
| 1304 | + $orderby = ['TKT_qty' => $order]; |
|
| 1305 | + break; |
|
| 1306 | + } |
|
| 1307 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1308 | + ? $this->_req_data['paged'] |
|
| 1309 | + : 1; |
|
| 1310 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1311 | + ? $this->_req_data['perpage'] |
|
| 1312 | + : $per_page; |
|
| 1313 | + $_where = [ |
|
| 1314 | + 'TKT_is_default' => 1, |
|
| 1315 | + 'TKT_deleted' => $trashed, |
|
| 1316 | + ]; |
|
| 1317 | + $offset = ($current_page - 1) * $per_page; |
|
| 1318 | + $limit = [$offset, $per_page]; |
|
| 1319 | + if (isset($this->_req_data['s'])) { |
|
| 1320 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1321 | + $_where['OR'] = [ |
|
| 1322 | + 'TKT_name' => ['LIKE', $sstr], |
|
| 1323 | + 'TKT_description' => ['LIKE', $sstr], |
|
| 1324 | + ]; |
|
| 1325 | + } |
|
| 1326 | + $query_params = [ |
|
| 1327 | + $_where, |
|
| 1328 | + 'order_by' => $orderby, |
|
| 1329 | + 'limit' => $limit, |
|
| 1330 | + 'group_by' => 'TKT_ID', |
|
| 1331 | + ]; |
|
| 1332 | + if ($count) { |
|
| 1333 | + return EEM_Ticket::instance()->count_deleted_and_undeleted([$_where]); |
|
| 1334 | + } |
|
| 1335 | + return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * @param bool $trash |
|
| 1341 | + * @throws EE_Error |
|
| 1342 | + * @throws InvalidArgumentException |
|
| 1343 | + * @throws InvalidDataTypeException |
|
| 1344 | + * @throws InvalidInterfaceException |
|
| 1345 | + */ |
|
| 1346 | + protected function _trash_or_restore_ticket($trash = false) |
|
| 1347 | + { |
|
| 1348 | + $success = 1; |
|
| 1349 | + $TKT = EEM_Ticket::instance(); |
|
| 1350 | + // checkboxes? |
|
| 1351 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1352 | + // if array has more than one element then success message should be plural |
|
| 1353 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1354 | + // cycle thru the boxes |
|
| 1355 | + foreach ($this->_req_data['checkbox'] as $TKT_ID) { |
|
| 1356 | + if ($trash) { |
|
| 1357 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1358 | + $success = 0; |
|
| 1359 | + } |
|
| 1360 | + } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1361 | + $success = 0; |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + } else { |
|
| 1365 | + // grab single id and trash |
|
| 1366 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1367 | + if ($trash) { |
|
| 1368 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1369 | + $success = 0; |
|
| 1370 | + } |
|
| 1371 | + } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1372 | + $success = 0; |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
| 1376 | + $query_args = [ |
|
| 1377 | + 'action' => 'ticket_list_table', |
|
| 1378 | + 'status' => $trash ? '' : 'trashed', |
|
| 1379 | + ]; |
|
| 1380 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + |
|
| 1384 | + /** |
|
| 1385 | + * Handles trashing default ticket. |
|
| 1386 | + * |
|
| 1387 | + * @throws EE_Error |
|
| 1388 | + * @throws InvalidArgumentException |
|
| 1389 | + * @throws InvalidDataTypeException |
|
| 1390 | + * @throws InvalidInterfaceException |
|
| 1391 | + * @throws ReflectionException |
|
| 1392 | + */ |
|
| 1393 | + protected function _delete_ticket() |
|
| 1394 | + { |
|
| 1395 | + $success = 1; |
|
| 1396 | + // checkboxes? |
|
| 1397 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1398 | + // if array has more than one element then success message should be plural |
|
| 1399 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1400 | + // cycle thru the boxes |
|
| 1401 | + foreach ($this->_req_data['checkbox'] as $TKT_ID) { |
|
| 1402 | + // delete |
|
| 1403 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1404 | + $success = 0; |
|
| 1405 | + } |
|
| 1406 | + } |
|
| 1407 | + } else { |
|
| 1408 | + // grab single id and trash |
|
| 1409 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
| 1410 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1411 | + $success = 0; |
|
| 1412 | + } |
|
| 1413 | + } |
|
| 1414 | + $action_desc = 'deleted'; |
|
| 1415 | + // fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
| 1416 | + $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
| 1417 | + [['TKT_is_default' => 1]], |
|
| 1418 | + 'TKT_ID', |
|
| 1419 | + true |
|
| 1420 | + ); |
|
| 1421 | + $query_args = $ticket_count |
|
| 1422 | + ? [] |
|
| 1423 | + : [ |
|
| 1424 | + 'action' => 'ticket_list_table', |
|
| 1425 | + 'status' => 'trashed', |
|
| 1426 | + ]; |
|
| 1427 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + |
|
| 1431 | + /** |
|
| 1432 | + * @param int $TKT_ID |
|
| 1433 | + * @return bool|int |
|
| 1434 | + * @throws EE_Error |
|
| 1435 | + * @throws InvalidArgumentException |
|
| 1436 | + * @throws InvalidDataTypeException |
|
| 1437 | + * @throws InvalidInterfaceException |
|
| 1438 | + * @throws ReflectionException |
|
| 1439 | + */ |
|
| 1440 | + protected function _delete_the_ticket($TKT_ID) |
|
| 1441 | + { |
|
| 1442 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
| 1443 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1444 | + return false; |
|
| 1445 | + } |
|
| 1446 | + $ticket->_remove_relations('Datetime'); |
|
| 1447 | + // delete all related prices first |
|
| 1448 | + $ticket->delete_related_permanently('Price'); |
|
| 1449 | + return $ticket->delete_permanently(); |
|
| 1450 | + } |
|
| 1451 | 1451 | } |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function __construct($routing = true) |
| 37 | 37 | { |
| 38 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 39 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
| 40 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
| 41 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
| 38 | + if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
| 39 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/'); |
|
| 40 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/'); |
|
| 41 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/'); |
|
| 42 | 42 | } |
| 43 | 43 | parent::__construct($routing); |
| 44 | 44 | $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
@@ -56,18 +56,18 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | protected function _extend_page_config() |
| 58 | 58 | { |
| 59 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
| 59 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events'; |
|
| 60 | 60 | // is there a evt_id in the request? |
| 61 | 61 | $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
| 62 | 62 | ? $this->_req_data['EVT_ID'] |
| 63 | 63 | : 0; |
| 64 | 64 | $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
| 65 | 65 | // tkt_id? |
| 66 | - $tkt_id = |
|
| 66 | + $tkt_id = |
|
| 67 | 67 | ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
| 68 | 68 | ? $this->_req_data['TKT_ID'] |
| 69 | 69 | : 0; |
| 70 | - $new_page_routes = [ |
|
| 70 | + $new_page_routes = [ |
|
| 71 | 71 | 'duplicate_event' => [ |
| 72 | 72 | 'func' => '_duplicate_event', |
| 73 | 73 | 'capability' => 'ee_edit_event', |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | 'noheader' => true, |
| 161 | 161 | ], |
| 162 | 162 | ]; |
| 163 | - $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes); |
|
| 163 | + $new_page_routes = array_merge($new_page_routes, $legacy_editor_page_routes); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | // 'help_tour' => ['Templates_Help_Tour'], |
| 203 | 203 | 'require_nonce' => false, |
| 204 | 204 | ]; |
| 205 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 205 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 206 | 206 | // add filters and actions |
| 207 | 207 | // modifying _views |
| 208 | 208 | add_filter( |
@@ -308,12 +308,12 @@ discard block |
||
| 308 | 308 | { |
| 309 | 309 | $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
| 310 | 310 | // make sure this is only when editing |
| 311 | - if (! empty($id)) { |
|
| 312 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 311 | + if ( ! empty($id)) { |
|
| 312 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
| 313 | 313 | ['action' => 'duplicate_event', 'EVT_ID' => $id], |
| 314 | 314 | $this->_admin_base_url |
| 315 | 315 | ); |
| 316 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 316 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
| 317 | 317 | $return .= '<a href="' |
| 318 | 318 | . $href |
| 319 | 319 | . '" title="' |
@@ -358,10 +358,10 @@ discard block |
||
| 358 | 358 | */ |
| 359 | 359 | public function load_scripts_styles_edit() |
| 360 | 360 | { |
| 361 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
| 361 | + if ( ! $this->admin_config->useAdvancedEditor()) { |
|
| 362 | 362 | wp_register_script( |
| 363 | 363 | 'ee-event-editor-heartbeat', |
| 364 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
| 364 | + EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js', |
|
| 365 | 365 | ['ee_admin_js', 'heartbeat'], |
| 366 | 366 | EVENT_ESPRESSO_VERSION, |
| 367 | 367 | true |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | public function add_additional_datetime_button($template, $template_args) |
| 387 | 387 | { |
| 388 | 388 | return EEH_Template::display_template( |
| 389 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
| 389 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php', |
|
| 390 | 390 | $template_args, |
| 391 | 391 | true |
| 392 | 392 | ); |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | public function add_datetime_clone_button($template, $template_args) |
| 405 | 405 | { |
| 406 | 406 | return EEH_Template::display_template( |
| 407 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
| 407 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php', |
|
| 408 | 408 | $template_args, |
| 409 | 409 | true |
| 410 | 410 | ); |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | public function datetime_timezones_template($template, $template_args) |
| 423 | 423 | { |
| 424 | 424 | return EEH_Template::display_template( |
| 425 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
| 425 | + EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php', |
|
| 426 | 426 | $template_args, |
| 427 | 427 | true |
| 428 | 428 | ); |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | protected function _set_list_table_views_default() |
| 438 | 438 | { |
| 439 | 439 | parent::_set_list_table_views_default(); |
| 440 | - $new_views = [ |
|
| 440 | + $new_views = [ |
|
| 441 | 441 | 'today' => [ |
| 442 | 442 | 'slug' => 'today', |
| 443 | 443 | 'label' => esc_html__('Today', 'event_espresso'), |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | { |
| 556 | 556 | // first make sure the ID for the event is in the request. |
| 557 | 557 | // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
| 558 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
| 558 | + if ( ! isset($this->_req_data['EVT_ID'])) { |
|
| 559 | 559 | EE_Error::add_error( |
| 560 | 560 | esc_html__( |
| 561 | 561 | 'In order to duplicate an event an Event ID is required. None was given.', |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | } |
| 571 | 571 | // k we've got EVT_ID so let's use that to get the event we'll duplicate |
| 572 | 572 | $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
| 573 | - if (! $orig_event instanceof EE_Event) { |
|
| 573 | + if ( ! $orig_event instanceof EE_Event) { |
|
| 574 | 574 | throw new EE_Error( |
| 575 | 575 | sprintf( |
| 576 | 576 | esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | $orig_ven = $orig_event->get_many_related('Venue'); |
| 587 | 587 | // reset the ID and modify other details to make it clear this is a dupe |
| 588 | 588 | $new_event->set('EVT_ID', 0); |
| 589 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 589 | + $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso'); |
|
| 590 | 590 | $new_event->set('EVT_name', $new_name); |
| 591 | 591 | $new_event->set( |
| 592 | 592 | 'EVT_slug', |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | 'Question_Group', |
| 616 | 616 | [['Event_Question_Group.EQG_primary' => true]] |
| 617 | 617 | ); |
| 618 | - if (! empty($orig_primary_qgs)) { |
|
| 618 | + if ( ! empty($orig_primary_qgs)) { |
|
| 619 | 619 | foreach ($orig_primary_qgs as $id => $obj) { |
| 620 | 620 | if ($obj instanceof EE_Question_Group) { |
| 621 | 621 | $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]); |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | 'Question_Group', |
| 628 | 628 | [['Event_Question_Group.EQG_additional' => true]] |
| 629 | 629 | ); |
| 630 | - if (! empty($orig_additional_qgs)) { |
|
| 630 | + if ( ! empty($orig_additional_qgs)) { |
|
| 631 | 631 | foreach ($orig_additional_qgs as $id => $obj) { |
| 632 | 632 | if ($obj instanceof EE_Question_Group) { |
| 633 | 633 | $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]); |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | // k now that we have the new event saved we can loop through the datetimes and start adding relations. |
| 641 | 641 | $cloned_tickets = []; |
| 642 | 642 | foreach ($orig_datetimes as $orig_dtt) { |
| 643 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
| 643 | + if ( ! $orig_dtt instanceof EE_Datetime) { |
|
| 644 | 644 | continue; |
| 645 | 645 | } |
| 646 | 646 | $new_dtt = clone $orig_dtt; |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | // now let's get the ticket relations setup. |
| 656 | 656 | foreach ((array) $orig_tkts as $orig_tkt) { |
| 657 | 657 | // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
| 658 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
| 658 | + if ( ! $orig_tkt instanceof EE_Ticket) { |
|
| 659 | 659 | continue; |
| 660 | 660 | } |
| 661 | 661 | // is this ticket archived? If it is then let's skip |
@@ -664,8 +664,8 @@ discard block |
||
| 664 | 664 | } |
| 665 | 665 | // does this original ticket already exist in the clone_tickets cache? |
| 666 | 666 | // If so we'll just use the new ticket from it. |
| 667 | - if (isset($cloned_tickets[ $orig_tkt->ID() ])) { |
|
| 668 | - $new_tkt = $cloned_tickets[ $orig_tkt->ID() ]; |
|
| 667 | + if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
| 668 | + $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
| 669 | 669 | } else { |
| 670 | 670 | $new_tkt = clone $orig_tkt; |
| 671 | 671 | // get relations on the $orig_tkt that we need to setup. |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | // for use with later datetimes that have the same ticket. |
| 699 | 699 | $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
| 700 | 700 | $new_dtt->save(); |
| 701 | - $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt; |
|
| 701 | + $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
| 702 | 702 | } |
| 703 | 703 | } |
| 704 | 704 | // clone taxonomy information |
@@ -780,12 +780,12 @@ discard block |
||
| 780 | 780 | $action, |
| 781 | 781 | $type |
| 782 | 782 | ); |
| 783 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 783 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 784 | 784 | ['action' => 'sample_export_file'], |
| 785 | 785 | $this->_admin_base_url |
| 786 | 786 | ); |
| 787 | - $content = EEH_Template::display_template( |
|
| 788 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
| 787 | + $content = EEH_Template::display_template( |
|
| 788 | + EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php', |
|
| 789 | 789 | $this->_template_args, |
| 790 | 790 | true |
| 791 | 791 | ); |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | */ |
| 807 | 807 | protected function _import_events() |
| 808 | 808 | { |
| 809 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
| 809 | + require_once(EE_CLASSES.'EE_Import.class.php'); |
|
| 810 | 810 | $success = EE_Import::instance()->import(); |
| 811 | 811 | $this->_redirect_after_action($success, 'Import File', 'ran', ['action' => 'import_page'], true); |
| 812 | 812 | } |
@@ -834,9 +834,9 @@ discard block |
||
| 834 | 834 | 'action' => 'all_event_data', |
| 835 | 835 | 'EVT_ID' => $event_ids, |
| 836 | 836 | ]; |
| 837 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 838 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 839 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 837 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 838 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 839 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 840 | 840 | $EE_Export = EE_Export::instance($this->_req_data); |
| 841 | 841 | if ($EE_Export instanceof EE_Export) { |
| 842 | 842 | $EE_Export->export(); |
@@ -858,9 +858,9 @@ discard block |
||
| 858 | 858 | 'action' => 'categories', |
| 859 | 859 | 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
| 860 | 860 | ]; |
| 861 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 862 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 863 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 861 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 862 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 863 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 864 | 864 | $EE_Export = EE_Export::instance($this->_req_data); |
| 865 | 865 | if ($EE_Export instanceof EE_Export) { |
| 866 | 866 | $EE_Export->export(); |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | $this->_set_add_edit_form_tags('update_template_settings'); |
| 906 | 906 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 907 | 907 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 908 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
| 908 | + EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php', |
|
| 909 | 909 | $this->_template_args, |
| 910 | 910 | true |
| 911 | 911 | ); |
@@ -997,11 +997,11 @@ discard block |
||
| 997 | 997 | */ |
| 998 | 998 | public function registration_options_meta_box() |
| 999 | 999 | { |
| 1000 | - $yes_no_values = [ |
|
| 1000 | + $yes_no_values = [ |
|
| 1001 | 1001 | ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
| 1002 | 1002 | ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
| 1003 | 1003 | ]; |
| 1004 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1004 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1005 | 1005 | [ |
| 1006 | 1006 | EEM_Registration::status_id_cancelled, |
| 1007 | 1007 | EEM_Registration::status_id_declined, |
@@ -1018,12 +1018,12 @@ discard block |
||
| 1018 | 1018 | $default_reg_status_values, |
| 1019 | 1019 | $this->_cpt_model_obj->default_registration_status() |
| 1020 | 1020 | ); |
| 1021 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1021 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1022 | 1022 | 'display_desc', |
| 1023 | 1023 | $yes_no_values, |
| 1024 | 1024 | $this->_cpt_model_obj->display_description() |
| 1025 | 1025 | ); |
| 1026 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1026 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1027 | 1027 | 'display_ticket_selector', |
| 1028 | 1028 | $yes_no_values, |
| 1029 | 1029 | $this->_cpt_model_obj->display_ticket_selector(), |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | $default_reg_status_values |
| 1045 | 1045 | ); |
| 1046 | 1046 | EEH_Template::display_template( |
| 1047 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1047 | + EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1048 | 1048 | $template_args |
| 1049 | 1049 | ); |
| 1050 | 1050 | } |
@@ -1153,7 +1153,7 @@ discard block |
||
| 1153 | 1153 | $venues = $venue_model->get_all(['order_by' => ['VNU_name' => 'ASC']]); |
| 1154 | 1154 | |
| 1155 | 1155 | foreach ($venues as $venue) { |
| 1156 | - $values[ $venue->ID() ] = $venue->name(); |
|
| 1156 | + $values[$venue->ID()] = $venue->name(); |
|
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | 1159 | return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide'); |
@@ -1187,13 +1187,13 @@ discard block |
||
| 1187 | 1187 | { |
| 1188 | 1188 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
| 1189 | 1189 | 'DTT_EVT_start', |
| 1190 | - date('Y-m-d') . ' 00:00:00', |
|
| 1190 | + date('Y-m-d').' 00:00:00', |
|
| 1191 | 1191 | 'Y-m-d H:i:s', |
| 1192 | 1192 | 'UTC' |
| 1193 | 1193 | ); |
| 1194 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1194 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1195 | 1195 | 'DTT_EVT_start', |
| 1196 | - date('Y-m-d') . ' 23:59:59', |
|
| 1196 | + date('Y-m-d').' 23:59:59', |
|
| 1197 | 1197 | 'Y-m-d H:i:s', |
| 1198 | 1198 | 'UTC' |
| 1199 | 1199 | ); |
@@ -1222,17 +1222,17 @@ discard block |
||
| 1222 | 1222 | $days_this_month = date('t'); |
| 1223 | 1223 | $start = EEM_Datetime::instance()->convert_datetime_for_query( |
| 1224 | 1224 | 'DTT_EVT_start', |
| 1225 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
| 1225 | + $this_year_r.'-'.$this_month_r.'-01 00:00:00', |
|
| 1226 | 1226 | 'Y-m-d H:i:s', |
| 1227 | 1227 | 'UTC' |
| 1228 | 1228 | ); |
| 1229 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1229 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
| 1230 | 1230 | 'DTT_EVT_start', |
| 1231 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
| 1231 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59', |
|
| 1232 | 1232 | 'Y-m-d H:i:s', |
| 1233 | 1233 | 'UTC' |
| 1234 | 1234 | ); |
| 1235 | - $where = [ |
|
| 1235 | + $where = [ |
|
| 1236 | 1236 | 'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]], |
| 1237 | 1237 | ]; |
| 1238 | 1238 | return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true); |
@@ -1258,7 +1258,7 @@ discard block |
||
| 1258 | 1258 | ) { |
| 1259 | 1259 | // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
| 1260 | 1260 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 1261 | - EVENTS_CAF_TEMPLATE_PATH . 'default_tickets_moved_notice.template.php', |
|
| 1261 | + EVENTS_CAF_TEMPLATE_PATH.'default_tickets_moved_notice.template.php', |
|
| 1262 | 1262 | [], |
| 1263 | 1263 | true |
| 1264 | 1264 | ); |
@@ -1317,7 +1317,7 @@ discard block |
||
| 1317 | 1317 | $offset = ($current_page - 1) * $per_page; |
| 1318 | 1318 | $limit = [$offset, $per_page]; |
| 1319 | 1319 | if (isset($this->_req_data['s'])) { |
| 1320 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1320 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 1321 | 1321 | $_where['OR'] = [ |
| 1322 | 1322 | 'TKT_name' => ['LIKE', $sstr], |
| 1323 | 1323 | 'TKT_description' => ['LIKE', $sstr], |
@@ -1348,16 +1348,16 @@ discard block |
||
| 1348 | 1348 | $success = 1; |
| 1349 | 1349 | $TKT = EEM_Ticket::instance(); |
| 1350 | 1350 | // checkboxes? |
| 1351 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1351 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1352 | 1352 | // if array has more than one element then success message should be plural |
| 1353 | 1353 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 1354 | 1354 | // cycle thru the boxes |
| 1355 | 1355 | foreach ($this->_req_data['checkbox'] as $TKT_ID) { |
| 1356 | 1356 | if ($trash) { |
| 1357 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1357 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1358 | 1358 | $success = 0; |
| 1359 | 1359 | } |
| 1360 | - } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1360 | + } elseif ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1361 | 1361 | $success = 0; |
| 1362 | 1362 | } |
| 1363 | 1363 | } |
@@ -1365,10 +1365,10 @@ discard block |
||
| 1365 | 1365 | // grab single id and trash |
| 1366 | 1366 | $TKT_ID = absint($this->_req_data['TKT_ID']); |
| 1367 | 1367 | if ($trash) { |
| 1368 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1368 | + if ( ! $TKT->delete_by_ID($TKT_ID)) { |
|
| 1369 | 1369 | $success = 0; |
| 1370 | 1370 | } |
| 1371 | - } elseif (! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1371 | + } elseif ( ! $TKT->restore_by_ID($TKT_ID)) { |
|
| 1372 | 1372 | $success = 0; |
| 1373 | 1373 | } |
| 1374 | 1374 | } |
@@ -1394,20 +1394,20 @@ discard block |
||
| 1394 | 1394 | { |
| 1395 | 1395 | $success = 1; |
| 1396 | 1396 | // checkboxes? |
| 1397 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1397 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1398 | 1398 | // if array has more than one element then success message should be plural |
| 1399 | 1399 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 1400 | 1400 | // cycle thru the boxes |
| 1401 | 1401 | foreach ($this->_req_data['checkbox'] as $TKT_ID) { |
| 1402 | 1402 | // delete |
| 1403 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1403 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1404 | 1404 | $success = 0; |
| 1405 | 1405 | } |
| 1406 | 1406 | } |
| 1407 | 1407 | } else { |
| 1408 | 1408 | // grab single id and trash |
| 1409 | 1409 | $TKT_ID = absint($this->_req_data['TKT_ID']); |
| 1410 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1410 | + if ( ! $this->_delete_the_ticket($TKT_ID)) { |
|
| 1411 | 1411 | $success = 0; |
| 1412 | 1412 | } |
| 1413 | 1413 | } |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | 'TKT_ID', |
| 1419 | 1419 | true |
| 1420 | 1420 | ); |
| 1421 | - $query_args = $ticket_count |
|
| 1421 | + $query_args = $ticket_count |
|
| 1422 | 1422 | ? [] |
| 1423 | 1423 | : [ |
| 1424 | 1424 | 'action' => 'ticket_list_table', |
@@ -1440,7 +1440,7 @@ discard block |
||
| 1440 | 1440 | protected function _delete_the_ticket($TKT_ID) |
| 1441 | 1441 | { |
| 1442 | 1442 | $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
| 1443 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1443 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1444 | 1444 | return false; |
| 1445 | 1445 | } |
| 1446 | 1446 | $ticket->_remove_relations('Datetime'); |
@@ -2,12 +2,12 @@ discard block |
||
| 2 | 2 | <h2><?php esc_html_e('The Default Tickets Manager Has Moved', 'event_espresso'); ?></h2> |
| 3 | 3 | <p> |
| 4 | 4 | <?php printf( |
| 5 | - esc_html__( |
|
| 6 | - 'The new Advanced Event Editor introduces a better way to manage your events\' default tickets...%1$sright from within the Event Editor.', |
|
| 7 | - 'event_espresso' |
|
| 8 | - ), |
|
| 9 | - '<br />' |
|
| 10 | - ); ?> |
|
| 5 | + esc_html__( |
|
| 6 | + 'The new Advanced Event Editor introduces a better way to manage your events\' default tickets...%1$sright from within the Event Editor.', |
|
| 7 | + 'event_espresso' |
|
| 8 | + ), |
|
| 9 | + '<br />' |
|
| 10 | + ); ?> |
|
| 11 | 11 | </p> |
| 12 | 12 | <h5> |
| 13 | 13 | <?php esc_html_e('Follow these simple steps:', 'event_espresso'); ?> |
@@ -19,26 +19,26 @@ discard block |
||
| 19 | 19 | <li> |
| 20 | 20 | <p> |
| 21 | 21 | <?php esc_html_e( |
| 22 | - 'Edit an existing event or create a new event by clicking the "Add New Event" button.', |
|
| 23 | - 'event_espresso' |
|
| 24 | - ); ?> |
|
| 22 | + 'Edit an existing event or create a new event by clicking the "Add New Event" button.', |
|
| 23 | + 'event_espresso' |
|
| 24 | + ); ?> |
|
| 25 | 25 | </p> |
| 26 | 26 | </li> |
| 27 | 27 | <li> |
| 28 | 28 | <p> |
| 29 | 29 | <?php esc_html_e( |
| 30 | - 'Scroll down to the bottom of the "Available Tickets" list.', |
|
| 31 | - 'event_espresso' |
|
| 32 | - ); ?> |
|
| 30 | + 'Scroll down to the bottom of the "Available Tickets" list.', |
|
| 31 | + 'event_espresso' |
|
| 32 | + ); ?> |
|
| 33 | 33 | </p> |
| 34 | 34 | </li> |
| 35 | 35 | <li> |
| 36 | 36 | <div> |
| 37 | 37 | <p> |
| 38 | 38 | <?php esc_html_e( |
| 39 | - 'Click on the menu button to the right of the "Add New Ticket" button.', |
|
| 40 | - 'event_espresso' |
|
| 41 | - ); ?> |
|
| 39 | + 'Click on the menu button to the right of the "Add New Ticket" button.', |
|
| 40 | + 'event_espresso' |
|
| 41 | + ); ?> |
|
| 42 | 42 | </p> |
| 43 | 43 | <img alt='event editor tickets list menu button' |
| 44 | 44 | class='ee-new-edtr-notice__img' |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | <div> |
| 51 | 51 | <p> |
| 52 | 52 | <?php esc_html_e( |
| 53 | - 'Click on the "Default Tickets" option to open the "Default Tickets Manager".', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 53 | + 'Click on the "Default Tickets" option to open the "Default Tickets Manager".', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | <img alt='event editor default tickets menu option' |
| 58 | 58 | class='ee-new-edtr-notice__img' |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | <div> |
| 65 | 65 | <p> |
| 66 | 66 | <?php esc_html_e( |
| 67 | - 'Use existing tickets as templates or create new default tickets from scratch', |
|
| 68 | - 'event_espresso' |
|
| 69 | - ); ?> |
|
| 67 | + 'Use existing tickets as templates or create new default tickets from scratch', |
|
| 68 | + 'event_espresso' |
|
| 69 | + ); ?> |
|
| 70 | 70 | </p> |
| 71 | 71 | <img alt='the default tickets editor' |
| 72 | 72 | class="ee-new-edtr-notice__img ee-new-edtr-notice__img--big" |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | </p> |
| 43 | 43 | <img alt='event editor tickets list menu button' |
| 44 | 44 | class='ee-new-edtr-notice__img' |
| 45 | - src='<?php echo esc_url_raw(EE_IMAGES_URL . 'default-tickets-1.png'); ?>' |
|
| 45 | + src='<?php echo esc_url_raw(EE_IMAGES_URL.'default-tickets-1.png'); ?>' |
|
| 46 | 46 | /> |
| 47 | 47 | </div> |
| 48 | 48 | </li> |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | </p> |
| 57 | 57 | <img alt='event editor default tickets menu option' |
| 58 | 58 | class='ee-new-edtr-notice__img' |
| 59 | - src='<?php echo esc_url_raw(EE_IMAGES_URL . 'default-tickets-2.png'); ?>' |
|
| 59 | + src='<?php echo esc_url_raw(EE_IMAGES_URL.'default-tickets-2.png'); ?>' |
|
| 60 | 60 | /> |
| 61 | 61 | </div> |
| 62 | 62 | </li> |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | </p> |
| 71 | 71 | <img alt='the default tickets editor' |
| 72 | 72 | class="ee-new-edtr-notice__img ee-new-edtr-notice__img--big" |
| 73 | - src='<?php echo esc_url_raw(EE_IMAGES_URL . 'default-tickets-3.png'); ?>' |
|
| 73 | + src='<?php echo esc_url_raw(EE_IMAGES_URL.'default-tickets-3.png'); ?>' |
|
| 74 | 74 | /> |
| 75 | 75 | </div> |
| 76 | 76 | </li> |
@@ -14,2544 +14,2544 @@ discard block |
||
| 14 | 14 | final class EE_Config implements ResettableInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const OPTION_NAME = 'ee_config'; |
|
| 18 | - |
|
| 19 | - const LOG_NAME = 'ee_config_log'; |
|
| 20 | - |
|
| 21 | - const LOG_LENGTH = 100; |
|
| 22 | - |
|
| 23 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * instance of the EE_Config object |
|
| 27 | - * |
|
| 28 | - * @var EE_Config $_instance |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var boolean $_logging_enabled |
|
| 35 | - */ |
|
| 36 | - private static $_logging_enabled = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | - */ |
|
| 41 | - private $legacy_shortcodes_manager; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * An StdClass whose property names are addon slugs, |
|
| 45 | - * and values are their config classes |
|
| 46 | - * |
|
| 47 | - * @var StdClass |
|
| 48 | - */ |
|
| 49 | - public $addons; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Admin_Config |
|
| 53 | - */ |
|
| 54 | - public $admin; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Core_Config |
|
| 58 | - */ |
|
| 59 | - public $core; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var EE_Currency_Config |
|
| 63 | - */ |
|
| 64 | - public $currency; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var EE_Organization_Config |
|
| 68 | - */ |
|
| 69 | - public $organization; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_Registration_Config |
|
| 73 | - */ |
|
| 74 | - public $registration; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_Template_Config |
|
| 78 | - */ |
|
| 79 | - public $template_settings; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Holds EE environment values. |
|
| 83 | - * |
|
| 84 | - * @var EE_Environment_Config |
|
| 85 | - */ |
|
| 86 | - public $environment; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * settings pertaining to Google maps |
|
| 90 | - * |
|
| 91 | - * @var EE_Map_Config |
|
| 92 | - */ |
|
| 93 | - public $map_settings; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * settings pertaining to Taxes |
|
| 97 | - * |
|
| 98 | - * @var EE_Tax_Config |
|
| 99 | - */ |
|
| 100 | - public $tax_settings; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Settings pertaining to global messages settings. |
|
| 104 | - * |
|
| 105 | - * @var EE_Messages_Config |
|
| 106 | - */ |
|
| 107 | - public $messages; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated |
|
| 111 | - * @var EE_Gateway_Config |
|
| 112 | - */ |
|
| 113 | - public $gateway; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var array $_addon_option_names |
|
| 117 | - * @access private |
|
| 118 | - */ |
|
| 119 | - private $_addon_option_names = array(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var array $_module_route_map |
|
| 123 | - * @access private |
|
| 124 | - */ |
|
| 125 | - private static $_module_route_map = array(); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var array $_module_forward_map |
|
| 129 | - * @access private |
|
| 130 | - */ |
|
| 131 | - private static $_module_forward_map = array(); |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @var array $_module_view_map |
|
| 135 | - * @access private |
|
| 136 | - */ |
|
| 137 | - private static $_module_view_map = array(); |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @singleton method used to instantiate class object |
|
| 142 | - * @access public |
|
| 143 | - * @return EE_Config instance |
|
| 144 | - */ |
|
| 145 | - public static function instance() |
|
| 146 | - { |
|
| 147 | - // check if class object is instantiated, and instantiated properly |
|
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 149 | - self::$_instance = new self(); |
|
| 150 | - } |
|
| 151 | - return self::$_instance; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Resets the config |
|
| 157 | - * |
|
| 158 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | - * reflect its state in the database |
|
| 161 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | - * site was put into maintenance mode) |
|
| 165 | - * @return EE_Config |
|
| 166 | - */ |
|
| 167 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | - { |
|
| 169 | - if (self::$_instance instanceof EE_Config) { |
|
| 170 | - if ($hard_reset) { |
|
| 171 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | - self::$_instance->_addon_option_names = array(); |
|
| 173 | - self::$_instance->_initialize_config(); |
|
| 174 | - self::$_instance->update_espresso_config(); |
|
| 175 | - } |
|
| 176 | - self::$_instance->update_addon_option_names(); |
|
| 177 | - } |
|
| 178 | - self::$_instance = null; |
|
| 179 | - // we don't need to reset the static properties imo because those should |
|
| 180 | - // only change when a module is added or removed. Currently we don't |
|
| 181 | - // support removing a module during a request when it previously existed |
|
| 182 | - if ($reinstantiate) { |
|
| 183 | - return self::instance(); |
|
| 184 | - } else { |
|
| 185 | - return null; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * class constructor |
|
| 192 | - * |
|
| 193 | - * @access private |
|
| 194 | - */ |
|
| 195 | - private function __construct() |
|
| 196 | - { |
|
| 197 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | - // setup empty config classes |
|
| 200 | - $this->_initialize_config(); |
|
| 201 | - // load existing EE site settings |
|
| 202 | - $this->_load_core_config(); |
|
| 203 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | - $this->_verify_config(); |
|
| 205 | - // register shortcodes and modules |
|
| 206 | - add_action( |
|
| 207 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | - array($this, 'register_shortcodes_and_modules'), |
|
| 209 | - 999 |
|
| 210 | - ); |
|
| 211 | - // initialize shortcodes and modules |
|
| 212 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | - // register widgets |
|
| 214 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | - // shutdown |
|
| 216 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | - // construct__end hook |
|
| 218 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | - // hardcoded hack |
|
| 220 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @return boolean |
|
| 226 | - */ |
|
| 227 | - public static function logging_enabled() |
|
| 228 | - { |
|
| 229 | - return self::$_logging_enabled; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * use to get the current theme if needed from static context |
|
| 235 | - * |
|
| 236 | - * @return string current theme set. |
|
| 237 | - */ |
|
| 238 | - public static function get_current_theme() |
|
| 239 | - { |
|
| 240 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * _initialize_config |
|
| 247 | - * |
|
| 248 | - * @access private |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - private function _initialize_config() |
|
| 252 | - { |
|
| 253 | - EE_Config::trim_log(); |
|
| 254 | - // set defaults |
|
| 255 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | - $this->addons = new stdClass(); |
|
| 257 | - // set _module_route_map |
|
| 258 | - EE_Config::$_module_route_map = array(); |
|
| 259 | - // set _module_forward_map |
|
| 260 | - EE_Config::$_module_forward_map = array(); |
|
| 261 | - // set _module_view_map |
|
| 262 | - EE_Config::$_module_view_map = array(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * load core plugin configuration |
|
| 268 | - * |
|
| 269 | - * @access private |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - private function _load_core_config() |
|
| 273 | - { |
|
| 274 | - // load_core_config__start hook |
|
| 275 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | - $espresso_config = $this->get_espresso_config(); |
|
| 277 | - foreach ($espresso_config as $config => $settings) { |
|
| 278 | - // load_core_config__start hook |
|
| 279 | - $settings = apply_filters( |
|
| 280 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | - $settings, |
|
| 282 | - $config, |
|
| 283 | - $this |
|
| 284 | - ); |
|
| 285 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | - // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | - if (method_exists($settings, 'populate')) { |
|
| 289 | - $this->{$config}->populate(); |
|
| 290 | - } |
|
| 291 | - if (method_exists($settings, 'do_hooks')) { |
|
| 292 | - $this->{$config}->do_hooks(); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | - $this->update_espresso_config(); |
|
| 298 | - } |
|
| 299 | - // load_core_config__end hook |
|
| 300 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * _verify_config |
|
| 306 | - * |
|
| 307 | - * @access protected |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - protected function _verify_config() |
|
| 311 | - { |
|
| 312 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | - ? $this->core |
|
| 314 | - : new EE_Core_Config(); |
|
| 315 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | - ? $this->organization |
|
| 318 | - : new EE_Organization_Config(); |
|
| 319 | - $this->organization = apply_filters( |
|
| 320 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | - $this->organization |
|
| 322 | - ); |
|
| 323 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | - ? $this->currency |
|
| 325 | - : new EE_Currency_Config(); |
|
| 326 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | - ? $this->registration |
|
| 329 | - : new EE_Registration_Config(); |
|
| 330 | - $this->registration = apply_filters( |
|
| 331 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | - $this->registration |
|
| 333 | - ); |
|
| 334 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | - ? $this->admin |
|
| 336 | - : new EE_Admin_Config(); |
|
| 337 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | - ? $this->template_settings |
|
| 340 | - : new EE_Template_Config(); |
|
| 341 | - $this->template_settings = apply_filters( |
|
| 342 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | - $this->template_settings |
|
| 344 | - ); |
|
| 345 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | - ? $this->map_settings |
|
| 347 | - : new EE_Map_Config(); |
|
| 348 | - $this->map_settings = apply_filters( |
|
| 349 | - 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | - $this->map_settings |
|
| 351 | - ); |
|
| 352 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | - ? $this->environment |
|
| 354 | - : new EE_Environment_Config(); |
|
| 355 | - $this->environment = apply_filters( |
|
| 356 | - 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | - $this->environment |
|
| 358 | - ); |
|
| 359 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | - ? $this->tax_settings |
|
| 361 | - : new EE_Tax_Config(); |
|
| 362 | - $this->tax_settings = apply_filters( |
|
| 363 | - 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | - $this->tax_settings |
|
| 365 | - ); |
|
| 366 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | - ? $this->messages |
|
| 369 | - : new EE_Messages_Config(); |
|
| 370 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | - ? $this->gateway |
|
| 372 | - : new EE_Gateway_Config(); |
|
| 373 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | - $this->legacy_shortcodes_manager = null; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * get_espresso_config |
|
| 380 | - * |
|
| 381 | - * @access public |
|
| 382 | - * @return array of espresso config stuff |
|
| 383 | - */ |
|
| 384 | - public function get_espresso_config() |
|
| 385 | - { |
|
| 386 | - // grab espresso configuration |
|
| 387 | - return apply_filters( |
|
| 388 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * double_check_config_comparison |
|
| 396 | - * |
|
| 397 | - * @access public |
|
| 398 | - * @param string $option |
|
| 399 | - * @param $old_value |
|
| 400 | - * @param $value |
|
| 401 | - */ |
|
| 402 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | - { |
|
| 404 | - // make sure we're checking the ee config |
|
| 405 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | - if ($value != $old_value) { |
|
| 409 | - // if they are NOT the same, then remove the hook, |
|
| 410 | - // which means the subsequent update results will be based solely on the update query results |
|
| 411 | - // the reason we do this is because, as stated above, |
|
| 412 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | - // If values are found to match their previous old value, |
|
| 415 | - // then WP bails before performing any update. |
|
| 416 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | - // MySQL MAY ALSO NOT perform the update because |
|
| 420 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * update_espresso_config |
|
| 431 | - * |
|
| 432 | - * @access public |
|
| 433 | - */ |
|
| 434 | - protected function _reset_espresso_addon_config() |
|
| 435 | - { |
|
| 436 | - $this->_addon_option_names = array(); |
|
| 437 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | - } |
|
| 442 | - $this->addons->{$addon_name} = null; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * update_espresso_config |
|
| 449 | - * |
|
| 450 | - * @access public |
|
| 451 | - * @param bool $add_success |
|
| 452 | - * @param bool $add_error |
|
| 453 | - * @return bool |
|
| 454 | - */ |
|
| 455 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | - { |
|
| 457 | - // don't allow config updates during WP heartbeats |
|
| 458 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | - // $clone = clone( self::$_instance ); |
|
| 463 | - // self::$_instance = NULL; |
|
| 464 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | - $this->_reset_espresso_addon_config(); |
|
| 466 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | - // but BEFORE the actual update occurs |
|
| 468 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | - $this->legacy_shortcodes_manager = null; |
|
| 472 | - // now update "ee_config" |
|
| 473 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | - // if not saved... check if the hook we just added still exists; |
|
| 477 | - // if it does, it means one of two things: |
|
| 478 | - // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | - // or... |
|
| 480 | - // the db update query returned 0 rows affected |
|
| 481 | - // (probably because the data value was the same from it's perspective) |
|
| 482 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | - // but just means no update occurred, so don't display an error to the user. |
|
| 484 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | - // then it means that something truly went wrong |
|
| 486 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | - // remove our action since we don't want it in the system anymore |
|
| 488 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | - // self::$_instance = $clone; |
|
| 491 | - // unset( $clone ); |
|
| 492 | - // if config remains the same or was updated successfully |
|
| 493 | - if ($saved) { |
|
| 494 | - if ($add_success) { |
|
| 495 | - EE_Error::add_success( |
|
| 496 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | - __FILE__, |
|
| 498 | - __FUNCTION__, |
|
| 499 | - __LINE__ |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - return true; |
|
| 503 | - } else { |
|
| 504 | - if ($add_error) { |
|
| 505 | - EE_Error::add_error( |
|
| 506 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | - __FILE__, |
|
| 508 | - __FUNCTION__, |
|
| 509 | - __LINE__ |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * _verify_config_params |
|
| 519 | - * |
|
| 520 | - * @access private |
|
| 521 | - * @param string $section |
|
| 522 | - * @param string $name |
|
| 523 | - * @param string $config_class |
|
| 524 | - * @param EE_Config_Base $config_obj |
|
| 525 | - * @param array $tests_to_run |
|
| 526 | - * @param bool $display_errors |
|
| 527 | - * @return bool TRUE on success, FALSE on fail |
|
| 528 | - */ |
|
| 529 | - private function _verify_config_params( |
|
| 530 | - $section = '', |
|
| 531 | - $name = '', |
|
| 532 | - $config_class = '', |
|
| 533 | - $config_obj = null, |
|
| 534 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | - $display_errors = true |
|
| 536 | - ) { |
|
| 537 | - try { |
|
| 538 | - foreach ($tests_to_run as $test) { |
|
| 539 | - switch ($test) { |
|
| 540 | - // TEST #1 : check that section was set |
|
| 541 | - case 1: |
|
| 542 | - if (empty($section)) { |
|
| 543 | - if ($display_errors) { |
|
| 544 | - throw new EE_Error( |
|
| 545 | - sprintf( |
|
| 546 | - __( |
|
| 547 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ), |
|
| 550 | - $config_class |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - return false; |
|
| 555 | - } |
|
| 556 | - break; |
|
| 557 | - // TEST #2 : check that settings section exists |
|
| 558 | - case 2: |
|
| 559 | - if (! isset($this->{$section})) { |
|
| 560 | - if ($display_errors) { |
|
| 561 | - throw new EE_Error( |
|
| 562 | - sprintf( |
|
| 563 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | - $section |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - break; |
|
| 571 | - // TEST #3 : check that section is the proper format |
|
| 572 | - case 3: |
|
| 573 | - if ( |
|
| 574 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 575 | - ) { |
|
| 576 | - if ($display_errors) { |
|
| 577 | - throw new EE_Error( |
|
| 578 | - sprintf( |
|
| 579 | - __( |
|
| 580 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 581 | - 'event_espresso' |
|
| 582 | - ), |
|
| 583 | - $section |
|
| 584 | - ) |
|
| 585 | - ); |
|
| 586 | - } |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 589 | - break; |
|
| 590 | - // TEST #4 : check that config section name has been set |
|
| 591 | - case 4: |
|
| 592 | - if (empty($name)) { |
|
| 593 | - if ($display_errors) { |
|
| 594 | - throw new EE_Error( |
|
| 595 | - __( |
|
| 596 | - 'No name has been provided for the specific configuration section.', |
|
| 597 | - 'event_espresso' |
|
| 598 | - ) |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - return false; |
|
| 602 | - } |
|
| 603 | - break; |
|
| 604 | - // TEST #5 : check that a config class name has been set |
|
| 605 | - case 5: |
|
| 606 | - if (empty($config_class)) { |
|
| 607 | - if ($display_errors) { |
|
| 608 | - throw new EE_Error( |
|
| 609 | - __( |
|
| 610 | - 'No class name has been provided for the specific configuration section.', |
|
| 611 | - 'event_espresso' |
|
| 612 | - ) |
|
| 613 | - ); |
|
| 614 | - } |
|
| 615 | - return false; |
|
| 616 | - } |
|
| 617 | - break; |
|
| 618 | - // TEST #6 : verify config class is accessible |
|
| 619 | - case 6: |
|
| 620 | - if (! class_exists($config_class)) { |
|
| 621 | - if ($display_errors) { |
|
| 622 | - throw new EE_Error( |
|
| 623 | - sprintf( |
|
| 624 | - __( |
|
| 625 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 626 | - 'event_espresso' |
|
| 627 | - ), |
|
| 628 | - $config_class |
|
| 629 | - ) |
|
| 630 | - ); |
|
| 631 | - } |
|
| 632 | - return false; |
|
| 633 | - } |
|
| 634 | - break; |
|
| 635 | - // TEST #7 : check that config has even been set |
|
| 636 | - case 7: |
|
| 637 | - if (! isset($this->{$section}->{$name})) { |
|
| 638 | - if ($display_errors) { |
|
| 639 | - throw new EE_Error( |
|
| 640 | - sprintf( |
|
| 641 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 642 | - $section, |
|
| 643 | - $name |
|
| 644 | - ) |
|
| 645 | - ); |
|
| 646 | - } |
|
| 647 | - return false; |
|
| 648 | - } else { |
|
| 649 | - // and make sure it's not serialized |
|
| 650 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 651 | - } |
|
| 652 | - break; |
|
| 653 | - // TEST #8 : check that config is the requested type |
|
| 654 | - case 8: |
|
| 655 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 656 | - if ($display_errors) { |
|
| 657 | - throw new EE_Error( |
|
| 658 | - sprintf( |
|
| 659 | - __( |
|
| 660 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 661 | - 'event_espresso' |
|
| 662 | - ), |
|
| 663 | - $section, |
|
| 664 | - $name, |
|
| 665 | - $config_class |
|
| 666 | - ) |
|
| 667 | - ); |
|
| 668 | - } |
|
| 669 | - return false; |
|
| 670 | - } |
|
| 671 | - break; |
|
| 672 | - // TEST #9 : verify config object |
|
| 673 | - case 9: |
|
| 674 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 675 | - if ($display_errors) { |
|
| 676 | - throw new EE_Error( |
|
| 677 | - sprintf( |
|
| 678 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 679 | - print_r($config_obj, true) |
|
| 680 | - ) |
|
| 681 | - ); |
|
| 682 | - } |
|
| 683 | - return false; |
|
| 684 | - } |
|
| 685 | - break; |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - } catch (EE_Error $e) { |
|
| 689 | - $e->get_error(); |
|
| 690 | - } |
|
| 691 | - // you have successfully run the gauntlet |
|
| 692 | - return true; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * _generate_config_option_name |
|
| 698 | - * |
|
| 699 | - * @access protected |
|
| 700 | - * @param string $section |
|
| 701 | - * @param string $name |
|
| 702 | - * @return string |
|
| 703 | - */ |
|
| 704 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 705 | - { |
|
| 706 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * _set_config_class |
|
| 712 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 713 | - * |
|
| 714 | - * @access private |
|
| 715 | - * @param string $config_class |
|
| 716 | - * @param string $name |
|
| 717 | - * @return string |
|
| 718 | - */ |
|
| 719 | - private function _set_config_class($config_class = '', $name = '') |
|
| 720 | - { |
|
| 721 | - return ! empty($config_class) |
|
| 722 | - ? $config_class |
|
| 723 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * set_config |
|
| 729 | - * |
|
| 730 | - * @access protected |
|
| 731 | - * @param string $section |
|
| 732 | - * @param string $name |
|
| 733 | - * @param string $config_class |
|
| 734 | - * @param EE_Config_Base $config_obj |
|
| 735 | - * @return EE_Config_Base |
|
| 736 | - */ |
|
| 737 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 738 | - { |
|
| 739 | - // ensure config class is set to something |
|
| 740 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 741 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 742 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 743 | - return null; |
|
| 744 | - } |
|
| 745 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 746 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 747 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 748 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 749 | - $this->update_addon_option_names(); |
|
| 750 | - } |
|
| 751 | - // verify the incoming config object but suppress errors |
|
| 752 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 753 | - $config_obj = new $config_class(); |
|
| 754 | - } |
|
| 755 | - if (get_option($config_option_name)) { |
|
| 756 | - EE_Config::log($config_option_name); |
|
| 757 | - update_option($config_option_name, $config_obj); |
|
| 758 | - $this->{$section}->{$name} = $config_obj; |
|
| 759 | - return $this->{$section}->{$name}; |
|
| 760 | - } else { |
|
| 761 | - // create a wp-option for this config |
|
| 762 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 763 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 764 | - return $this->{$section}->{$name}; |
|
| 765 | - } else { |
|
| 766 | - EE_Error::add_error( |
|
| 767 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 768 | - __FILE__, |
|
| 769 | - __FUNCTION__, |
|
| 770 | - __LINE__ |
|
| 771 | - ); |
|
| 772 | - return null; |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * update_config |
|
| 780 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 781 | - * |
|
| 782 | - * @access public |
|
| 783 | - * @param string $section |
|
| 784 | - * @param string $name |
|
| 785 | - * @param EE_Config_Base|string $config_obj |
|
| 786 | - * @param bool $throw_errors |
|
| 787 | - * @return bool |
|
| 788 | - */ |
|
| 789 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 790 | - { |
|
| 791 | - // don't allow config updates during WP heartbeats |
|
| 792 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 793 | - return false; |
|
| 794 | - } |
|
| 795 | - $config_obj = maybe_unserialize($config_obj); |
|
| 796 | - // get class name of the incoming object |
|
| 797 | - $config_class = get_class($config_obj); |
|
| 798 | - // run tests 1-5 and 9 to verify config |
|
| 799 | - if ( |
|
| 800 | - ! $this->_verify_config_params( |
|
| 801 | - $section, |
|
| 802 | - $name, |
|
| 803 | - $config_class, |
|
| 804 | - $config_obj, |
|
| 805 | - array(1, 2, 3, 4, 7, 9) |
|
| 806 | - ) |
|
| 807 | - ) { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 811 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 812 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 813 | - // save new config to db |
|
| 814 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 815 | - return true; |
|
| 816 | - } |
|
| 817 | - } else { |
|
| 818 | - // first check if the record already exists |
|
| 819 | - $existing_config = get_option($config_option_name); |
|
| 820 | - $config_obj = serialize($config_obj); |
|
| 821 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 822 | - if ($existing_config == $config_obj) { |
|
| 823 | - $this->{$section}->{$name} = $config_obj; |
|
| 824 | - return true; |
|
| 825 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
| 826 | - EE_Config::log($config_option_name); |
|
| 827 | - // update wp-option for this config class |
|
| 828 | - $this->{$section}->{$name} = $config_obj; |
|
| 829 | - return true; |
|
| 830 | - } elseif ($throw_errors) { |
|
| 831 | - EE_Error::add_error( |
|
| 832 | - sprintf( |
|
| 833 | - __( |
|
| 834 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 835 | - 'event_espresso' |
|
| 836 | - ), |
|
| 837 | - $config_class, |
|
| 838 | - 'EE_Config->' . $section . '->' . $name |
|
| 839 | - ), |
|
| 840 | - __FILE__, |
|
| 841 | - __FUNCTION__, |
|
| 842 | - __LINE__ |
|
| 843 | - ); |
|
| 844 | - } |
|
| 845 | - } |
|
| 846 | - return false; |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * get_config |
|
| 852 | - * |
|
| 853 | - * @access public |
|
| 854 | - * @param string $section |
|
| 855 | - * @param string $name |
|
| 856 | - * @param string $config_class |
|
| 857 | - * @return mixed EE_Config_Base | NULL |
|
| 858 | - */ |
|
| 859 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 860 | - { |
|
| 861 | - // ensure config class is set to something |
|
| 862 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 863 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 864 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 865 | - return null; |
|
| 866 | - } |
|
| 867 | - // now test if the requested config object exists, but suppress errors |
|
| 868 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 869 | - // config already exists, so pass it back |
|
| 870 | - return $this->{$section}->{$name}; |
|
| 871 | - } |
|
| 872 | - // load config option from db if it exists |
|
| 873 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 874 | - // verify the newly retrieved config object, but suppress errors |
|
| 875 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 876 | - // config is good, so set it and pass it back |
|
| 877 | - $this->{$section}->{$name} = $config_obj; |
|
| 878 | - return $this->{$section}->{$name}; |
|
| 879 | - } |
|
| 880 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 881 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 882 | - // verify the newly created config object |
|
| 883 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 884 | - return $this->{$section}->{$name}; |
|
| 885 | - } else { |
|
| 886 | - EE_Error::add_error( |
|
| 887 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 888 | - __FILE__, |
|
| 889 | - __FUNCTION__, |
|
| 890 | - __LINE__ |
|
| 891 | - ); |
|
| 892 | - } |
|
| 893 | - return null; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * get_config_option |
|
| 899 | - * |
|
| 900 | - * @access public |
|
| 901 | - * @param string $config_option_name |
|
| 902 | - * @return mixed EE_Config_Base | FALSE |
|
| 903 | - */ |
|
| 904 | - public function get_config_option($config_option_name = '') |
|
| 905 | - { |
|
| 906 | - // retrieve the wp-option for this config class. |
|
| 907 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 908 | - if (empty($config_option)) { |
|
| 909 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 910 | - } |
|
| 911 | - return $config_option; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - /** |
|
| 916 | - * log |
|
| 917 | - * |
|
| 918 | - * @param string $config_option_name |
|
| 919 | - */ |
|
| 920 | - public static function log($config_option_name = '') |
|
| 921 | - { |
|
| 922 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 923 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 924 | - // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 925 | - $_request = $_REQUEST; |
|
| 926 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 927 | - $config_log[ (string) microtime(true) ] = array( |
|
| 928 | - 'config_name' => $config_option_name, |
|
| 929 | - 'request' => $_request, |
|
| 930 | - ); |
|
| 931 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - /** |
|
| 937 | - * trim_log |
|
| 938 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 939 | - */ |
|
| 940 | - public static function trim_log() |
|
| 941 | - { |
|
| 942 | - if (! EE_Config::logging_enabled()) { |
|
| 943 | - return; |
|
| 944 | - } |
|
| 945 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 946 | - $log_length = count($config_log); |
|
| 947 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 948 | - ksort($config_log); |
|
| 949 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 950 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 951 | - } |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * get_page_for_posts |
|
| 957 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 958 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 959 | - * |
|
| 960 | - * @access public |
|
| 961 | - * @return string |
|
| 962 | - */ |
|
| 963 | - public static function get_page_for_posts() |
|
| 964 | - { |
|
| 965 | - $page_for_posts = get_option('page_for_posts'); |
|
| 966 | - if (! $page_for_posts) { |
|
| 967 | - return 'posts'; |
|
| 968 | - } |
|
| 969 | - /** @type WPDB $wpdb */ |
|
| 970 | - global $wpdb; |
|
| 971 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 972 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - |
|
| 976 | - /** |
|
| 977 | - * register_shortcodes_and_modules. |
|
| 978 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 979 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 980 | - * so they can help trigger maintenance mode if it's needed |
|
| 981 | - * |
|
| 982 | - * @access public |
|
| 983 | - * @return void |
|
| 984 | - */ |
|
| 985 | - public function register_shortcodes_and_modules() |
|
| 986 | - { |
|
| 987 | - // allow modules to set hooks for the rest of the system |
|
| 988 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - /** |
|
| 993 | - * initialize_shortcodes_and_modules |
|
| 994 | - * meaning they can start adding their hooks to get stuff done |
|
| 995 | - * |
|
| 996 | - * @access public |
|
| 997 | - * @return void |
|
| 998 | - */ |
|
| 999 | - public function initialize_shortcodes_and_modules() |
|
| 1000 | - { |
|
| 1001 | - // allow modules to set hooks for the rest of the system |
|
| 1002 | - $this->_initialize_modules(); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * widgets_init |
|
| 1008 | - * |
|
| 1009 | - * @access private |
|
| 1010 | - * @return void |
|
| 1011 | - */ |
|
| 1012 | - public function widgets_init() |
|
| 1013 | - { |
|
| 1014 | - // only init widgets on admin pages when not in complete maintenance, and |
|
| 1015 | - // on frontend when not in any maintenance mode |
|
| 1016 | - if ( |
|
| 1017 | - ! EE_Maintenance_Mode::instance()->level() |
|
| 1018 | - || ( |
|
| 1019 | - is_admin() |
|
| 1020 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1021 | - ) |
|
| 1022 | - ) { |
|
| 1023 | - // grab list of installed widgets |
|
| 1024 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1025 | - // filter list of modules to register |
|
| 1026 | - $widgets_to_register = apply_filters( |
|
| 1027 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1028 | - $widgets_to_register |
|
| 1029 | - ); |
|
| 1030 | - if (! empty($widgets_to_register)) { |
|
| 1031 | - // cycle thru widget folders |
|
| 1032 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1033 | - // add to list of installed widget modules |
|
| 1034 | - EE_Config::register_ee_widget($widget_path); |
|
| 1035 | - } |
|
| 1036 | - } |
|
| 1037 | - // filter list of installed modules |
|
| 1038 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1039 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1040 | - EE_Registry::instance()->widgets |
|
| 1041 | - ); |
|
| 1042 | - } |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * register_ee_widget - makes core aware of this widget |
|
| 1048 | - * |
|
| 1049 | - * @access public |
|
| 1050 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1051 | - * @return void |
|
| 1052 | - */ |
|
| 1053 | - public static function register_ee_widget($widget_path = null) |
|
| 1054 | - { |
|
| 1055 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1056 | - $widget_ext = '.widget.php'; |
|
| 1057 | - // make all separators match |
|
| 1058 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1059 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1060 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1061 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1062 | - $file_name = explode('.', basename($widget_path)); |
|
| 1063 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1064 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1065 | - // sanitize shortcode directory name |
|
| 1066 | - $widget = sanitize_key($widget); |
|
| 1067 | - // now we need to rebuild the shortcode path |
|
| 1068 | - $widget_path = explode('/', $widget_path); |
|
| 1069 | - // remove last segment |
|
| 1070 | - array_pop($widget_path); |
|
| 1071 | - // glue it back together |
|
| 1072 | - $widget_path = implode(DS, $widget_path); |
|
| 1073 | - } else { |
|
| 1074 | - // grab and sanitize widget directory name |
|
| 1075 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1076 | - } |
|
| 1077 | - // create classname from widget directory name |
|
| 1078 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1079 | - // add class prefix |
|
| 1080 | - $widget_class = 'EEW_' . $widget; |
|
| 1081 | - // does the widget exist ? |
|
| 1082 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1083 | - $msg = sprintf( |
|
| 1084 | - __( |
|
| 1085 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1086 | - 'event_espresso' |
|
| 1087 | - ), |
|
| 1088 | - $widget_class, |
|
| 1089 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1090 | - ); |
|
| 1091 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1092 | - return; |
|
| 1093 | - } |
|
| 1094 | - // load the widget class file |
|
| 1095 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1096 | - // verify that class exists |
|
| 1097 | - if (! class_exists($widget_class)) { |
|
| 1098 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1099 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1100 | - return; |
|
| 1101 | - } |
|
| 1102 | - register_widget($widget_class); |
|
| 1103 | - // add to array of registered widgets |
|
| 1104 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * _register_modules |
|
| 1110 | - * |
|
| 1111 | - * @access private |
|
| 1112 | - * @return array |
|
| 1113 | - */ |
|
| 1114 | - private function _register_modules() |
|
| 1115 | - { |
|
| 1116 | - // grab list of installed modules |
|
| 1117 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1118 | - // filter list of modules to register |
|
| 1119 | - $modules_to_register = apply_filters( |
|
| 1120 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1121 | - $modules_to_register |
|
| 1122 | - ); |
|
| 1123 | - if (! empty($modules_to_register)) { |
|
| 1124 | - // loop through folders |
|
| 1125 | - foreach ($modules_to_register as $module_path) { |
|
| 1126 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1127 | - if ( |
|
| 1128 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1129 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1130 | - ) { |
|
| 1131 | - // add to list of installed modules |
|
| 1132 | - EE_Config::register_module($module_path); |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1136 | - // filter list of installed modules |
|
| 1137 | - return apply_filters( |
|
| 1138 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1139 | - EE_Registry::instance()->modules |
|
| 1140 | - ); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * register_module - makes core aware of this module |
|
| 1146 | - * |
|
| 1147 | - * @access public |
|
| 1148 | - * @param string $module_path - full path up to and including module folder |
|
| 1149 | - * @return bool |
|
| 1150 | - */ |
|
| 1151 | - public static function register_module($module_path = null) |
|
| 1152 | - { |
|
| 1153 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1154 | - $module_ext = '.module.php'; |
|
| 1155 | - // make all separators match |
|
| 1156 | - $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1157 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1158 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1159 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1160 | - $module_file = explode('.', basename($module_path)); |
|
| 1161 | - // now we need to rebuild the shortcode path |
|
| 1162 | - $module_path = explode('/', $module_path); |
|
| 1163 | - // remove last segment |
|
| 1164 | - array_pop($module_path); |
|
| 1165 | - // glue it back together |
|
| 1166 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1167 | - // take first segment from file name pieces and sanitize it |
|
| 1168 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1169 | - // ensure class prefix is added |
|
| 1170 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1171 | - } else { |
|
| 1172 | - // we need to generate the filename based off of the folder name |
|
| 1173 | - // grab and sanitize module name |
|
| 1174 | - $module = strtolower(basename($module_path)); |
|
| 1175 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1176 | - // like trailingslashit() |
|
| 1177 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1178 | - // create classname from module directory name |
|
| 1179 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1180 | - // add class prefix |
|
| 1181 | - $module_class = 'EED_' . $module; |
|
| 1182 | - } |
|
| 1183 | - // does the module exist ? |
|
| 1184 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1185 | - $msg = sprintf( |
|
| 1186 | - __( |
|
| 1187 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1188 | - 'event_espresso' |
|
| 1189 | - ), |
|
| 1190 | - $module |
|
| 1191 | - ); |
|
| 1192 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1193 | - return false; |
|
| 1194 | - } |
|
| 1195 | - // load the module class file |
|
| 1196 | - require_once($module_path . $module_class . $module_ext); |
|
| 1197 | - // verify that class exists |
|
| 1198 | - if (! class_exists($module_class)) { |
|
| 1199 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1200 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1201 | - return false; |
|
| 1202 | - } |
|
| 1203 | - // add to array of registered modules |
|
| 1204 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1205 | - do_action( |
|
| 1206 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1207 | - $module_class, |
|
| 1208 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1209 | - ); |
|
| 1210 | - return true; |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - |
|
| 1214 | - /** |
|
| 1215 | - * _initialize_modules |
|
| 1216 | - * allow modules to set hooks for the rest of the system |
|
| 1217 | - * |
|
| 1218 | - * @access private |
|
| 1219 | - * @return void |
|
| 1220 | - */ |
|
| 1221 | - private function _initialize_modules() |
|
| 1222 | - { |
|
| 1223 | - // cycle thru shortcode folders |
|
| 1224 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1225 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1226 | - // which set hooks ? |
|
| 1227 | - if (is_admin()) { |
|
| 1228 | - // fire immediately |
|
| 1229 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1230 | - } else { |
|
| 1231 | - // delay until other systems are online |
|
| 1232 | - add_action( |
|
| 1233 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1234 | - array($module_class, 'set_hooks') |
|
| 1235 | - ); |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - |
|
| 1241 | - /** |
|
| 1242 | - * register_route - adds module method routes to route_map |
|
| 1243 | - * |
|
| 1244 | - * @access public |
|
| 1245 | - * @param string $route - "pretty" public alias for module method |
|
| 1246 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1247 | - * @param string $method_name - the actual module method to be routed to |
|
| 1248 | - * @param string $key - url param key indicating a route is being called |
|
| 1249 | - * @return bool |
|
| 1250 | - */ |
|
| 1251 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1252 | - { |
|
| 1253 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1254 | - $module = str_replace('EED_', '', $module); |
|
| 1255 | - $module_class = 'EED_' . $module; |
|
| 1256 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1257 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1258 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1259 | - return false; |
|
| 1260 | - } |
|
| 1261 | - if (empty($route)) { |
|
| 1262 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1263 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1264 | - return false; |
|
| 1265 | - } |
|
| 1266 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1267 | - $msg = sprintf( |
|
| 1268 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1269 | - $route |
|
| 1270 | - ); |
|
| 1271 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1272 | - return false; |
|
| 1273 | - } |
|
| 1274 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1275 | - return true; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * get_route - get module method route |
|
| 1281 | - * |
|
| 1282 | - * @access public |
|
| 1283 | - * @param string $route - "pretty" public alias for module method |
|
| 1284 | - * @param string $key - url param key indicating a route is being called |
|
| 1285 | - * @return string |
|
| 1286 | - */ |
|
| 1287 | - public static function get_route($route = null, $key = 'ee') |
|
| 1288 | - { |
|
| 1289 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1290 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1291 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1292 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1293 | - } |
|
| 1294 | - return null; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * get_routes - get ALL module method routes |
|
| 1300 | - * |
|
| 1301 | - * @access public |
|
| 1302 | - * @return array |
|
| 1303 | - */ |
|
| 1304 | - public static function get_routes() |
|
| 1305 | - { |
|
| 1306 | - return EE_Config::$_module_route_map; |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1312 | - * |
|
| 1313 | - * @access public |
|
| 1314 | - * @param string $route - "pretty" public alias for module method |
|
| 1315 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1316 | - * class, allows different forwards to be served based on status |
|
| 1317 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1318 | - * @param string $key - url param key indicating a route is being called |
|
| 1319 | - * @return bool |
|
| 1320 | - */ |
|
| 1321 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1322 | - { |
|
| 1323 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1324 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1325 | - $msg = sprintf( |
|
| 1326 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1327 | - $route |
|
| 1328 | - ); |
|
| 1329 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1330 | - return false; |
|
| 1331 | - } |
|
| 1332 | - if (empty($forward)) { |
|
| 1333 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1334 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1335 | - return false; |
|
| 1336 | - } |
|
| 1337 | - if (is_array($forward)) { |
|
| 1338 | - if (! isset($forward[1])) { |
|
| 1339 | - $msg = sprintf( |
|
| 1340 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1341 | - $route |
|
| 1342 | - ); |
|
| 1343 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1344 | - return false; |
|
| 1345 | - } |
|
| 1346 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1347 | - $msg = sprintf( |
|
| 1348 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1349 | - $forward[1], |
|
| 1350 | - $route |
|
| 1351 | - ); |
|
| 1352 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1353 | - return false; |
|
| 1354 | - } |
|
| 1355 | - } elseif (! function_exists($forward)) { |
|
| 1356 | - $msg = sprintf( |
|
| 1357 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1358 | - $forward, |
|
| 1359 | - $route |
|
| 1360 | - ); |
|
| 1361 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1362 | - return false; |
|
| 1363 | - } |
|
| 1364 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1365 | - return true; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /** |
|
| 1370 | - * get_forward - get forwarding route |
|
| 1371 | - * |
|
| 1372 | - * @access public |
|
| 1373 | - * @param string $route - "pretty" public alias for module method |
|
| 1374 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1375 | - * allows different forwards to be served based on status |
|
| 1376 | - * @param string $key - url param key indicating a route is being called |
|
| 1377 | - * @return string |
|
| 1378 | - */ |
|
| 1379 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1380 | - { |
|
| 1381 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1382 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1383 | - return apply_filters( |
|
| 1384 | - 'FHEE__EE_Config__get_forward', |
|
| 1385 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1386 | - $route, |
|
| 1387 | - $status |
|
| 1388 | - ); |
|
| 1389 | - } |
|
| 1390 | - return null; |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1396 | - * results |
|
| 1397 | - * |
|
| 1398 | - * @access public |
|
| 1399 | - * @param string $route - "pretty" public alias for module method |
|
| 1400 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1401 | - * allows different views to be served based on status |
|
| 1402 | - * @param string $view |
|
| 1403 | - * @param string $key - url param key indicating a route is being called |
|
| 1404 | - * @return bool |
|
| 1405 | - */ |
|
| 1406 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1407 | - { |
|
| 1408 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1409 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1410 | - $msg = sprintf( |
|
| 1411 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1412 | - $route |
|
| 1413 | - ); |
|
| 1414 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1415 | - return false; |
|
| 1416 | - } |
|
| 1417 | - if (! is_readable($view)) { |
|
| 1418 | - $msg = sprintf( |
|
| 1419 | - __( |
|
| 1420 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1421 | - 'event_espresso' |
|
| 1422 | - ), |
|
| 1423 | - $view |
|
| 1424 | - ); |
|
| 1425 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1426 | - return false; |
|
| 1427 | - } |
|
| 1428 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1429 | - return true; |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - |
|
| 1433 | - /** |
|
| 1434 | - * get_view - get view for route and status |
|
| 1435 | - * |
|
| 1436 | - * @access public |
|
| 1437 | - * @param string $route - "pretty" public alias for module method |
|
| 1438 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1439 | - * allows different views to be served based on status |
|
| 1440 | - * @param string $key - url param key indicating a route is being called |
|
| 1441 | - * @return string |
|
| 1442 | - */ |
|
| 1443 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1444 | - { |
|
| 1445 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1446 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1447 | - return apply_filters( |
|
| 1448 | - 'FHEE__EE_Config__get_view', |
|
| 1449 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1450 | - $route, |
|
| 1451 | - $status |
|
| 1452 | - ); |
|
| 1453 | - } |
|
| 1454 | - return null; |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - |
|
| 1458 | - public function update_addon_option_names() |
|
| 1459 | - { |
|
| 1460 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - |
|
| 1464 | - public function shutdown() |
|
| 1465 | - { |
|
| 1466 | - $this->update_addon_option_names(); |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * @return LegacyShortcodesManager |
|
| 1472 | - */ |
|
| 1473 | - public static function getLegacyShortcodesManager() |
|
| 1474 | - { |
|
| 1475 | - |
|
| 1476 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1477 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1478 | - EE_Registry::instance() |
|
| 1479 | - ); |
|
| 1480 | - } |
|
| 1481 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - |
|
| 1485 | - /** |
|
| 1486 | - * register_shortcode - makes core aware of this shortcode |
|
| 1487 | - * |
|
| 1488 | - * @deprecated 4.9.26 |
|
| 1489 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1490 | - * @return bool |
|
| 1491 | - */ |
|
| 1492 | - public static function register_shortcode($shortcode_path = null) |
|
| 1493 | - { |
|
| 1494 | - EE_Error::doing_it_wrong( |
|
| 1495 | - __METHOD__, |
|
| 1496 | - __( |
|
| 1497 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1498 | - 'event_espresso' |
|
| 1499 | - ), |
|
| 1500 | - '4.9.26' |
|
| 1501 | - ); |
|
| 1502 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1503 | - } |
|
| 1504 | -} |
|
| 1505 | - |
|
| 1506 | -/** |
|
| 1507 | - * Base class used for config classes. These classes should generally not have |
|
| 1508 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1509 | - * basically, they should just be well-defined stdClasses |
|
| 1510 | - */ |
|
| 1511 | -class EE_Config_Base |
|
| 1512 | -{ |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * Utility function for escaping the value of a property and returning. |
|
| 1516 | - * |
|
| 1517 | - * @param string $property property name (checks to see if exists). |
|
| 1518 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1519 | - * @throws \EE_Error |
|
| 1520 | - */ |
|
| 1521 | - public function get_pretty($property) |
|
| 1522 | - { |
|
| 1523 | - if (! property_exists($this, $property)) { |
|
| 1524 | - throw new EE_Error( |
|
| 1525 | - sprintf( |
|
| 1526 | - __( |
|
| 1527 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1528 | - 'event_espresso' |
|
| 1529 | - ), |
|
| 1530 | - get_class($this), |
|
| 1531 | - $property |
|
| 1532 | - ) |
|
| 1533 | - ); |
|
| 1534 | - } |
|
| 1535 | - // just handling escaping of strings for now. |
|
| 1536 | - if (is_string($this->{$property})) { |
|
| 1537 | - return stripslashes($this->{$property}); |
|
| 1538 | - } |
|
| 1539 | - return $this->{$property}; |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - |
|
| 1543 | - public function populate() |
|
| 1544 | - { |
|
| 1545 | - // grab defaults via a new instance of this class. |
|
| 1546 | - $class_name = get_class($this); |
|
| 1547 | - $defaults = new $class_name(); |
|
| 1548 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1549 | - // default from our $defaults object. |
|
| 1550 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1551 | - if ($this->{$property} === null) { |
|
| 1552 | - $this->{$property} = $value; |
|
| 1553 | - } |
|
| 1554 | - } |
|
| 1555 | - // cleanup |
|
| 1556 | - unset($defaults); |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - |
|
| 1560 | - /** |
|
| 1561 | - * __isset |
|
| 1562 | - * |
|
| 1563 | - * @param $a |
|
| 1564 | - * @return bool |
|
| 1565 | - */ |
|
| 1566 | - public function __isset($a) |
|
| 1567 | - { |
|
| 1568 | - return false; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - |
|
| 1572 | - /** |
|
| 1573 | - * __unset |
|
| 1574 | - * |
|
| 1575 | - * @param $a |
|
| 1576 | - * @return bool |
|
| 1577 | - */ |
|
| 1578 | - public function __unset($a) |
|
| 1579 | - { |
|
| 1580 | - return false; |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - |
|
| 1584 | - /** |
|
| 1585 | - * __clone |
|
| 1586 | - */ |
|
| 1587 | - public function __clone() |
|
| 1588 | - { |
|
| 1589 | - } |
|
| 1590 | - |
|
| 1591 | - |
|
| 1592 | - /** |
|
| 1593 | - * __wakeup |
|
| 1594 | - */ |
|
| 1595 | - public function __wakeup() |
|
| 1596 | - { |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - |
|
| 1600 | - /** |
|
| 1601 | - * __destruct |
|
| 1602 | - */ |
|
| 1603 | - public function __destruct() |
|
| 1604 | - { |
|
| 1605 | - } |
|
| 1606 | -} |
|
| 1607 | - |
|
| 1608 | -/** |
|
| 1609 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1610 | - */ |
|
| 1611 | -class EE_Core_Config extends EE_Config_Base |
|
| 1612 | -{ |
|
| 1613 | - |
|
| 1614 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1615 | - |
|
| 1616 | - |
|
| 1617 | - public $current_blog_id; |
|
| 1618 | - |
|
| 1619 | - public $ee_ueip_optin; |
|
| 1620 | - |
|
| 1621 | - public $ee_ueip_has_notified; |
|
| 1622 | - |
|
| 1623 | - /** |
|
| 1624 | - * Not to be confused with the 4 critical page variables (See |
|
| 1625 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1626 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1627 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1628 | - * |
|
| 1629 | - * @var array |
|
| 1630 | - */ |
|
| 1631 | - public $post_shortcodes; |
|
| 1632 | - |
|
| 1633 | - public $module_route_map; |
|
| 1634 | - |
|
| 1635 | - public $module_forward_map; |
|
| 1636 | - |
|
| 1637 | - public $module_view_map; |
|
| 1638 | - |
|
| 1639 | - /** |
|
| 1640 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1641 | - * |
|
| 1642 | - * @var int |
|
| 1643 | - */ |
|
| 1644 | - public $reg_page_id; |
|
| 1645 | - |
|
| 1646 | - public $txn_page_id; |
|
| 1647 | - |
|
| 1648 | - public $thank_you_page_id; |
|
| 1649 | - |
|
| 1650 | - public $cancel_page_id; |
|
| 1651 | - |
|
| 1652 | - /** |
|
| 1653 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1654 | - * |
|
| 1655 | - * @var int |
|
| 1656 | - */ |
|
| 1657 | - public $reg_page_url; |
|
| 1658 | - |
|
| 1659 | - public $txn_page_url; |
|
| 1660 | - |
|
| 1661 | - public $thank_you_page_url; |
|
| 1662 | - |
|
| 1663 | - public $cancel_page_url; |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1667 | - */ |
|
| 1668 | - public $event_cpt_slug; |
|
| 1669 | - |
|
| 1670 | - /** |
|
| 1671 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1672 | - * request across blog switches in a multisite context. |
|
| 1673 | - * Avoids extra queries to the db for this option. |
|
| 1674 | - * |
|
| 1675 | - * @var bool |
|
| 1676 | - */ |
|
| 1677 | - public static $ee_ueip_option; |
|
| 1678 | - |
|
| 1679 | - |
|
| 1680 | - /** |
|
| 1681 | - * class constructor |
|
| 1682 | - * |
|
| 1683 | - * @access public |
|
| 1684 | - */ |
|
| 1685 | - public function __construct() |
|
| 1686 | - { |
|
| 1687 | - // set default organization settings |
|
| 1688 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1689 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1690 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1691 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1692 | - $this->post_shortcodes = array(); |
|
| 1693 | - $this->module_route_map = array(); |
|
| 1694 | - $this->module_forward_map = array(); |
|
| 1695 | - $this->module_view_map = array(); |
|
| 1696 | - // critical EE page IDs |
|
| 1697 | - $this->reg_page_id = 0; |
|
| 1698 | - $this->txn_page_id = 0; |
|
| 1699 | - $this->thank_you_page_id = 0; |
|
| 1700 | - $this->cancel_page_id = 0; |
|
| 1701 | - // critical EE page URLs |
|
| 1702 | - $this->reg_page_url = ''; |
|
| 1703 | - $this->txn_page_url = ''; |
|
| 1704 | - $this->thank_you_page_url = ''; |
|
| 1705 | - $this->cancel_page_url = ''; |
|
| 1706 | - // cpt slugs |
|
| 1707 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1708 | - // ueip constant check |
|
| 1709 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1710 | - $this->ee_ueip_optin = false; |
|
| 1711 | - $this->ee_ueip_has_notified = true; |
|
| 1712 | - } |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - |
|
| 1716 | - /** |
|
| 1717 | - * @return array |
|
| 1718 | - */ |
|
| 1719 | - public function get_critical_pages_array() |
|
| 1720 | - { |
|
| 1721 | - return array( |
|
| 1722 | - $this->reg_page_id, |
|
| 1723 | - $this->txn_page_id, |
|
| 1724 | - $this->thank_you_page_id, |
|
| 1725 | - $this->cancel_page_id, |
|
| 1726 | - ); |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * @return array |
|
| 1732 | - */ |
|
| 1733 | - public function get_critical_pages_shortcodes_array() |
|
| 1734 | - { |
|
| 1735 | - return array( |
|
| 1736 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1737 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1738 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1739 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1740 | - ); |
|
| 1741 | - } |
|
| 1742 | - |
|
| 1743 | - |
|
| 1744 | - /** |
|
| 1745 | - * gets/returns URL for EE reg_page |
|
| 1746 | - * |
|
| 1747 | - * @access public |
|
| 1748 | - * @return string |
|
| 1749 | - */ |
|
| 1750 | - public function reg_page_url() |
|
| 1751 | - { |
|
| 1752 | - if (! $this->reg_page_url) { |
|
| 1753 | - $this->reg_page_url = add_query_arg( |
|
| 1754 | - array('uts' => time()), |
|
| 1755 | - get_permalink($this->reg_page_id) |
|
| 1756 | - ) . '#checkout'; |
|
| 1757 | - } |
|
| 1758 | - return $this->reg_page_url; |
|
| 1759 | - } |
|
| 1760 | - |
|
| 1761 | - |
|
| 1762 | - /** |
|
| 1763 | - * gets/returns URL for EE txn_page |
|
| 1764 | - * |
|
| 1765 | - * @param array $query_args like what gets passed to |
|
| 1766 | - * add_query_arg() as the first argument |
|
| 1767 | - * @access public |
|
| 1768 | - * @return string |
|
| 1769 | - */ |
|
| 1770 | - public function txn_page_url($query_args = array()) |
|
| 1771 | - { |
|
| 1772 | - if (! $this->txn_page_url) { |
|
| 1773 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1774 | - } |
|
| 1775 | - if ($query_args) { |
|
| 1776 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1777 | - } else { |
|
| 1778 | - return $this->txn_page_url; |
|
| 1779 | - } |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - |
|
| 1783 | - /** |
|
| 1784 | - * gets/returns URL for EE thank_you_page |
|
| 1785 | - * |
|
| 1786 | - * @param array $query_args like what gets passed to |
|
| 1787 | - * add_query_arg() as the first argument |
|
| 1788 | - * @access public |
|
| 1789 | - * @return string |
|
| 1790 | - */ |
|
| 1791 | - public function thank_you_page_url($query_args = array()) |
|
| 1792 | - { |
|
| 1793 | - if (! $this->thank_you_page_url) { |
|
| 1794 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1795 | - } |
|
| 1796 | - if ($query_args) { |
|
| 1797 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1798 | - } else { |
|
| 1799 | - return $this->thank_you_page_url; |
|
| 1800 | - } |
|
| 1801 | - } |
|
| 1802 | - |
|
| 1803 | - |
|
| 1804 | - /** |
|
| 1805 | - * gets/returns URL for EE cancel_page |
|
| 1806 | - * |
|
| 1807 | - * @access public |
|
| 1808 | - * @return string |
|
| 1809 | - */ |
|
| 1810 | - public function cancel_page_url() |
|
| 1811 | - { |
|
| 1812 | - if (! $this->cancel_page_url) { |
|
| 1813 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1814 | - } |
|
| 1815 | - return $this->cancel_page_url; |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1821 | - * |
|
| 1822 | - * @since 4.7.5 |
|
| 1823 | - */ |
|
| 1824 | - protected function _reset_urls() |
|
| 1825 | - { |
|
| 1826 | - $this->reg_page_url = ''; |
|
| 1827 | - $this->txn_page_url = ''; |
|
| 1828 | - $this->cancel_page_url = ''; |
|
| 1829 | - $this->thank_you_page_url = ''; |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - |
|
| 1833 | - /** |
|
| 1834 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1835 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1836 | - * on the main site only. |
|
| 1837 | - * |
|
| 1838 | - * @return bool |
|
| 1839 | - */ |
|
| 1840 | - protected function _get_main_ee_ueip_optin() |
|
| 1841 | - { |
|
| 1842 | - // if this is the main site then we can just bypass our direct query. |
|
| 1843 | - if (is_main_site()) { |
|
| 1844 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1845 | - } |
|
| 1846 | - // is this already cached for this request? If so use it. |
|
| 1847 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1848 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1849 | - } |
|
| 1850 | - global $wpdb; |
|
| 1851 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1852 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1853 | - $option = self::OPTION_NAME_UXIP; |
|
| 1854 | - // set correct table for query |
|
| 1855 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1856 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1857 | - // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1858 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1859 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1860 | - // for the purpose of caching. |
|
| 1861 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1862 | - if (false !== $pre) { |
|
| 1863 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1864 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1865 | - } |
|
| 1866 | - $row = $wpdb->get_row( |
|
| 1867 | - $wpdb->prepare( |
|
| 1868 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1869 | - $option |
|
| 1870 | - ) |
|
| 1871 | - ); |
|
| 1872 | - if (is_object($row)) { |
|
| 1873 | - $value = $row->option_value; |
|
| 1874 | - } else { // option does not exist so use default. |
|
| 1875 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1876 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1877 | - } |
|
| 1878 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1879 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * Utility function for escaping the value of a property and returning. |
|
| 1885 | - * |
|
| 1886 | - * @param string $property property name (checks to see if exists). |
|
| 1887 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1888 | - * @throws \EE_Error |
|
| 1889 | - */ |
|
| 1890 | - public function get_pretty($property) |
|
| 1891 | - { |
|
| 1892 | - if ($property === self::OPTION_NAME_UXIP) { |
|
| 1893 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1894 | - } |
|
| 1895 | - return parent::get_pretty($property); |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - |
|
| 1899 | - /** |
|
| 1900 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1901 | - * on the object. |
|
| 1902 | - * |
|
| 1903 | - * @return array |
|
| 1904 | - */ |
|
| 1905 | - public function __sleep() |
|
| 1906 | - { |
|
| 1907 | - // reset all url properties |
|
| 1908 | - $this->_reset_urls(); |
|
| 1909 | - // return what to save to db |
|
| 1910 | - return array_keys(get_object_vars($this)); |
|
| 1911 | - } |
|
| 17 | + const OPTION_NAME = 'ee_config'; |
|
| 18 | + |
|
| 19 | + const LOG_NAME = 'ee_config_log'; |
|
| 20 | + |
|
| 21 | + const LOG_LENGTH = 100; |
|
| 22 | + |
|
| 23 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * instance of the EE_Config object |
|
| 27 | + * |
|
| 28 | + * @var EE_Config $_instance |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var boolean $_logging_enabled |
|
| 35 | + */ |
|
| 36 | + private static $_logging_enabled = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | + */ |
|
| 41 | + private $legacy_shortcodes_manager; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * An StdClass whose property names are addon slugs, |
|
| 45 | + * and values are their config classes |
|
| 46 | + * |
|
| 47 | + * @var StdClass |
|
| 48 | + */ |
|
| 49 | + public $addons; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Admin_Config |
|
| 53 | + */ |
|
| 54 | + public $admin; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Core_Config |
|
| 58 | + */ |
|
| 59 | + public $core; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var EE_Currency_Config |
|
| 63 | + */ |
|
| 64 | + public $currency; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var EE_Organization_Config |
|
| 68 | + */ |
|
| 69 | + public $organization; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_Registration_Config |
|
| 73 | + */ |
|
| 74 | + public $registration; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_Template_Config |
|
| 78 | + */ |
|
| 79 | + public $template_settings; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Holds EE environment values. |
|
| 83 | + * |
|
| 84 | + * @var EE_Environment_Config |
|
| 85 | + */ |
|
| 86 | + public $environment; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * settings pertaining to Google maps |
|
| 90 | + * |
|
| 91 | + * @var EE_Map_Config |
|
| 92 | + */ |
|
| 93 | + public $map_settings; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * settings pertaining to Taxes |
|
| 97 | + * |
|
| 98 | + * @var EE_Tax_Config |
|
| 99 | + */ |
|
| 100 | + public $tax_settings; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Settings pertaining to global messages settings. |
|
| 104 | + * |
|
| 105 | + * @var EE_Messages_Config |
|
| 106 | + */ |
|
| 107 | + public $messages; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated |
|
| 111 | + * @var EE_Gateway_Config |
|
| 112 | + */ |
|
| 113 | + public $gateway; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var array $_addon_option_names |
|
| 117 | + * @access private |
|
| 118 | + */ |
|
| 119 | + private $_addon_option_names = array(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var array $_module_route_map |
|
| 123 | + * @access private |
|
| 124 | + */ |
|
| 125 | + private static $_module_route_map = array(); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var array $_module_forward_map |
|
| 129 | + * @access private |
|
| 130 | + */ |
|
| 131 | + private static $_module_forward_map = array(); |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @var array $_module_view_map |
|
| 135 | + * @access private |
|
| 136 | + */ |
|
| 137 | + private static $_module_view_map = array(); |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @singleton method used to instantiate class object |
|
| 142 | + * @access public |
|
| 143 | + * @return EE_Config instance |
|
| 144 | + */ |
|
| 145 | + public static function instance() |
|
| 146 | + { |
|
| 147 | + // check if class object is instantiated, and instantiated properly |
|
| 148 | + if (! self::$_instance instanceof EE_Config) { |
|
| 149 | + self::$_instance = new self(); |
|
| 150 | + } |
|
| 151 | + return self::$_instance; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Resets the config |
|
| 157 | + * |
|
| 158 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | + * reflect its state in the database |
|
| 161 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | + * site was put into maintenance mode) |
|
| 165 | + * @return EE_Config |
|
| 166 | + */ |
|
| 167 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | + { |
|
| 169 | + if (self::$_instance instanceof EE_Config) { |
|
| 170 | + if ($hard_reset) { |
|
| 171 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | + self::$_instance->_addon_option_names = array(); |
|
| 173 | + self::$_instance->_initialize_config(); |
|
| 174 | + self::$_instance->update_espresso_config(); |
|
| 175 | + } |
|
| 176 | + self::$_instance->update_addon_option_names(); |
|
| 177 | + } |
|
| 178 | + self::$_instance = null; |
|
| 179 | + // we don't need to reset the static properties imo because those should |
|
| 180 | + // only change when a module is added or removed. Currently we don't |
|
| 181 | + // support removing a module during a request when it previously existed |
|
| 182 | + if ($reinstantiate) { |
|
| 183 | + return self::instance(); |
|
| 184 | + } else { |
|
| 185 | + return null; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * class constructor |
|
| 192 | + * |
|
| 193 | + * @access private |
|
| 194 | + */ |
|
| 195 | + private function __construct() |
|
| 196 | + { |
|
| 197 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | + // setup empty config classes |
|
| 200 | + $this->_initialize_config(); |
|
| 201 | + // load existing EE site settings |
|
| 202 | + $this->_load_core_config(); |
|
| 203 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | + $this->_verify_config(); |
|
| 205 | + // register shortcodes and modules |
|
| 206 | + add_action( |
|
| 207 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | + array($this, 'register_shortcodes_and_modules'), |
|
| 209 | + 999 |
|
| 210 | + ); |
|
| 211 | + // initialize shortcodes and modules |
|
| 212 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | + // register widgets |
|
| 214 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | + // shutdown |
|
| 216 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | + // construct__end hook |
|
| 218 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | + // hardcoded hack |
|
| 220 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @return boolean |
|
| 226 | + */ |
|
| 227 | + public static function logging_enabled() |
|
| 228 | + { |
|
| 229 | + return self::$_logging_enabled; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * use to get the current theme if needed from static context |
|
| 235 | + * |
|
| 236 | + * @return string current theme set. |
|
| 237 | + */ |
|
| 238 | + public static function get_current_theme() |
|
| 239 | + { |
|
| 240 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * _initialize_config |
|
| 247 | + * |
|
| 248 | + * @access private |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + private function _initialize_config() |
|
| 252 | + { |
|
| 253 | + EE_Config::trim_log(); |
|
| 254 | + // set defaults |
|
| 255 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | + $this->addons = new stdClass(); |
|
| 257 | + // set _module_route_map |
|
| 258 | + EE_Config::$_module_route_map = array(); |
|
| 259 | + // set _module_forward_map |
|
| 260 | + EE_Config::$_module_forward_map = array(); |
|
| 261 | + // set _module_view_map |
|
| 262 | + EE_Config::$_module_view_map = array(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * load core plugin configuration |
|
| 268 | + * |
|
| 269 | + * @access private |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + private function _load_core_config() |
|
| 273 | + { |
|
| 274 | + // load_core_config__start hook |
|
| 275 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | + $espresso_config = $this->get_espresso_config(); |
|
| 277 | + foreach ($espresso_config as $config => $settings) { |
|
| 278 | + // load_core_config__start hook |
|
| 279 | + $settings = apply_filters( |
|
| 280 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | + $settings, |
|
| 282 | + $config, |
|
| 283 | + $this |
|
| 284 | + ); |
|
| 285 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | + // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | + if (method_exists($settings, 'populate')) { |
|
| 289 | + $this->{$config}->populate(); |
|
| 290 | + } |
|
| 291 | + if (method_exists($settings, 'do_hooks')) { |
|
| 292 | + $this->{$config}->do_hooks(); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | + $this->update_espresso_config(); |
|
| 298 | + } |
|
| 299 | + // load_core_config__end hook |
|
| 300 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * _verify_config |
|
| 306 | + * |
|
| 307 | + * @access protected |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + protected function _verify_config() |
|
| 311 | + { |
|
| 312 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | + ? $this->core |
|
| 314 | + : new EE_Core_Config(); |
|
| 315 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | + ? $this->organization |
|
| 318 | + : new EE_Organization_Config(); |
|
| 319 | + $this->organization = apply_filters( |
|
| 320 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | + $this->organization |
|
| 322 | + ); |
|
| 323 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | + ? $this->currency |
|
| 325 | + : new EE_Currency_Config(); |
|
| 326 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | + ? $this->registration |
|
| 329 | + : new EE_Registration_Config(); |
|
| 330 | + $this->registration = apply_filters( |
|
| 331 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | + $this->registration |
|
| 333 | + ); |
|
| 334 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | + ? $this->admin |
|
| 336 | + : new EE_Admin_Config(); |
|
| 337 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | + ? $this->template_settings |
|
| 340 | + : new EE_Template_Config(); |
|
| 341 | + $this->template_settings = apply_filters( |
|
| 342 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | + $this->template_settings |
|
| 344 | + ); |
|
| 345 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | + ? $this->map_settings |
|
| 347 | + : new EE_Map_Config(); |
|
| 348 | + $this->map_settings = apply_filters( |
|
| 349 | + 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | + $this->map_settings |
|
| 351 | + ); |
|
| 352 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | + ? $this->environment |
|
| 354 | + : new EE_Environment_Config(); |
|
| 355 | + $this->environment = apply_filters( |
|
| 356 | + 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | + $this->environment |
|
| 358 | + ); |
|
| 359 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | + ? $this->tax_settings |
|
| 361 | + : new EE_Tax_Config(); |
|
| 362 | + $this->tax_settings = apply_filters( |
|
| 363 | + 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | + $this->tax_settings |
|
| 365 | + ); |
|
| 366 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | + ? $this->messages |
|
| 369 | + : new EE_Messages_Config(); |
|
| 370 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | + ? $this->gateway |
|
| 372 | + : new EE_Gateway_Config(); |
|
| 373 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | + $this->legacy_shortcodes_manager = null; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * get_espresso_config |
|
| 380 | + * |
|
| 381 | + * @access public |
|
| 382 | + * @return array of espresso config stuff |
|
| 383 | + */ |
|
| 384 | + public function get_espresso_config() |
|
| 385 | + { |
|
| 386 | + // grab espresso configuration |
|
| 387 | + return apply_filters( |
|
| 388 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * double_check_config_comparison |
|
| 396 | + * |
|
| 397 | + * @access public |
|
| 398 | + * @param string $option |
|
| 399 | + * @param $old_value |
|
| 400 | + * @param $value |
|
| 401 | + */ |
|
| 402 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | + { |
|
| 404 | + // make sure we're checking the ee config |
|
| 405 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | + if ($value != $old_value) { |
|
| 409 | + // if they are NOT the same, then remove the hook, |
|
| 410 | + // which means the subsequent update results will be based solely on the update query results |
|
| 411 | + // the reason we do this is because, as stated above, |
|
| 412 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | + // If values are found to match their previous old value, |
|
| 415 | + // then WP bails before performing any update. |
|
| 416 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | + // MySQL MAY ALSO NOT perform the update because |
|
| 420 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * update_espresso_config |
|
| 431 | + * |
|
| 432 | + * @access public |
|
| 433 | + */ |
|
| 434 | + protected function _reset_espresso_addon_config() |
|
| 435 | + { |
|
| 436 | + $this->_addon_option_names = array(); |
|
| 437 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | + } |
|
| 442 | + $this->addons->{$addon_name} = null; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * update_espresso_config |
|
| 449 | + * |
|
| 450 | + * @access public |
|
| 451 | + * @param bool $add_success |
|
| 452 | + * @param bool $add_error |
|
| 453 | + * @return bool |
|
| 454 | + */ |
|
| 455 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | + { |
|
| 457 | + // don't allow config updates during WP heartbeats |
|
| 458 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | + // $clone = clone( self::$_instance ); |
|
| 463 | + // self::$_instance = NULL; |
|
| 464 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | + $this->_reset_espresso_addon_config(); |
|
| 466 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | + // but BEFORE the actual update occurs |
|
| 468 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | + $this->legacy_shortcodes_manager = null; |
|
| 472 | + // now update "ee_config" |
|
| 473 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | + // if not saved... check if the hook we just added still exists; |
|
| 477 | + // if it does, it means one of two things: |
|
| 478 | + // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | + // or... |
|
| 480 | + // the db update query returned 0 rows affected |
|
| 481 | + // (probably because the data value was the same from it's perspective) |
|
| 482 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | + // but just means no update occurred, so don't display an error to the user. |
|
| 484 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | + // then it means that something truly went wrong |
|
| 486 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | + // remove our action since we don't want it in the system anymore |
|
| 488 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | + // self::$_instance = $clone; |
|
| 491 | + // unset( $clone ); |
|
| 492 | + // if config remains the same or was updated successfully |
|
| 493 | + if ($saved) { |
|
| 494 | + if ($add_success) { |
|
| 495 | + EE_Error::add_success( |
|
| 496 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | + __FILE__, |
|
| 498 | + __FUNCTION__, |
|
| 499 | + __LINE__ |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + return true; |
|
| 503 | + } else { |
|
| 504 | + if ($add_error) { |
|
| 505 | + EE_Error::add_error( |
|
| 506 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | + __FILE__, |
|
| 508 | + __FUNCTION__, |
|
| 509 | + __LINE__ |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * _verify_config_params |
|
| 519 | + * |
|
| 520 | + * @access private |
|
| 521 | + * @param string $section |
|
| 522 | + * @param string $name |
|
| 523 | + * @param string $config_class |
|
| 524 | + * @param EE_Config_Base $config_obj |
|
| 525 | + * @param array $tests_to_run |
|
| 526 | + * @param bool $display_errors |
|
| 527 | + * @return bool TRUE on success, FALSE on fail |
|
| 528 | + */ |
|
| 529 | + private function _verify_config_params( |
|
| 530 | + $section = '', |
|
| 531 | + $name = '', |
|
| 532 | + $config_class = '', |
|
| 533 | + $config_obj = null, |
|
| 534 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | + $display_errors = true |
|
| 536 | + ) { |
|
| 537 | + try { |
|
| 538 | + foreach ($tests_to_run as $test) { |
|
| 539 | + switch ($test) { |
|
| 540 | + // TEST #1 : check that section was set |
|
| 541 | + case 1: |
|
| 542 | + if (empty($section)) { |
|
| 543 | + if ($display_errors) { |
|
| 544 | + throw new EE_Error( |
|
| 545 | + sprintf( |
|
| 546 | + __( |
|
| 547 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ), |
|
| 550 | + $config_class |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + return false; |
|
| 555 | + } |
|
| 556 | + break; |
|
| 557 | + // TEST #2 : check that settings section exists |
|
| 558 | + case 2: |
|
| 559 | + if (! isset($this->{$section})) { |
|
| 560 | + if ($display_errors) { |
|
| 561 | + throw new EE_Error( |
|
| 562 | + sprintf( |
|
| 563 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | + $section |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + break; |
|
| 571 | + // TEST #3 : check that section is the proper format |
|
| 572 | + case 3: |
|
| 573 | + if ( |
|
| 574 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 575 | + ) { |
|
| 576 | + if ($display_errors) { |
|
| 577 | + throw new EE_Error( |
|
| 578 | + sprintf( |
|
| 579 | + __( |
|
| 580 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 581 | + 'event_espresso' |
|
| 582 | + ), |
|
| 583 | + $section |
|
| 584 | + ) |
|
| 585 | + ); |
|
| 586 | + } |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | + break; |
|
| 590 | + // TEST #4 : check that config section name has been set |
|
| 591 | + case 4: |
|
| 592 | + if (empty($name)) { |
|
| 593 | + if ($display_errors) { |
|
| 594 | + throw new EE_Error( |
|
| 595 | + __( |
|
| 596 | + 'No name has been provided for the specific configuration section.', |
|
| 597 | + 'event_espresso' |
|
| 598 | + ) |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + return false; |
|
| 602 | + } |
|
| 603 | + break; |
|
| 604 | + // TEST #5 : check that a config class name has been set |
|
| 605 | + case 5: |
|
| 606 | + if (empty($config_class)) { |
|
| 607 | + if ($display_errors) { |
|
| 608 | + throw new EE_Error( |
|
| 609 | + __( |
|
| 610 | + 'No class name has been provided for the specific configuration section.', |
|
| 611 | + 'event_espresso' |
|
| 612 | + ) |
|
| 613 | + ); |
|
| 614 | + } |
|
| 615 | + return false; |
|
| 616 | + } |
|
| 617 | + break; |
|
| 618 | + // TEST #6 : verify config class is accessible |
|
| 619 | + case 6: |
|
| 620 | + if (! class_exists($config_class)) { |
|
| 621 | + if ($display_errors) { |
|
| 622 | + throw new EE_Error( |
|
| 623 | + sprintf( |
|
| 624 | + __( |
|
| 625 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 626 | + 'event_espresso' |
|
| 627 | + ), |
|
| 628 | + $config_class |
|
| 629 | + ) |
|
| 630 | + ); |
|
| 631 | + } |
|
| 632 | + return false; |
|
| 633 | + } |
|
| 634 | + break; |
|
| 635 | + // TEST #7 : check that config has even been set |
|
| 636 | + case 7: |
|
| 637 | + if (! isset($this->{$section}->{$name})) { |
|
| 638 | + if ($display_errors) { |
|
| 639 | + throw new EE_Error( |
|
| 640 | + sprintf( |
|
| 641 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 642 | + $section, |
|
| 643 | + $name |
|
| 644 | + ) |
|
| 645 | + ); |
|
| 646 | + } |
|
| 647 | + return false; |
|
| 648 | + } else { |
|
| 649 | + // and make sure it's not serialized |
|
| 650 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 651 | + } |
|
| 652 | + break; |
|
| 653 | + // TEST #8 : check that config is the requested type |
|
| 654 | + case 8: |
|
| 655 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 656 | + if ($display_errors) { |
|
| 657 | + throw new EE_Error( |
|
| 658 | + sprintf( |
|
| 659 | + __( |
|
| 660 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 661 | + 'event_espresso' |
|
| 662 | + ), |
|
| 663 | + $section, |
|
| 664 | + $name, |
|
| 665 | + $config_class |
|
| 666 | + ) |
|
| 667 | + ); |
|
| 668 | + } |
|
| 669 | + return false; |
|
| 670 | + } |
|
| 671 | + break; |
|
| 672 | + // TEST #9 : verify config object |
|
| 673 | + case 9: |
|
| 674 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 675 | + if ($display_errors) { |
|
| 676 | + throw new EE_Error( |
|
| 677 | + sprintf( |
|
| 678 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 679 | + print_r($config_obj, true) |
|
| 680 | + ) |
|
| 681 | + ); |
|
| 682 | + } |
|
| 683 | + return false; |
|
| 684 | + } |
|
| 685 | + break; |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + } catch (EE_Error $e) { |
|
| 689 | + $e->get_error(); |
|
| 690 | + } |
|
| 691 | + // you have successfully run the gauntlet |
|
| 692 | + return true; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * _generate_config_option_name |
|
| 698 | + * |
|
| 699 | + * @access protected |
|
| 700 | + * @param string $section |
|
| 701 | + * @param string $name |
|
| 702 | + * @return string |
|
| 703 | + */ |
|
| 704 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 705 | + { |
|
| 706 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * _set_config_class |
|
| 712 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 713 | + * |
|
| 714 | + * @access private |
|
| 715 | + * @param string $config_class |
|
| 716 | + * @param string $name |
|
| 717 | + * @return string |
|
| 718 | + */ |
|
| 719 | + private function _set_config_class($config_class = '', $name = '') |
|
| 720 | + { |
|
| 721 | + return ! empty($config_class) |
|
| 722 | + ? $config_class |
|
| 723 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * set_config |
|
| 729 | + * |
|
| 730 | + * @access protected |
|
| 731 | + * @param string $section |
|
| 732 | + * @param string $name |
|
| 733 | + * @param string $config_class |
|
| 734 | + * @param EE_Config_Base $config_obj |
|
| 735 | + * @return EE_Config_Base |
|
| 736 | + */ |
|
| 737 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 738 | + { |
|
| 739 | + // ensure config class is set to something |
|
| 740 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 741 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 742 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 743 | + return null; |
|
| 744 | + } |
|
| 745 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 746 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 747 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 748 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 749 | + $this->update_addon_option_names(); |
|
| 750 | + } |
|
| 751 | + // verify the incoming config object but suppress errors |
|
| 752 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 753 | + $config_obj = new $config_class(); |
|
| 754 | + } |
|
| 755 | + if (get_option($config_option_name)) { |
|
| 756 | + EE_Config::log($config_option_name); |
|
| 757 | + update_option($config_option_name, $config_obj); |
|
| 758 | + $this->{$section}->{$name} = $config_obj; |
|
| 759 | + return $this->{$section}->{$name}; |
|
| 760 | + } else { |
|
| 761 | + // create a wp-option for this config |
|
| 762 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 763 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 764 | + return $this->{$section}->{$name}; |
|
| 765 | + } else { |
|
| 766 | + EE_Error::add_error( |
|
| 767 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 768 | + __FILE__, |
|
| 769 | + __FUNCTION__, |
|
| 770 | + __LINE__ |
|
| 771 | + ); |
|
| 772 | + return null; |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * update_config |
|
| 780 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 781 | + * |
|
| 782 | + * @access public |
|
| 783 | + * @param string $section |
|
| 784 | + * @param string $name |
|
| 785 | + * @param EE_Config_Base|string $config_obj |
|
| 786 | + * @param bool $throw_errors |
|
| 787 | + * @return bool |
|
| 788 | + */ |
|
| 789 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 790 | + { |
|
| 791 | + // don't allow config updates during WP heartbeats |
|
| 792 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 793 | + return false; |
|
| 794 | + } |
|
| 795 | + $config_obj = maybe_unserialize($config_obj); |
|
| 796 | + // get class name of the incoming object |
|
| 797 | + $config_class = get_class($config_obj); |
|
| 798 | + // run tests 1-5 and 9 to verify config |
|
| 799 | + if ( |
|
| 800 | + ! $this->_verify_config_params( |
|
| 801 | + $section, |
|
| 802 | + $name, |
|
| 803 | + $config_class, |
|
| 804 | + $config_obj, |
|
| 805 | + array(1, 2, 3, 4, 7, 9) |
|
| 806 | + ) |
|
| 807 | + ) { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 811 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 812 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 813 | + // save new config to db |
|
| 814 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 815 | + return true; |
|
| 816 | + } |
|
| 817 | + } else { |
|
| 818 | + // first check if the record already exists |
|
| 819 | + $existing_config = get_option($config_option_name); |
|
| 820 | + $config_obj = serialize($config_obj); |
|
| 821 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 822 | + if ($existing_config == $config_obj) { |
|
| 823 | + $this->{$section}->{$name} = $config_obj; |
|
| 824 | + return true; |
|
| 825 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
| 826 | + EE_Config::log($config_option_name); |
|
| 827 | + // update wp-option for this config class |
|
| 828 | + $this->{$section}->{$name} = $config_obj; |
|
| 829 | + return true; |
|
| 830 | + } elseif ($throw_errors) { |
|
| 831 | + EE_Error::add_error( |
|
| 832 | + sprintf( |
|
| 833 | + __( |
|
| 834 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 835 | + 'event_espresso' |
|
| 836 | + ), |
|
| 837 | + $config_class, |
|
| 838 | + 'EE_Config->' . $section . '->' . $name |
|
| 839 | + ), |
|
| 840 | + __FILE__, |
|
| 841 | + __FUNCTION__, |
|
| 842 | + __LINE__ |
|
| 843 | + ); |
|
| 844 | + } |
|
| 845 | + } |
|
| 846 | + return false; |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * get_config |
|
| 852 | + * |
|
| 853 | + * @access public |
|
| 854 | + * @param string $section |
|
| 855 | + * @param string $name |
|
| 856 | + * @param string $config_class |
|
| 857 | + * @return mixed EE_Config_Base | NULL |
|
| 858 | + */ |
|
| 859 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 860 | + { |
|
| 861 | + // ensure config class is set to something |
|
| 862 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 863 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 864 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 865 | + return null; |
|
| 866 | + } |
|
| 867 | + // now test if the requested config object exists, but suppress errors |
|
| 868 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 869 | + // config already exists, so pass it back |
|
| 870 | + return $this->{$section}->{$name}; |
|
| 871 | + } |
|
| 872 | + // load config option from db if it exists |
|
| 873 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 874 | + // verify the newly retrieved config object, but suppress errors |
|
| 875 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 876 | + // config is good, so set it and pass it back |
|
| 877 | + $this->{$section}->{$name} = $config_obj; |
|
| 878 | + return $this->{$section}->{$name}; |
|
| 879 | + } |
|
| 880 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 881 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 882 | + // verify the newly created config object |
|
| 883 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 884 | + return $this->{$section}->{$name}; |
|
| 885 | + } else { |
|
| 886 | + EE_Error::add_error( |
|
| 887 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 888 | + __FILE__, |
|
| 889 | + __FUNCTION__, |
|
| 890 | + __LINE__ |
|
| 891 | + ); |
|
| 892 | + } |
|
| 893 | + return null; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * get_config_option |
|
| 899 | + * |
|
| 900 | + * @access public |
|
| 901 | + * @param string $config_option_name |
|
| 902 | + * @return mixed EE_Config_Base | FALSE |
|
| 903 | + */ |
|
| 904 | + public function get_config_option($config_option_name = '') |
|
| 905 | + { |
|
| 906 | + // retrieve the wp-option for this config class. |
|
| 907 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 908 | + if (empty($config_option)) { |
|
| 909 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 910 | + } |
|
| 911 | + return $config_option; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + /** |
|
| 916 | + * log |
|
| 917 | + * |
|
| 918 | + * @param string $config_option_name |
|
| 919 | + */ |
|
| 920 | + public static function log($config_option_name = '') |
|
| 921 | + { |
|
| 922 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 923 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 924 | + // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 925 | + $_request = $_REQUEST; |
|
| 926 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 927 | + $config_log[ (string) microtime(true) ] = array( |
|
| 928 | + 'config_name' => $config_option_name, |
|
| 929 | + 'request' => $_request, |
|
| 930 | + ); |
|
| 931 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + /** |
|
| 937 | + * trim_log |
|
| 938 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 939 | + */ |
|
| 940 | + public static function trim_log() |
|
| 941 | + { |
|
| 942 | + if (! EE_Config::logging_enabled()) { |
|
| 943 | + return; |
|
| 944 | + } |
|
| 945 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 946 | + $log_length = count($config_log); |
|
| 947 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 948 | + ksort($config_log); |
|
| 949 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 950 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 951 | + } |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * get_page_for_posts |
|
| 957 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 958 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 959 | + * |
|
| 960 | + * @access public |
|
| 961 | + * @return string |
|
| 962 | + */ |
|
| 963 | + public static function get_page_for_posts() |
|
| 964 | + { |
|
| 965 | + $page_for_posts = get_option('page_for_posts'); |
|
| 966 | + if (! $page_for_posts) { |
|
| 967 | + return 'posts'; |
|
| 968 | + } |
|
| 969 | + /** @type WPDB $wpdb */ |
|
| 970 | + global $wpdb; |
|
| 971 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 972 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + |
|
| 976 | + /** |
|
| 977 | + * register_shortcodes_and_modules. |
|
| 978 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 979 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 980 | + * so they can help trigger maintenance mode if it's needed |
|
| 981 | + * |
|
| 982 | + * @access public |
|
| 983 | + * @return void |
|
| 984 | + */ |
|
| 985 | + public function register_shortcodes_and_modules() |
|
| 986 | + { |
|
| 987 | + // allow modules to set hooks for the rest of the system |
|
| 988 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + /** |
|
| 993 | + * initialize_shortcodes_and_modules |
|
| 994 | + * meaning they can start adding their hooks to get stuff done |
|
| 995 | + * |
|
| 996 | + * @access public |
|
| 997 | + * @return void |
|
| 998 | + */ |
|
| 999 | + public function initialize_shortcodes_and_modules() |
|
| 1000 | + { |
|
| 1001 | + // allow modules to set hooks for the rest of the system |
|
| 1002 | + $this->_initialize_modules(); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * widgets_init |
|
| 1008 | + * |
|
| 1009 | + * @access private |
|
| 1010 | + * @return void |
|
| 1011 | + */ |
|
| 1012 | + public function widgets_init() |
|
| 1013 | + { |
|
| 1014 | + // only init widgets on admin pages when not in complete maintenance, and |
|
| 1015 | + // on frontend when not in any maintenance mode |
|
| 1016 | + if ( |
|
| 1017 | + ! EE_Maintenance_Mode::instance()->level() |
|
| 1018 | + || ( |
|
| 1019 | + is_admin() |
|
| 1020 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1021 | + ) |
|
| 1022 | + ) { |
|
| 1023 | + // grab list of installed widgets |
|
| 1024 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1025 | + // filter list of modules to register |
|
| 1026 | + $widgets_to_register = apply_filters( |
|
| 1027 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1028 | + $widgets_to_register |
|
| 1029 | + ); |
|
| 1030 | + if (! empty($widgets_to_register)) { |
|
| 1031 | + // cycle thru widget folders |
|
| 1032 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1033 | + // add to list of installed widget modules |
|
| 1034 | + EE_Config::register_ee_widget($widget_path); |
|
| 1035 | + } |
|
| 1036 | + } |
|
| 1037 | + // filter list of installed modules |
|
| 1038 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1039 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1040 | + EE_Registry::instance()->widgets |
|
| 1041 | + ); |
|
| 1042 | + } |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * register_ee_widget - makes core aware of this widget |
|
| 1048 | + * |
|
| 1049 | + * @access public |
|
| 1050 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1051 | + * @return void |
|
| 1052 | + */ |
|
| 1053 | + public static function register_ee_widget($widget_path = null) |
|
| 1054 | + { |
|
| 1055 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1056 | + $widget_ext = '.widget.php'; |
|
| 1057 | + // make all separators match |
|
| 1058 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1059 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1060 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1061 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1062 | + $file_name = explode('.', basename($widget_path)); |
|
| 1063 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1064 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1065 | + // sanitize shortcode directory name |
|
| 1066 | + $widget = sanitize_key($widget); |
|
| 1067 | + // now we need to rebuild the shortcode path |
|
| 1068 | + $widget_path = explode('/', $widget_path); |
|
| 1069 | + // remove last segment |
|
| 1070 | + array_pop($widget_path); |
|
| 1071 | + // glue it back together |
|
| 1072 | + $widget_path = implode(DS, $widget_path); |
|
| 1073 | + } else { |
|
| 1074 | + // grab and sanitize widget directory name |
|
| 1075 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1076 | + } |
|
| 1077 | + // create classname from widget directory name |
|
| 1078 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1079 | + // add class prefix |
|
| 1080 | + $widget_class = 'EEW_' . $widget; |
|
| 1081 | + // does the widget exist ? |
|
| 1082 | + if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1083 | + $msg = sprintf( |
|
| 1084 | + __( |
|
| 1085 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1086 | + 'event_espresso' |
|
| 1087 | + ), |
|
| 1088 | + $widget_class, |
|
| 1089 | + $widget_path . '/' . $widget_class . $widget_ext |
|
| 1090 | + ); |
|
| 1091 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1092 | + return; |
|
| 1093 | + } |
|
| 1094 | + // load the widget class file |
|
| 1095 | + require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1096 | + // verify that class exists |
|
| 1097 | + if (! class_exists($widget_class)) { |
|
| 1098 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1099 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1100 | + return; |
|
| 1101 | + } |
|
| 1102 | + register_widget($widget_class); |
|
| 1103 | + // add to array of registered widgets |
|
| 1104 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * _register_modules |
|
| 1110 | + * |
|
| 1111 | + * @access private |
|
| 1112 | + * @return array |
|
| 1113 | + */ |
|
| 1114 | + private function _register_modules() |
|
| 1115 | + { |
|
| 1116 | + // grab list of installed modules |
|
| 1117 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1118 | + // filter list of modules to register |
|
| 1119 | + $modules_to_register = apply_filters( |
|
| 1120 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1121 | + $modules_to_register |
|
| 1122 | + ); |
|
| 1123 | + if (! empty($modules_to_register)) { |
|
| 1124 | + // loop through folders |
|
| 1125 | + foreach ($modules_to_register as $module_path) { |
|
| 1126 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1127 | + if ( |
|
| 1128 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1129 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1130 | + ) { |
|
| 1131 | + // add to list of installed modules |
|
| 1132 | + EE_Config::register_module($module_path); |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | + // filter list of installed modules |
|
| 1137 | + return apply_filters( |
|
| 1138 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1139 | + EE_Registry::instance()->modules |
|
| 1140 | + ); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * register_module - makes core aware of this module |
|
| 1146 | + * |
|
| 1147 | + * @access public |
|
| 1148 | + * @param string $module_path - full path up to and including module folder |
|
| 1149 | + * @return bool |
|
| 1150 | + */ |
|
| 1151 | + public static function register_module($module_path = null) |
|
| 1152 | + { |
|
| 1153 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1154 | + $module_ext = '.module.php'; |
|
| 1155 | + // make all separators match |
|
| 1156 | + $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1157 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1158 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1159 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1160 | + $module_file = explode('.', basename($module_path)); |
|
| 1161 | + // now we need to rebuild the shortcode path |
|
| 1162 | + $module_path = explode('/', $module_path); |
|
| 1163 | + // remove last segment |
|
| 1164 | + array_pop($module_path); |
|
| 1165 | + // glue it back together |
|
| 1166 | + $module_path = implode('/', $module_path) . '/'; |
|
| 1167 | + // take first segment from file name pieces and sanitize it |
|
| 1168 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1169 | + // ensure class prefix is added |
|
| 1170 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1171 | + } else { |
|
| 1172 | + // we need to generate the filename based off of the folder name |
|
| 1173 | + // grab and sanitize module name |
|
| 1174 | + $module = strtolower(basename($module_path)); |
|
| 1175 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1176 | + // like trailingslashit() |
|
| 1177 | + $module_path = rtrim($module_path, '/') . '/'; |
|
| 1178 | + // create classname from module directory name |
|
| 1179 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1180 | + // add class prefix |
|
| 1181 | + $module_class = 'EED_' . $module; |
|
| 1182 | + } |
|
| 1183 | + // does the module exist ? |
|
| 1184 | + if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1185 | + $msg = sprintf( |
|
| 1186 | + __( |
|
| 1187 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1188 | + 'event_espresso' |
|
| 1189 | + ), |
|
| 1190 | + $module |
|
| 1191 | + ); |
|
| 1192 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1193 | + return false; |
|
| 1194 | + } |
|
| 1195 | + // load the module class file |
|
| 1196 | + require_once($module_path . $module_class . $module_ext); |
|
| 1197 | + // verify that class exists |
|
| 1198 | + if (! class_exists($module_class)) { |
|
| 1199 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1200 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1201 | + return false; |
|
| 1202 | + } |
|
| 1203 | + // add to array of registered modules |
|
| 1204 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1205 | + do_action( |
|
| 1206 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1207 | + $module_class, |
|
| 1208 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1209 | + ); |
|
| 1210 | + return true; |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + |
|
| 1214 | + /** |
|
| 1215 | + * _initialize_modules |
|
| 1216 | + * allow modules to set hooks for the rest of the system |
|
| 1217 | + * |
|
| 1218 | + * @access private |
|
| 1219 | + * @return void |
|
| 1220 | + */ |
|
| 1221 | + private function _initialize_modules() |
|
| 1222 | + { |
|
| 1223 | + // cycle thru shortcode folders |
|
| 1224 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1225 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1226 | + // which set hooks ? |
|
| 1227 | + if (is_admin()) { |
|
| 1228 | + // fire immediately |
|
| 1229 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1230 | + } else { |
|
| 1231 | + // delay until other systems are online |
|
| 1232 | + add_action( |
|
| 1233 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1234 | + array($module_class, 'set_hooks') |
|
| 1235 | + ); |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + |
|
| 1241 | + /** |
|
| 1242 | + * register_route - adds module method routes to route_map |
|
| 1243 | + * |
|
| 1244 | + * @access public |
|
| 1245 | + * @param string $route - "pretty" public alias for module method |
|
| 1246 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1247 | + * @param string $method_name - the actual module method to be routed to |
|
| 1248 | + * @param string $key - url param key indicating a route is being called |
|
| 1249 | + * @return bool |
|
| 1250 | + */ |
|
| 1251 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1252 | + { |
|
| 1253 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1254 | + $module = str_replace('EED_', '', $module); |
|
| 1255 | + $module_class = 'EED_' . $module; |
|
| 1256 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1257 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1258 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1259 | + return false; |
|
| 1260 | + } |
|
| 1261 | + if (empty($route)) { |
|
| 1262 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1263 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1264 | + return false; |
|
| 1265 | + } |
|
| 1266 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1267 | + $msg = sprintf( |
|
| 1268 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1269 | + $route |
|
| 1270 | + ); |
|
| 1271 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1272 | + return false; |
|
| 1273 | + } |
|
| 1274 | + EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1275 | + return true; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * get_route - get module method route |
|
| 1281 | + * |
|
| 1282 | + * @access public |
|
| 1283 | + * @param string $route - "pretty" public alias for module method |
|
| 1284 | + * @param string $key - url param key indicating a route is being called |
|
| 1285 | + * @return string |
|
| 1286 | + */ |
|
| 1287 | + public static function get_route($route = null, $key = 'ee') |
|
| 1288 | + { |
|
| 1289 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1290 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1291 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1292 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1293 | + } |
|
| 1294 | + return null; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * get_routes - get ALL module method routes |
|
| 1300 | + * |
|
| 1301 | + * @access public |
|
| 1302 | + * @return array |
|
| 1303 | + */ |
|
| 1304 | + public static function get_routes() |
|
| 1305 | + { |
|
| 1306 | + return EE_Config::$_module_route_map; |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1312 | + * |
|
| 1313 | + * @access public |
|
| 1314 | + * @param string $route - "pretty" public alias for module method |
|
| 1315 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1316 | + * class, allows different forwards to be served based on status |
|
| 1317 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1318 | + * @param string $key - url param key indicating a route is being called |
|
| 1319 | + * @return bool |
|
| 1320 | + */ |
|
| 1321 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1322 | + { |
|
| 1323 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1324 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1325 | + $msg = sprintf( |
|
| 1326 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1327 | + $route |
|
| 1328 | + ); |
|
| 1329 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1330 | + return false; |
|
| 1331 | + } |
|
| 1332 | + if (empty($forward)) { |
|
| 1333 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1334 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1335 | + return false; |
|
| 1336 | + } |
|
| 1337 | + if (is_array($forward)) { |
|
| 1338 | + if (! isset($forward[1])) { |
|
| 1339 | + $msg = sprintf( |
|
| 1340 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1341 | + $route |
|
| 1342 | + ); |
|
| 1343 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1344 | + return false; |
|
| 1345 | + } |
|
| 1346 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1347 | + $msg = sprintf( |
|
| 1348 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1349 | + $forward[1], |
|
| 1350 | + $route |
|
| 1351 | + ); |
|
| 1352 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1353 | + return false; |
|
| 1354 | + } |
|
| 1355 | + } elseif (! function_exists($forward)) { |
|
| 1356 | + $msg = sprintf( |
|
| 1357 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1358 | + $forward, |
|
| 1359 | + $route |
|
| 1360 | + ); |
|
| 1361 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1362 | + return false; |
|
| 1363 | + } |
|
| 1364 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1365 | + return true; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /** |
|
| 1370 | + * get_forward - get forwarding route |
|
| 1371 | + * |
|
| 1372 | + * @access public |
|
| 1373 | + * @param string $route - "pretty" public alias for module method |
|
| 1374 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1375 | + * allows different forwards to be served based on status |
|
| 1376 | + * @param string $key - url param key indicating a route is being called |
|
| 1377 | + * @return string |
|
| 1378 | + */ |
|
| 1379 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1380 | + { |
|
| 1381 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1382 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1383 | + return apply_filters( |
|
| 1384 | + 'FHEE__EE_Config__get_forward', |
|
| 1385 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1386 | + $route, |
|
| 1387 | + $status |
|
| 1388 | + ); |
|
| 1389 | + } |
|
| 1390 | + return null; |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1396 | + * results |
|
| 1397 | + * |
|
| 1398 | + * @access public |
|
| 1399 | + * @param string $route - "pretty" public alias for module method |
|
| 1400 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1401 | + * allows different views to be served based on status |
|
| 1402 | + * @param string $view |
|
| 1403 | + * @param string $key - url param key indicating a route is being called |
|
| 1404 | + * @return bool |
|
| 1405 | + */ |
|
| 1406 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1407 | + { |
|
| 1408 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1409 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1410 | + $msg = sprintf( |
|
| 1411 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1412 | + $route |
|
| 1413 | + ); |
|
| 1414 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1415 | + return false; |
|
| 1416 | + } |
|
| 1417 | + if (! is_readable($view)) { |
|
| 1418 | + $msg = sprintf( |
|
| 1419 | + __( |
|
| 1420 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1421 | + 'event_espresso' |
|
| 1422 | + ), |
|
| 1423 | + $view |
|
| 1424 | + ); |
|
| 1425 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1426 | + return false; |
|
| 1427 | + } |
|
| 1428 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1429 | + return true; |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + |
|
| 1433 | + /** |
|
| 1434 | + * get_view - get view for route and status |
|
| 1435 | + * |
|
| 1436 | + * @access public |
|
| 1437 | + * @param string $route - "pretty" public alias for module method |
|
| 1438 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1439 | + * allows different views to be served based on status |
|
| 1440 | + * @param string $key - url param key indicating a route is being called |
|
| 1441 | + * @return string |
|
| 1442 | + */ |
|
| 1443 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1444 | + { |
|
| 1445 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1446 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1447 | + return apply_filters( |
|
| 1448 | + 'FHEE__EE_Config__get_view', |
|
| 1449 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1450 | + $route, |
|
| 1451 | + $status |
|
| 1452 | + ); |
|
| 1453 | + } |
|
| 1454 | + return null; |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + |
|
| 1458 | + public function update_addon_option_names() |
|
| 1459 | + { |
|
| 1460 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + |
|
| 1464 | + public function shutdown() |
|
| 1465 | + { |
|
| 1466 | + $this->update_addon_option_names(); |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * @return LegacyShortcodesManager |
|
| 1472 | + */ |
|
| 1473 | + public static function getLegacyShortcodesManager() |
|
| 1474 | + { |
|
| 1475 | + |
|
| 1476 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1477 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1478 | + EE_Registry::instance() |
|
| 1479 | + ); |
|
| 1480 | + } |
|
| 1481 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + |
|
| 1485 | + /** |
|
| 1486 | + * register_shortcode - makes core aware of this shortcode |
|
| 1487 | + * |
|
| 1488 | + * @deprecated 4.9.26 |
|
| 1489 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1490 | + * @return bool |
|
| 1491 | + */ |
|
| 1492 | + public static function register_shortcode($shortcode_path = null) |
|
| 1493 | + { |
|
| 1494 | + EE_Error::doing_it_wrong( |
|
| 1495 | + __METHOD__, |
|
| 1496 | + __( |
|
| 1497 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1498 | + 'event_espresso' |
|
| 1499 | + ), |
|
| 1500 | + '4.9.26' |
|
| 1501 | + ); |
|
| 1502 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1503 | + } |
|
| 1912 | 1504 | } |
| 1913 | 1505 | |
| 1914 | -/** |
|
| 1915 | - * Config class for storing info on the Organization |
|
| 1916 | - */ |
|
| 1917 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1918 | -{ |
|
| 1919 | - |
|
| 1920 | - /** |
|
| 1921 | - * @var string $name |
|
| 1922 | - * eg EE4.1 |
|
| 1923 | - */ |
|
| 1924 | - public $name; |
|
| 1925 | - |
|
| 1926 | - /** |
|
| 1927 | - * @var string $address_1 |
|
| 1928 | - * eg 123 Onna Road |
|
| 1929 | - */ |
|
| 1930 | - public $address_1 = ''; |
|
| 1931 | - |
|
| 1932 | - /** |
|
| 1933 | - * @var string $address_2 |
|
| 1934 | - * eg PO Box 123 |
|
| 1935 | - */ |
|
| 1936 | - public $address_2 = ''; |
|
| 1937 | - |
|
| 1938 | - /** |
|
| 1939 | - * @var string $city |
|
| 1940 | - * eg Inna City |
|
| 1941 | - */ |
|
| 1942 | - public $city = ''; |
|
| 1943 | - |
|
| 1944 | - /** |
|
| 1945 | - * @var int $STA_ID |
|
| 1946 | - * eg 4 |
|
| 1947 | - */ |
|
| 1948 | - public $STA_ID = 0; |
|
| 1949 | - |
|
| 1950 | - /** |
|
| 1951 | - * @var string $CNT_ISO |
|
| 1952 | - * eg US |
|
| 1953 | - */ |
|
| 1954 | - public $CNT_ISO = ''; |
|
| 1955 | - |
|
| 1956 | - /** |
|
| 1957 | - * @var string $zip |
|
| 1958 | - * eg 12345 or V1A 2B3 |
|
| 1959 | - */ |
|
| 1960 | - public $zip = ''; |
|
| 1961 | - |
|
| 1962 | - /** |
|
| 1963 | - * @var string $email |
|
| 1964 | - * eg [email protected] |
|
| 1965 | - */ |
|
| 1966 | - public $email; |
|
| 1967 | - |
|
| 1968 | - /** |
|
| 1969 | - * @var string $phone |
|
| 1970 | - * eg. 111-111-1111 |
|
| 1971 | - */ |
|
| 1972 | - public $phone = ''; |
|
| 1973 | - |
|
| 1974 | - /** |
|
| 1975 | - * @var string $vat |
|
| 1976 | - * VAT/Tax Number |
|
| 1977 | - */ |
|
| 1978 | - public $vat = ''; |
|
| 1979 | - |
|
| 1980 | - /** |
|
| 1981 | - * @var string $logo_url |
|
| 1982 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1983 | - */ |
|
| 1984 | - public $logo_url = ''; |
|
| 1985 | - |
|
| 1986 | - /** |
|
| 1987 | - * The below are all various properties for holding links to organization social network profiles |
|
| 1988 | - * |
|
| 1989 | - * @var string |
|
| 1990 | - */ |
|
| 1991 | - /** |
|
| 1992 | - * facebook (facebook.com/profile.name) |
|
| 1993 | - * |
|
| 1994 | - * @var string |
|
| 1995 | - */ |
|
| 1996 | - public $facebook = ''; |
|
| 1997 | - |
|
| 1998 | - /** |
|
| 1999 | - * twitter (twitter.com/twitter_handle) |
|
| 2000 | - * |
|
| 2001 | - * @var string |
|
| 2002 | - */ |
|
| 2003 | - public $twitter = ''; |
|
| 2004 | - |
|
| 2005 | - /** |
|
| 2006 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2007 | - * |
|
| 2008 | - * @var string |
|
| 2009 | - */ |
|
| 2010 | - public $linkedin = ''; |
|
| 2011 | - |
|
| 2012 | - /** |
|
| 2013 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2014 | - * |
|
| 2015 | - * @var string |
|
| 2016 | - */ |
|
| 2017 | - public $pinterest = ''; |
|
| 2018 | - |
|
| 2019 | - /** |
|
| 2020 | - * google+ (google.com/+profileName) |
|
| 2021 | - * |
|
| 2022 | - * @var string |
|
| 2023 | - */ |
|
| 2024 | - public $google = ''; |
|
| 2025 | - |
|
| 2026 | - /** |
|
| 2027 | - * instagram (instagram.com/handle) |
|
| 2028 | - * |
|
| 2029 | - * @var string |
|
| 2030 | - */ |
|
| 2031 | - public $instagram = ''; |
|
| 2032 | - |
|
| 2033 | - |
|
| 2034 | - /** |
|
| 2035 | - * class constructor |
|
| 2036 | - * |
|
| 2037 | - * @access public |
|
| 2038 | - */ |
|
| 2039 | - public function __construct() |
|
| 2040 | - { |
|
| 2041 | - // set default organization settings |
|
| 2042 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2043 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2044 | - $this->email = get_bloginfo('admin_email'); |
|
| 2045 | - } |
|
| 2046 | -} |
|
| 2047 | - |
|
| 2048 | -/** |
|
| 2049 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2050 | - */ |
|
| 2051 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2052 | -{ |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * @var string $code |
|
| 2056 | - * eg 'US' |
|
| 2057 | - */ |
|
| 2058 | - public $code; |
|
| 2059 | - |
|
| 2060 | - /** |
|
| 2061 | - * @var string $name |
|
| 2062 | - * eg 'Dollar' |
|
| 2063 | - */ |
|
| 2064 | - public $name; |
|
| 2065 | - |
|
| 2066 | - /** |
|
| 2067 | - * plural name |
|
| 2068 | - * |
|
| 2069 | - * @var string $plural |
|
| 2070 | - * eg 'Dollars' |
|
| 2071 | - */ |
|
| 2072 | - public $plural; |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * currency sign |
|
| 2076 | - * |
|
| 2077 | - * @var string $sign |
|
| 2078 | - * eg '$' |
|
| 2079 | - */ |
|
| 2080 | - public $sign; |
|
| 2081 | - |
|
| 2082 | - /** |
|
| 2083 | - * Whether the currency sign should come before the number or not |
|
| 2084 | - * |
|
| 2085 | - * @var boolean $sign_b4 |
|
| 2086 | - */ |
|
| 2087 | - public $sign_b4; |
|
| 2088 | - |
|
| 2089 | - /** |
|
| 2090 | - * How many digits should come after the decimal place |
|
| 2091 | - * |
|
| 2092 | - * @var int $dec_plc |
|
| 2093 | - */ |
|
| 2094 | - public $dec_plc; |
|
| 2095 | - |
|
| 2096 | - /** |
|
| 2097 | - * Symbol to use for decimal mark |
|
| 2098 | - * |
|
| 2099 | - * @var string $dec_mrk |
|
| 2100 | - * eg '.' |
|
| 2101 | - */ |
|
| 2102 | - public $dec_mrk; |
|
| 2103 | - |
|
| 2104 | - /** |
|
| 2105 | - * Symbol to use for thousands |
|
| 2106 | - * |
|
| 2107 | - * @var string $thsnds |
|
| 2108 | - * eg ',' |
|
| 2109 | - */ |
|
| 2110 | - public $thsnds; |
|
| 2111 | - |
|
| 2112 | - |
|
| 2113 | - /** |
|
| 2114 | - * class constructor |
|
| 2115 | - * |
|
| 2116 | - * @access public |
|
| 2117 | - * @param string $CNT_ISO |
|
| 2118 | - * @throws \EE_Error |
|
| 2119 | - */ |
|
| 2120 | - public function __construct($CNT_ISO = '') |
|
| 2121 | - { |
|
| 2122 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2123 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2124 | - // get country code from organization settings or use default |
|
| 2125 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2126 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2127 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2128 | - : ''; |
|
| 2129 | - // but override if requested |
|
| 2130 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2131 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2132 | - if ( |
|
| 2133 | - ! empty($CNT_ISO) |
|
| 2134 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2135 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2136 | - ) { |
|
| 2137 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2138 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2139 | - if ($country instanceof EE_Country) { |
|
| 2140 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2141 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2142 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2143 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2144 | - $this->sign_b4 = $country->currency_sign_before( |
|
| 2145 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2146 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2147 | - $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2148 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2149 | - $this->thsnds = $country->currency_thousands_separator( |
|
| 2150 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2151 | - } |
|
| 2152 | - } |
|
| 2153 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2154 | - if (empty($this->code)) { |
|
| 2155 | - // set default currency settings |
|
| 2156 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2157 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2158 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2159 | - $this->sign = '$'; // currency sign: $ |
|
| 2160 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2161 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2162 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2163 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2164 | - } |
|
| 2165 | - } |
|
| 2166 | -} |
|
| 2167 | - |
|
| 2168 | -/** |
|
| 2169 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2170 | - */ |
|
| 2171 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2172 | -{ |
|
| 2173 | - |
|
| 2174 | - /** |
|
| 2175 | - * Default registration status |
|
| 2176 | - * |
|
| 2177 | - * @var string $default_STS_ID |
|
| 2178 | - * eg 'RPP' |
|
| 2179 | - */ |
|
| 2180 | - public $default_STS_ID; |
|
| 2181 | - |
|
| 2182 | - /** |
|
| 2183 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2184 | - * registrations) |
|
| 2185 | - * |
|
| 2186 | - * @var int |
|
| 2187 | - */ |
|
| 2188 | - public $default_maximum_number_of_tickets; |
|
| 2189 | - |
|
| 2190 | - /** |
|
| 2191 | - * level of validation to apply to email addresses |
|
| 2192 | - * |
|
| 2193 | - * @var string $email_validation_level |
|
| 2194 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2195 | - */ |
|
| 2196 | - public $email_validation_level; |
|
| 2197 | - |
|
| 2198 | - /** |
|
| 2199 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2200 | - * |
|
| 2201 | - * @var boolean $show_pending_payment_options |
|
| 2202 | - */ |
|
| 2203 | - public $show_pending_payment_options; |
|
| 2204 | - |
|
| 2205 | - /** |
|
| 2206 | - * Whether to skip the registration confirmation page |
|
| 2207 | - * |
|
| 2208 | - * @var boolean $skip_reg_confirmation |
|
| 2209 | - */ |
|
| 2210 | - public $skip_reg_confirmation; |
|
| 2211 | - |
|
| 2212 | - /** |
|
| 2213 | - * an array of SPCO reg steps where: |
|
| 2214 | - * the keys denotes the reg step order |
|
| 2215 | - * each element consists of an array with the following elements: |
|
| 2216 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2217 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2218 | - * "slug" => the URL param used to trigger the reg step |
|
| 2219 | - * |
|
| 2220 | - * @var array $reg_steps |
|
| 2221 | - */ |
|
| 2222 | - public $reg_steps; |
|
| 2223 | - |
|
| 2224 | - /** |
|
| 2225 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2226 | - * |
|
| 2227 | - * @var boolean $reg_confirmation_last |
|
| 2228 | - */ |
|
| 2229 | - public $reg_confirmation_last; |
|
| 2230 | - |
|
| 2231 | - /** |
|
| 2232 | - * Whether or not to enable the EE Bot Trap |
|
| 2233 | - * |
|
| 2234 | - * @var boolean $use_bot_trap |
|
| 2235 | - */ |
|
| 2236 | - public $use_bot_trap; |
|
| 2237 | - |
|
| 2238 | - /** |
|
| 2239 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2240 | - * |
|
| 2241 | - * @var boolean $use_encryption |
|
| 2242 | - */ |
|
| 2243 | - public $use_encryption; |
|
| 2244 | - |
|
| 2245 | - /** |
|
| 2246 | - * Whether or not to use ReCaptcha |
|
| 2247 | - * |
|
| 2248 | - * @var boolean $use_captcha |
|
| 2249 | - */ |
|
| 2250 | - public $use_captcha; |
|
| 2251 | - |
|
| 2252 | - /** |
|
| 2253 | - * ReCaptcha Theme |
|
| 2254 | - * |
|
| 2255 | - * @var string $recaptcha_theme |
|
| 2256 | - * options: 'dark', 'light', 'invisible' |
|
| 2257 | - */ |
|
| 2258 | - public $recaptcha_theme; |
|
| 2259 | - |
|
| 2260 | - /** |
|
| 2261 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2262 | - * |
|
| 2263 | - * @var string $recaptcha_badge |
|
| 2264 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2265 | - */ |
|
| 2266 | - public $recaptcha_badge; |
|
| 2267 | - |
|
| 2268 | - /** |
|
| 2269 | - * ReCaptcha Type |
|
| 2270 | - * |
|
| 2271 | - * @var string $recaptcha_type |
|
| 2272 | - * options: 'audio', 'image' |
|
| 2273 | - */ |
|
| 2274 | - public $recaptcha_type; |
|
| 1506 | +/** |
|
| 1507 | + * Base class used for config classes. These classes should generally not have |
|
| 1508 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1509 | + * basically, they should just be well-defined stdClasses |
|
| 1510 | + */ |
|
| 1511 | +class EE_Config_Base |
|
| 1512 | +{ |
|
| 2275 | 1513 | |
| 2276 | - /** |
|
| 2277 | - * ReCaptcha language |
|
| 2278 | - * |
|
| 2279 | - * @var string $recaptcha_language |
|
| 2280 | - * eg 'en' |
|
| 2281 | - */ |
|
| 2282 | - public $recaptcha_language; |
|
| 1514 | + /** |
|
| 1515 | + * Utility function for escaping the value of a property and returning. |
|
| 1516 | + * |
|
| 1517 | + * @param string $property property name (checks to see if exists). |
|
| 1518 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1519 | + * @throws \EE_Error |
|
| 1520 | + */ |
|
| 1521 | + public function get_pretty($property) |
|
| 1522 | + { |
|
| 1523 | + if (! property_exists($this, $property)) { |
|
| 1524 | + throw new EE_Error( |
|
| 1525 | + sprintf( |
|
| 1526 | + __( |
|
| 1527 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1528 | + 'event_espresso' |
|
| 1529 | + ), |
|
| 1530 | + get_class($this), |
|
| 1531 | + $property |
|
| 1532 | + ) |
|
| 1533 | + ); |
|
| 1534 | + } |
|
| 1535 | + // just handling escaping of strings for now. |
|
| 1536 | + if (is_string($this->{$property})) { |
|
| 1537 | + return stripslashes($this->{$property}); |
|
| 1538 | + } |
|
| 1539 | + return $this->{$property}; |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + |
|
| 1543 | + public function populate() |
|
| 1544 | + { |
|
| 1545 | + // grab defaults via a new instance of this class. |
|
| 1546 | + $class_name = get_class($this); |
|
| 1547 | + $defaults = new $class_name(); |
|
| 1548 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1549 | + // default from our $defaults object. |
|
| 1550 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1551 | + if ($this->{$property} === null) { |
|
| 1552 | + $this->{$property} = $value; |
|
| 1553 | + } |
|
| 1554 | + } |
|
| 1555 | + // cleanup |
|
| 1556 | + unset($defaults); |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + |
|
| 1560 | + /** |
|
| 1561 | + * __isset |
|
| 1562 | + * |
|
| 1563 | + * @param $a |
|
| 1564 | + * @return bool |
|
| 1565 | + */ |
|
| 1566 | + public function __isset($a) |
|
| 1567 | + { |
|
| 1568 | + return false; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + |
|
| 1572 | + /** |
|
| 1573 | + * __unset |
|
| 1574 | + * |
|
| 1575 | + * @param $a |
|
| 1576 | + * @return bool |
|
| 1577 | + */ |
|
| 1578 | + public function __unset($a) |
|
| 1579 | + { |
|
| 1580 | + return false; |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + |
|
| 1584 | + /** |
|
| 1585 | + * __clone |
|
| 1586 | + */ |
|
| 1587 | + public function __clone() |
|
| 1588 | + { |
|
| 1589 | + } |
|
| 1590 | + |
|
| 1591 | + |
|
| 1592 | + /** |
|
| 1593 | + * __wakeup |
|
| 1594 | + */ |
|
| 1595 | + public function __wakeup() |
|
| 1596 | + { |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + |
|
| 1600 | + /** |
|
| 1601 | + * __destruct |
|
| 1602 | + */ |
|
| 1603 | + public function __destruct() |
|
| 1604 | + { |
|
| 1605 | + } |
|
| 1606 | +} |
|
| 2283 | 1607 | |
| 2284 | - /** |
|
| 2285 | - * ReCaptcha public key |
|
| 2286 | - * |
|
| 2287 | - * @var string $recaptcha_publickey |
|
| 2288 | - */ |
|
| 2289 | - public $recaptcha_publickey; |
|
| 1608 | +/** |
|
| 1609 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1610 | + */ |
|
| 1611 | +class EE_Core_Config extends EE_Config_Base |
|
| 1612 | +{ |
|
| 2290 | 1613 | |
| 2291 | - /** |
|
| 2292 | - * ReCaptcha private key |
|
| 2293 | - * |
|
| 2294 | - * @var string $recaptcha_privatekey |
|
| 2295 | - */ |
|
| 2296 | - public $recaptcha_privatekey; |
|
| 1614 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1615 | + |
|
| 1616 | + |
|
| 1617 | + public $current_blog_id; |
|
| 1618 | + |
|
| 1619 | + public $ee_ueip_optin; |
|
| 1620 | + |
|
| 1621 | + public $ee_ueip_has_notified; |
|
| 1622 | + |
|
| 1623 | + /** |
|
| 1624 | + * Not to be confused with the 4 critical page variables (See |
|
| 1625 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1626 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1627 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1628 | + * |
|
| 1629 | + * @var array |
|
| 1630 | + */ |
|
| 1631 | + public $post_shortcodes; |
|
| 1632 | + |
|
| 1633 | + public $module_route_map; |
|
| 1634 | + |
|
| 1635 | + public $module_forward_map; |
|
| 1636 | + |
|
| 1637 | + public $module_view_map; |
|
| 1638 | + |
|
| 1639 | + /** |
|
| 1640 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1641 | + * |
|
| 1642 | + * @var int |
|
| 1643 | + */ |
|
| 1644 | + public $reg_page_id; |
|
| 1645 | + |
|
| 1646 | + public $txn_page_id; |
|
| 1647 | + |
|
| 1648 | + public $thank_you_page_id; |
|
| 1649 | + |
|
| 1650 | + public $cancel_page_id; |
|
| 1651 | + |
|
| 1652 | + /** |
|
| 1653 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1654 | + * |
|
| 1655 | + * @var int |
|
| 1656 | + */ |
|
| 1657 | + public $reg_page_url; |
|
| 1658 | + |
|
| 1659 | + public $txn_page_url; |
|
| 1660 | + |
|
| 1661 | + public $thank_you_page_url; |
|
| 1662 | + |
|
| 1663 | + public $cancel_page_url; |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1667 | + */ |
|
| 1668 | + public $event_cpt_slug; |
|
| 1669 | + |
|
| 1670 | + /** |
|
| 1671 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1672 | + * request across blog switches in a multisite context. |
|
| 1673 | + * Avoids extra queries to the db for this option. |
|
| 1674 | + * |
|
| 1675 | + * @var bool |
|
| 1676 | + */ |
|
| 1677 | + public static $ee_ueip_option; |
|
| 1678 | + |
|
| 1679 | + |
|
| 1680 | + /** |
|
| 1681 | + * class constructor |
|
| 1682 | + * |
|
| 1683 | + * @access public |
|
| 1684 | + */ |
|
| 1685 | + public function __construct() |
|
| 1686 | + { |
|
| 1687 | + // set default organization settings |
|
| 1688 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1689 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1690 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1691 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1692 | + $this->post_shortcodes = array(); |
|
| 1693 | + $this->module_route_map = array(); |
|
| 1694 | + $this->module_forward_map = array(); |
|
| 1695 | + $this->module_view_map = array(); |
|
| 1696 | + // critical EE page IDs |
|
| 1697 | + $this->reg_page_id = 0; |
|
| 1698 | + $this->txn_page_id = 0; |
|
| 1699 | + $this->thank_you_page_id = 0; |
|
| 1700 | + $this->cancel_page_id = 0; |
|
| 1701 | + // critical EE page URLs |
|
| 1702 | + $this->reg_page_url = ''; |
|
| 1703 | + $this->txn_page_url = ''; |
|
| 1704 | + $this->thank_you_page_url = ''; |
|
| 1705 | + $this->cancel_page_url = ''; |
|
| 1706 | + // cpt slugs |
|
| 1707 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1708 | + // ueip constant check |
|
| 1709 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1710 | + $this->ee_ueip_optin = false; |
|
| 1711 | + $this->ee_ueip_has_notified = true; |
|
| 1712 | + } |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + |
|
| 1716 | + /** |
|
| 1717 | + * @return array |
|
| 1718 | + */ |
|
| 1719 | + public function get_critical_pages_array() |
|
| 1720 | + { |
|
| 1721 | + return array( |
|
| 1722 | + $this->reg_page_id, |
|
| 1723 | + $this->txn_page_id, |
|
| 1724 | + $this->thank_you_page_id, |
|
| 1725 | + $this->cancel_page_id, |
|
| 1726 | + ); |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * @return array |
|
| 1732 | + */ |
|
| 1733 | + public function get_critical_pages_shortcodes_array() |
|
| 1734 | + { |
|
| 1735 | + return array( |
|
| 1736 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1737 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1738 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1739 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1740 | + ); |
|
| 1741 | + } |
|
| 1742 | + |
|
| 1743 | + |
|
| 1744 | + /** |
|
| 1745 | + * gets/returns URL for EE reg_page |
|
| 1746 | + * |
|
| 1747 | + * @access public |
|
| 1748 | + * @return string |
|
| 1749 | + */ |
|
| 1750 | + public function reg_page_url() |
|
| 1751 | + { |
|
| 1752 | + if (! $this->reg_page_url) { |
|
| 1753 | + $this->reg_page_url = add_query_arg( |
|
| 1754 | + array('uts' => time()), |
|
| 1755 | + get_permalink($this->reg_page_id) |
|
| 1756 | + ) . '#checkout'; |
|
| 1757 | + } |
|
| 1758 | + return $this->reg_page_url; |
|
| 1759 | + } |
|
| 1760 | + |
|
| 1761 | + |
|
| 1762 | + /** |
|
| 1763 | + * gets/returns URL for EE txn_page |
|
| 1764 | + * |
|
| 1765 | + * @param array $query_args like what gets passed to |
|
| 1766 | + * add_query_arg() as the first argument |
|
| 1767 | + * @access public |
|
| 1768 | + * @return string |
|
| 1769 | + */ |
|
| 1770 | + public function txn_page_url($query_args = array()) |
|
| 1771 | + { |
|
| 1772 | + if (! $this->txn_page_url) { |
|
| 1773 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1774 | + } |
|
| 1775 | + if ($query_args) { |
|
| 1776 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1777 | + } else { |
|
| 1778 | + return $this->txn_page_url; |
|
| 1779 | + } |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + |
|
| 1783 | + /** |
|
| 1784 | + * gets/returns URL for EE thank_you_page |
|
| 1785 | + * |
|
| 1786 | + * @param array $query_args like what gets passed to |
|
| 1787 | + * add_query_arg() as the first argument |
|
| 1788 | + * @access public |
|
| 1789 | + * @return string |
|
| 1790 | + */ |
|
| 1791 | + public function thank_you_page_url($query_args = array()) |
|
| 1792 | + { |
|
| 1793 | + if (! $this->thank_you_page_url) { |
|
| 1794 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1795 | + } |
|
| 1796 | + if ($query_args) { |
|
| 1797 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1798 | + } else { |
|
| 1799 | + return $this->thank_you_page_url; |
|
| 1800 | + } |
|
| 1801 | + } |
|
| 1802 | + |
|
| 1803 | + |
|
| 1804 | + /** |
|
| 1805 | + * gets/returns URL for EE cancel_page |
|
| 1806 | + * |
|
| 1807 | + * @access public |
|
| 1808 | + * @return string |
|
| 1809 | + */ |
|
| 1810 | + public function cancel_page_url() |
|
| 1811 | + { |
|
| 1812 | + if (! $this->cancel_page_url) { |
|
| 1813 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1814 | + } |
|
| 1815 | + return $this->cancel_page_url; |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1821 | + * |
|
| 1822 | + * @since 4.7.5 |
|
| 1823 | + */ |
|
| 1824 | + protected function _reset_urls() |
|
| 1825 | + { |
|
| 1826 | + $this->reg_page_url = ''; |
|
| 1827 | + $this->txn_page_url = ''; |
|
| 1828 | + $this->cancel_page_url = ''; |
|
| 1829 | + $this->thank_you_page_url = ''; |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + |
|
| 1833 | + /** |
|
| 1834 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1835 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1836 | + * on the main site only. |
|
| 1837 | + * |
|
| 1838 | + * @return bool |
|
| 1839 | + */ |
|
| 1840 | + protected function _get_main_ee_ueip_optin() |
|
| 1841 | + { |
|
| 1842 | + // if this is the main site then we can just bypass our direct query. |
|
| 1843 | + if (is_main_site()) { |
|
| 1844 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1845 | + } |
|
| 1846 | + // is this already cached for this request? If so use it. |
|
| 1847 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1848 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1849 | + } |
|
| 1850 | + global $wpdb; |
|
| 1851 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1852 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1853 | + $option = self::OPTION_NAME_UXIP; |
|
| 1854 | + // set correct table for query |
|
| 1855 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1856 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1857 | + // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1858 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1859 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1860 | + // for the purpose of caching. |
|
| 1861 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1862 | + if (false !== $pre) { |
|
| 1863 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1864 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1865 | + } |
|
| 1866 | + $row = $wpdb->get_row( |
|
| 1867 | + $wpdb->prepare( |
|
| 1868 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1869 | + $option |
|
| 1870 | + ) |
|
| 1871 | + ); |
|
| 1872 | + if (is_object($row)) { |
|
| 1873 | + $value = $row->option_value; |
|
| 1874 | + } else { // option does not exist so use default. |
|
| 1875 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1876 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1877 | + } |
|
| 1878 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1879 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * Utility function for escaping the value of a property and returning. |
|
| 1885 | + * |
|
| 1886 | + * @param string $property property name (checks to see if exists). |
|
| 1887 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1888 | + * @throws \EE_Error |
|
| 1889 | + */ |
|
| 1890 | + public function get_pretty($property) |
|
| 1891 | + { |
|
| 1892 | + if ($property === self::OPTION_NAME_UXIP) { |
|
| 1893 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1894 | + } |
|
| 1895 | + return parent::get_pretty($property); |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + |
|
| 1899 | + /** |
|
| 1900 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1901 | + * on the object. |
|
| 1902 | + * |
|
| 1903 | + * @return array |
|
| 1904 | + */ |
|
| 1905 | + public function __sleep() |
|
| 1906 | + { |
|
| 1907 | + // reset all url properties |
|
| 1908 | + $this->_reset_urls(); |
|
| 1909 | + // return what to save to db |
|
| 1910 | + return array_keys(get_object_vars($this)); |
|
| 1911 | + } |
|
| 1912 | +} |
|
| 2297 | 1913 | |
| 2298 | - /** |
|
| 2299 | - * array of form names protected by ReCaptcha |
|
| 2300 | - * |
|
| 2301 | - * @var array $recaptcha_protected_forms |
|
| 2302 | - */ |
|
| 2303 | - public $recaptcha_protected_forms; |
|
| 1914 | +/** |
|
| 1915 | + * Config class for storing info on the Organization |
|
| 1916 | + */ |
|
| 1917 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1918 | +{ |
|
| 2304 | 1919 | |
| 2305 | - /** |
|
| 2306 | - * ReCaptcha width |
|
| 2307 | - * |
|
| 2308 | - * @var int $recaptcha_width |
|
| 2309 | - * @deprecated |
|
| 2310 | - */ |
|
| 2311 | - public $recaptcha_width; |
|
| 1920 | + /** |
|
| 1921 | + * @var string $name |
|
| 1922 | + * eg EE4.1 |
|
| 1923 | + */ |
|
| 1924 | + public $name; |
|
| 1925 | + |
|
| 1926 | + /** |
|
| 1927 | + * @var string $address_1 |
|
| 1928 | + * eg 123 Onna Road |
|
| 1929 | + */ |
|
| 1930 | + public $address_1 = ''; |
|
| 1931 | + |
|
| 1932 | + /** |
|
| 1933 | + * @var string $address_2 |
|
| 1934 | + * eg PO Box 123 |
|
| 1935 | + */ |
|
| 1936 | + public $address_2 = ''; |
|
| 1937 | + |
|
| 1938 | + /** |
|
| 1939 | + * @var string $city |
|
| 1940 | + * eg Inna City |
|
| 1941 | + */ |
|
| 1942 | + public $city = ''; |
|
| 1943 | + |
|
| 1944 | + /** |
|
| 1945 | + * @var int $STA_ID |
|
| 1946 | + * eg 4 |
|
| 1947 | + */ |
|
| 1948 | + public $STA_ID = 0; |
|
| 1949 | + |
|
| 1950 | + /** |
|
| 1951 | + * @var string $CNT_ISO |
|
| 1952 | + * eg US |
|
| 1953 | + */ |
|
| 1954 | + public $CNT_ISO = ''; |
|
| 1955 | + |
|
| 1956 | + /** |
|
| 1957 | + * @var string $zip |
|
| 1958 | + * eg 12345 or V1A 2B3 |
|
| 1959 | + */ |
|
| 1960 | + public $zip = ''; |
|
| 1961 | + |
|
| 1962 | + /** |
|
| 1963 | + * @var string $email |
|
| 1964 | + * eg [email protected] |
|
| 1965 | + */ |
|
| 1966 | + public $email; |
|
| 1967 | + |
|
| 1968 | + /** |
|
| 1969 | + * @var string $phone |
|
| 1970 | + * eg. 111-111-1111 |
|
| 1971 | + */ |
|
| 1972 | + public $phone = ''; |
|
| 1973 | + |
|
| 1974 | + /** |
|
| 1975 | + * @var string $vat |
|
| 1976 | + * VAT/Tax Number |
|
| 1977 | + */ |
|
| 1978 | + public $vat = ''; |
|
| 1979 | + |
|
| 1980 | + /** |
|
| 1981 | + * @var string $logo_url |
|
| 1982 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1983 | + */ |
|
| 1984 | + public $logo_url = ''; |
|
| 1985 | + |
|
| 1986 | + /** |
|
| 1987 | + * The below are all various properties for holding links to organization social network profiles |
|
| 1988 | + * |
|
| 1989 | + * @var string |
|
| 1990 | + */ |
|
| 1991 | + /** |
|
| 1992 | + * facebook (facebook.com/profile.name) |
|
| 1993 | + * |
|
| 1994 | + * @var string |
|
| 1995 | + */ |
|
| 1996 | + public $facebook = ''; |
|
| 1997 | + |
|
| 1998 | + /** |
|
| 1999 | + * twitter (twitter.com/twitter_handle) |
|
| 2000 | + * |
|
| 2001 | + * @var string |
|
| 2002 | + */ |
|
| 2003 | + public $twitter = ''; |
|
| 2004 | + |
|
| 2005 | + /** |
|
| 2006 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2007 | + * |
|
| 2008 | + * @var string |
|
| 2009 | + */ |
|
| 2010 | + public $linkedin = ''; |
|
| 2011 | + |
|
| 2012 | + /** |
|
| 2013 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2014 | + * |
|
| 2015 | + * @var string |
|
| 2016 | + */ |
|
| 2017 | + public $pinterest = ''; |
|
| 2018 | + |
|
| 2019 | + /** |
|
| 2020 | + * google+ (google.com/+profileName) |
|
| 2021 | + * |
|
| 2022 | + * @var string |
|
| 2023 | + */ |
|
| 2024 | + public $google = ''; |
|
| 2025 | + |
|
| 2026 | + /** |
|
| 2027 | + * instagram (instagram.com/handle) |
|
| 2028 | + * |
|
| 2029 | + * @var string |
|
| 2030 | + */ |
|
| 2031 | + public $instagram = ''; |
|
| 2032 | + |
|
| 2033 | + |
|
| 2034 | + /** |
|
| 2035 | + * class constructor |
|
| 2036 | + * |
|
| 2037 | + * @access public |
|
| 2038 | + */ |
|
| 2039 | + public function __construct() |
|
| 2040 | + { |
|
| 2041 | + // set default organization settings |
|
| 2042 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2043 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2044 | + $this->email = get_bloginfo('admin_email'); |
|
| 2045 | + } |
|
| 2046 | +} |
|
| 2312 | 2047 | |
| 2313 | - /** |
|
| 2314 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2315 | - * |
|
| 2316 | - * @var boolean $track_invalid_checkout_access |
|
| 2317 | - */ |
|
| 2318 | - protected $track_invalid_checkout_access = true; |
|
| 2048 | +/** |
|
| 2049 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2050 | + */ |
|
| 2051 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2052 | +{ |
|
| 2319 | 2053 | |
| 2320 | - /** |
|
| 2321 | - * Whether or not to show the privacy policy consent checkbox |
|
| 2322 | - * |
|
| 2323 | - * @var bool |
|
| 2324 | - */ |
|
| 2325 | - public $consent_checkbox_enabled; |
|
| 2054 | + /** |
|
| 2055 | + * @var string $code |
|
| 2056 | + * eg 'US' |
|
| 2057 | + */ |
|
| 2058 | + public $code; |
|
| 2059 | + |
|
| 2060 | + /** |
|
| 2061 | + * @var string $name |
|
| 2062 | + * eg 'Dollar' |
|
| 2063 | + */ |
|
| 2064 | + public $name; |
|
| 2065 | + |
|
| 2066 | + /** |
|
| 2067 | + * plural name |
|
| 2068 | + * |
|
| 2069 | + * @var string $plural |
|
| 2070 | + * eg 'Dollars' |
|
| 2071 | + */ |
|
| 2072 | + public $plural; |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * currency sign |
|
| 2076 | + * |
|
| 2077 | + * @var string $sign |
|
| 2078 | + * eg '$' |
|
| 2079 | + */ |
|
| 2080 | + public $sign; |
|
| 2081 | + |
|
| 2082 | + /** |
|
| 2083 | + * Whether the currency sign should come before the number or not |
|
| 2084 | + * |
|
| 2085 | + * @var boolean $sign_b4 |
|
| 2086 | + */ |
|
| 2087 | + public $sign_b4; |
|
| 2088 | + |
|
| 2089 | + /** |
|
| 2090 | + * How many digits should come after the decimal place |
|
| 2091 | + * |
|
| 2092 | + * @var int $dec_plc |
|
| 2093 | + */ |
|
| 2094 | + public $dec_plc; |
|
| 2095 | + |
|
| 2096 | + /** |
|
| 2097 | + * Symbol to use for decimal mark |
|
| 2098 | + * |
|
| 2099 | + * @var string $dec_mrk |
|
| 2100 | + * eg '.' |
|
| 2101 | + */ |
|
| 2102 | + public $dec_mrk; |
|
| 2103 | + |
|
| 2104 | + /** |
|
| 2105 | + * Symbol to use for thousands |
|
| 2106 | + * |
|
| 2107 | + * @var string $thsnds |
|
| 2108 | + * eg ',' |
|
| 2109 | + */ |
|
| 2110 | + public $thsnds; |
|
| 2111 | + |
|
| 2112 | + |
|
| 2113 | + /** |
|
| 2114 | + * class constructor |
|
| 2115 | + * |
|
| 2116 | + * @access public |
|
| 2117 | + * @param string $CNT_ISO |
|
| 2118 | + * @throws \EE_Error |
|
| 2119 | + */ |
|
| 2120 | + public function __construct($CNT_ISO = '') |
|
| 2121 | + { |
|
| 2122 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2123 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2124 | + // get country code from organization settings or use default |
|
| 2125 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2126 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2127 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2128 | + : ''; |
|
| 2129 | + // but override if requested |
|
| 2130 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2131 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2132 | + if ( |
|
| 2133 | + ! empty($CNT_ISO) |
|
| 2134 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2135 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2136 | + ) { |
|
| 2137 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2138 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2139 | + if ($country instanceof EE_Country) { |
|
| 2140 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2141 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2142 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2143 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2144 | + $this->sign_b4 = $country->currency_sign_before( |
|
| 2145 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2146 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2147 | + $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2148 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2149 | + $this->thsnds = $country->currency_thousands_separator( |
|
| 2150 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2151 | + } |
|
| 2152 | + } |
|
| 2153 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2154 | + if (empty($this->code)) { |
|
| 2155 | + // set default currency settings |
|
| 2156 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2157 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2158 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2159 | + $this->sign = '$'; // currency sign: $ |
|
| 2160 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2161 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2162 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2163 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2164 | + } |
|
| 2165 | + } |
|
| 2166 | +} |
|
| 2326 | 2167 | |
| 2327 | - /** |
|
| 2328 | - * Label text to show on the checkbox |
|
| 2329 | - * |
|
| 2330 | - * @var string |
|
| 2331 | - */ |
|
| 2332 | - public $consent_checkbox_label_text; |
|
| 2168 | +/** |
|
| 2169 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2170 | + */ |
|
| 2171 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2172 | +{ |
|
| 2333 | 2173 | |
| 2334 | - /* |
|
| 2174 | + /** |
|
| 2175 | + * Default registration status |
|
| 2176 | + * |
|
| 2177 | + * @var string $default_STS_ID |
|
| 2178 | + * eg 'RPP' |
|
| 2179 | + */ |
|
| 2180 | + public $default_STS_ID; |
|
| 2181 | + |
|
| 2182 | + /** |
|
| 2183 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2184 | + * registrations) |
|
| 2185 | + * |
|
| 2186 | + * @var int |
|
| 2187 | + */ |
|
| 2188 | + public $default_maximum_number_of_tickets; |
|
| 2189 | + |
|
| 2190 | + /** |
|
| 2191 | + * level of validation to apply to email addresses |
|
| 2192 | + * |
|
| 2193 | + * @var string $email_validation_level |
|
| 2194 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2195 | + */ |
|
| 2196 | + public $email_validation_level; |
|
| 2197 | + |
|
| 2198 | + /** |
|
| 2199 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2200 | + * |
|
| 2201 | + * @var boolean $show_pending_payment_options |
|
| 2202 | + */ |
|
| 2203 | + public $show_pending_payment_options; |
|
| 2204 | + |
|
| 2205 | + /** |
|
| 2206 | + * Whether to skip the registration confirmation page |
|
| 2207 | + * |
|
| 2208 | + * @var boolean $skip_reg_confirmation |
|
| 2209 | + */ |
|
| 2210 | + public $skip_reg_confirmation; |
|
| 2211 | + |
|
| 2212 | + /** |
|
| 2213 | + * an array of SPCO reg steps where: |
|
| 2214 | + * the keys denotes the reg step order |
|
| 2215 | + * each element consists of an array with the following elements: |
|
| 2216 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2217 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2218 | + * "slug" => the URL param used to trigger the reg step |
|
| 2219 | + * |
|
| 2220 | + * @var array $reg_steps |
|
| 2221 | + */ |
|
| 2222 | + public $reg_steps; |
|
| 2223 | + |
|
| 2224 | + /** |
|
| 2225 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2226 | + * |
|
| 2227 | + * @var boolean $reg_confirmation_last |
|
| 2228 | + */ |
|
| 2229 | + public $reg_confirmation_last; |
|
| 2230 | + |
|
| 2231 | + /** |
|
| 2232 | + * Whether or not to enable the EE Bot Trap |
|
| 2233 | + * |
|
| 2234 | + * @var boolean $use_bot_trap |
|
| 2235 | + */ |
|
| 2236 | + public $use_bot_trap; |
|
| 2237 | + |
|
| 2238 | + /** |
|
| 2239 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2240 | + * |
|
| 2241 | + * @var boolean $use_encryption |
|
| 2242 | + */ |
|
| 2243 | + public $use_encryption; |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * Whether or not to use ReCaptcha |
|
| 2247 | + * |
|
| 2248 | + * @var boolean $use_captcha |
|
| 2249 | + */ |
|
| 2250 | + public $use_captcha; |
|
| 2251 | + |
|
| 2252 | + /** |
|
| 2253 | + * ReCaptcha Theme |
|
| 2254 | + * |
|
| 2255 | + * @var string $recaptcha_theme |
|
| 2256 | + * options: 'dark', 'light', 'invisible' |
|
| 2257 | + */ |
|
| 2258 | + public $recaptcha_theme; |
|
| 2259 | + |
|
| 2260 | + /** |
|
| 2261 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2262 | + * |
|
| 2263 | + * @var string $recaptcha_badge |
|
| 2264 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2265 | + */ |
|
| 2266 | + public $recaptcha_badge; |
|
| 2267 | + |
|
| 2268 | + /** |
|
| 2269 | + * ReCaptcha Type |
|
| 2270 | + * |
|
| 2271 | + * @var string $recaptcha_type |
|
| 2272 | + * options: 'audio', 'image' |
|
| 2273 | + */ |
|
| 2274 | + public $recaptcha_type; |
|
| 2275 | + |
|
| 2276 | + /** |
|
| 2277 | + * ReCaptcha language |
|
| 2278 | + * |
|
| 2279 | + * @var string $recaptcha_language |
|
| 2280 | + * eg 'en' |
|
| 2281 | + */ |
|
| 2282 | + public $recaptcha_language; |
|
| 2283 | + |
|
| 2284 | + /** |
|
| 2285 | + * ReCaptcha public key |
|
| 2286 | + * |
|
| 2287 | + * @var string $recaptcha_publickey |
|
| 2288 | + */ |
|
| 2289 | + public $recaptcha_publickey; |
|
| 2290 | + |
|
| 2291 | + /** |
|
| 2292 | + * ReCaptcha private key |
|
| 2293 | + * |
|
| 2294 | + * @var string $recaptcha_privatekey |
|
| 2295 | + */ |
|
| 2296 | + public $recaptcha_privatekey; |
|
| 2297 | + |
|
| 2298 | + /** |
|
| 2299 | + * array of form names protected by ReCaptcha |
|
| 2300 | + * |
|
| 2301 | + * @var array $recaptcha_protected_forms |
|
| 2302 | + */ |
|
| 2303 | + public $recaptcha_protected_forms; |
|
| 2304 | + |
|
| 2305 | + /** |
|
| 2306 | + * ReCaptcha width |
|
| 2307 | + * |
|
| 2308 | + * @var int $recaptcha_width |
|
| 2309 | + * @deprecated |
|
| 2310 | + */ |
|
| 2311 | + public $recaptcha_width; |
|
| 2312 | + |
|
| 2313 | + /** |
|
| 2314 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2315 | + * |
|
| 2316 | + * @var boolean $track_invalid_checkout_access |
|
| 2317 | + */ |
|
| 2318 | + protected $track_invalid_checkout_access = true; |
|
| 2319 | + |
|
| 2320 | + /** |
|
| 2321 | + * Whether or not to show the privacy policy consent checkbox |
|
| 2322 | + * |
|
| 2323 | + * @var bool |
|
| 2324 | + */ |
|
| 2325 | + public $consent_checkbox_enabled; |
|
| 2326 | + |
|
| 2327 | + /** |
|
| 2328 | + * Label text to show on the checkbox |
|
| 2329 | + * |
|
| 2330 | + * @var string |
|
| 2331 | + */ |
|
| 2332 | + public $consent_checkbox_label_text; |
|
| 2333 | + |
|
| 2334 | + /* |
|
| 2335 | 2335 | * String describing how long to keep payment logs. Passed into DateTime constructor |
| 2336 | 2336 | * @var string |
| 2337 | 2337 | */ |
| 2338 | - public $gateway_log_lifespan = '1 week'; |
|
| 2339 | - |
|
| 2340 | - /** |
|
| 2341 | - * Enable copy attendee info at form |
|
| 2342 | - * |
|
| 2343 | - * @var boolean $enable_copy_attendee |
|
| 2344 | - */ |
|
| 2345 | - protected $copy_attendee_info = true; |
|
| 2346 | - |
|
| 2347 | - |
|
| 2348 | - /** |
|
| 2349 | - * class constructor |
|
| 2350 | - * |
|
| 2351 | - * @access public |
|
| 2352 | - */ |
|
| 2353 | - public function __construct() |
|
| 2354 | - { |
|
| 2355 | - // set default registration settings |
|
| 2356 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2357 | - $this->email_validation_level = 'wp_default'; |
|
| 2358 | - $this->show_pending_payment_options = true; |
|
| 2359 | - $this->skip_reg_confirmation = true; |
|
| 2360 | - $this->reg_steps = array(); |
|
| 2361 | - $this->reg_confirmation_last = false; |
|
| 2362 | - $this->use_bot_trap = true; |
|
| 2363 | - $this->use_encryption = true; |
|
| 2364 | - $this->use_captcha = false; |
|
| 2365 | - $this->recaptcha_theme = 'light'; |
|
| 2366 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2367 | - $this->recaptcha_type = 'image'; |
|
| 2368 | - $this->recaptcha_language = 'en'; |
|
| 2369 | - $this->recaptcha_publickey = null; |
|
| 2370 | - $this->recaptcha_privatekey = null; |
|
| 2371 | - $this->recaptcha_protected_forms = array(); |
|
| 2372 | - $this->recaptcha_width = 500; |
|
| 2373 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2374 | - $this->consent_checkbox_enabled = false; |
|
| 2375 | - $this->consent_checkbox_label_text = ''; |
|
| 2376 | - $this->gateway_log_lifespan = '7 days'; |
|
| 2377 | - $this->copy_attendee_info = true; |
|
| 2378 | - } |
|
| 2379 | - |
|
| 2380 | - |
|
| 2381 | - /** |
|
| 2382 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2383 | - * |
|
| 2384 | - * @since 4.8.8.rc.019 |
|
| 2385 | - */ |
|
| 2386 | - public function do_hooks() |
|
| 2387 | - { |
|
| 2388 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2389 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2390 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2391 | - } |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - /** |
|
| 2395 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2396 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2397 | - */ |
|
| 2398 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2399 | - { |
|
| 2400 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2401 | - } |
|
| 2402 | - |
|
| 2403 | - |
|
| 2404 | - /** |
|
| 2405 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2406 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2407 | - */ |
|
| 2408 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2409 | - { |
|
| 2410 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2411 | - } |
|
| 2412 | - |
|
| 2413 | - |
|
| 2414 | - /** |
|
| 2415 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2416 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2417 | - * |
|
| 2418 | - * @throws InvalidArgumentException |
|
| 2419 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2420 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2421 | - */ |
|
| 2422 | - public function setDefaultCheckboxLabelText() |
|
| 2423 | - { |
|
| 2424 | - if ( |
|
| 2425 | - $this->getConsentCheckboxLabelText() === null |
|
| 2426 | - || $this->getConsentCheckboxLabelText() === '' |
|
| 2427 | - ) { |
|
| 2428 | - $opening_a_tag = ''; |
|
| 2429 | - $closing_a_tag = ''; |
|
| 2430 | - if (function_exists('get_privacy_policy_url')) { |
|
| 2431 | - $privacy_page_url = get_privacy_policy_url(); |
|
| 2432 | - if (! empty($privacy_page_url)) { |
|
| 2433 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2434 | - $closing_a_tag = '</a>'; |
|
| 2435 | - } |
|
| 2436 | - } |
|
| 2437 | - $loader = LoaderFactory::getLoader(); |
|
| 2438 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2439 | - /** |
|
| 2440 | - * @var $org_config EE_Organization_Config |
|
| 2441 | - */ |
|
| 2442 | - |
|
| 2443 | - $this->setConsentCheckboxLabelText( |
|
| 2444 | - sprintf( |
|
| 2445 | - esc_html__( |
|
| 2446 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2447 | - 'event_espresso' |
|
| 2448 | - ), |
|
| 2449 | - $org_config->name, |
|
| 2450 | - $opening_a_tag, |
|
| 2451 | - $closing_a_tag |
|
| 2452 | - ) |
|
| 2453 | - ); |
|
| 2454 | - } |
|
| 2455 | - } |
|
| 2456 | - |
|
| 2457 | - |
|
| 2458 | - /** |
|
| 2459 | - * @return boolean |
|
| 2460 | - */ |
|
| 2461 | - public function track_invalid_checkout_access() |
|
| 2462 | - { |
|
| 2463 | - return $this->track_invalid_checkout_access; |
|
| 2464 | - } |
|
| 2465 | - |
|
| 2466 | - |
|
| 2467 | - /** |
|
| 2468 | - * @param boolean $track_invalid_checkout_access |
|
| 2469 | - */ |
|
| 2470 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2471 | - { |
|
| 2472 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2473 | - $track_invalid_checkout_access, |
|
| 2474 | - FILTER_VALIDATE_BOOLEAN |
|
| 2475 | - ); |
|
| 2476 | - } |
|
| 2477 | - |
|
| 2478 | - /** |
|
| 2479 | - * @return boolean |
|
| 2480 | - */ |
|
| 2481 | - public function copyAttendeeInfo() |
|
| 2482 | - { |
|
| 2483 | - return $this->copy_attendee_info; |
|
| 2484 | - } |
|
| 2485 | - |
|
| 2486 | - |
|
| 2487 | - /** |
|
| 2488 | - * @param boolean $copy_attendee_info |
|
| 2489 | - */ |
|
| 2490 | - public function setCopyAttendeeInfo($copy_attendee_info) |
|
| 2491 | - { |
|
| 2492 | - $this->copy_attendee_info = filter_var( |
|
| 2493 | - $copy_attendee_info, |
|
| 2494 | - FILTER_VALIDATE_BOOLEAN |
|
| 2495 | - ); |
|
| 2496 | - } |
|
| 2497 | - |
|
| 2498 | - |
|
| 2499 | - /** |
|
| 2500 | - * Gets the options to make availalbe for the gateway log lifespan |
|
| 2501 | - * @return array |
|
| 2502 | - */ |
|
| 2503 | - public function gatewayLogLifespanOptions() |
|
| 2504 | - { |
|
| 2505 | - return (array) apply_filters( |
|
| 2506 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2507 | - array( |
|
| 2508 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2509 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2510 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2511 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2512 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2513 | - ) |
|
| 2514 | - ); |
|
| 2515 | - } |
|
| 2516 | - |
|
| 2517 | - |
|
| 2518 | - /** |
|
| 2519 | - * @return bool |
|
| 2520 | - */ |
|
| 2521 | - public function isConsentCheckboxEnabled() |
|
| 2522 | - { |
|
| 2523 | - return $this->consent_checkbox_enabled; |
|
| 2524 | - } |
|
| 2525 | - |
|
| 2526 | - |
|
| 2527 | - /** |
|
| 2528 | - * @param bool $consent_checkbox_enabled |
|
| 2529 | - */ |
|
| 2530 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2531 | - { |
|
| 2532 | - $this->consent_checkbox_enabled = filter_var( |
|
| 2533 | - $consent_checkbox_enabled, |
|
| 2534 | - FILTER_VALIDATE_BOOLEAN |
|
| 2535 | - ); |
|
| 2536 | - } |
|
| 2537 | - |
|
| 2538 | - |
|
| 2539 | - /** |
|
| 2540 | - * @return string |
|
| 2541 | - */ |
|
| 2542 | - public function getConsentCheckboxLabelText() |
|
| 2543 | - { |
|
| 2544 | - return $this->consent_checkbox_label_text; |
|
| 2545 | - } |
|
| 2546 | - |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * @param string $consent_checkbox_label_text |
|
| 2550 | - */ |
|
| 2551 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2552 | - { |
|
| 2553 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2554 | - } |
|
| 2338 | + public $gateway_log_lifespan = '1 week'; |
|
| 2339 | + |
|
| 2340 | + /** |
|
| 2341 | + * Enable copy attendee info at form |
|
| 2342 | + * |
|
| 2343 | + * @var boolean $enable_copy_attendee |
|
| 2344 | + */ |
|
| 2345 | + protected $copy_attendee_info = true; |
|
| 2346 | + |
|
| 2347 | + |
|
| 2348 | + /** |
|
| 2349 | + * class constructor |
|
| 2350 | + * |
|
| 2351 | + * @access public |
|
| 2352 | + */ |
|
| 2353 | + public function __construct() |
|
| 2354 | + { |
|
| 2355 | + // set default registration settings |
|
| 2356 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2357 | + $this->email_validation_level = 'wp_default'; |
|
| 2358 | + $this->show_pending_payment_options = true; |
|
| 2359 | + $this->skip_reg_confirmation = true; |
|
| 2360 | + $this->reg_steps = array(); |
|
| 2361 | + $this->reg_confirmation_last = false; |
|
| 2362 | + $this->use_bot_trap = true; |
|
| 2363 | + $this->use_encryption = true; |
|
| 2364 | + $this->use_captcha = false; |
|
| 2365 | + $this->recaptcha_theme = 'light'; |
|
| 2366 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2367 | + $this->recaptcha_type = 'image'; |
|
| 2368 | + $this->recaptcha_language = 'en'; |
|
| 2369 | + $this->recaptcha_publickey = null; |
|
| 2370 | + $this->recaptcha_privatekey = null; |
|
| 2371 | + $this->recaptcha_protected_forms = array(); |
|
| 2372 | + $this->recaptcha_width = 500; |
|
| 2373 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2374 | + $this->consent_checkbox_enabled = false; |
|
| 2375 | + $this->consent_checkbox_label_text = ''; |
|
| 2376 | + $this->gateway_log_lifespan = '7 days'; |
|
| 2377 | + $this->copy_attendee_info = true; |
|
| 2378 | + } |
|
| 2379 | + |
|
| 2380 | + |
|
| 2381 | + /** |
|
| 2382 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2383 | + * |
|
| 2384 | + * @since 4.8.8.rc.019 |
|
| 2385 | + */ |
|
| 2386 | + public function do_hooks() |
|
| 2387 | + { |
|
| 2388 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2389 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2390 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2391 | + } |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + /** |
|
| 2395 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2396 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2397 | + */ |
|
| 2398 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2399 | + { |
|
| 2400 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2401 | + } |
|
| 2402 | + |
|
| 2403 | + |
|
| 2404 | + /** |
|
| 2405 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2406 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2407 | + */ |
|
| 2408 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2409 | + { |
|
| 2410 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2411 | + } |
|
| 2412 | + |
|
| 2413 | + |
|
| 2414 | + /** |
|
| 2415 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2416 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2417 | + * |
|
| 2418 | + * @throws InvalidArgumentException |
|
| 2419 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2420 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2421 | + */ |
|
| 2422 | + public function setDefaultCheckboxLabelText() |
|
| 2423 | + { |
|
| 2424 | + if ( |
|
| 2425 | + $this->getConsentCheckboxLabelText() === null |
|
| 2426 | + || $this->getConsentCheckboxLabelText() === '' |
|
| 2427 | + ) { |
|
| 2428 | + $opening_a_tag = ''; |
|
| 2429 | + $closing_a_tag = ''; |
|
| 2430 | + if (function_exists('get_privacy_policy_url')) { |
|
| 2431 | + $privacy_page_url = get_privacy_policy_url(); |
|
| 2432 | + if (! empty($privacy_page_url)) { |
|
| 2433 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2434 | + $closing_a_tag = '</a>'; |
|
| 2435 | + } |
|
| 2436 | + } |
|
| 2437 | + $loader = LoaderFactory::getLoader(); |
|
| 2438 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2439 | + /** |
|
| 2440 | + * @var $org_config EE_Organization_Config |
|
| 2441 | + */ |
|
| 2442 | + |
|
| 2443 | + $this->setConsentCheckboxLabelText( |
|
| 2444 | + sprintf( |
|
| 2445 | + esc_html__( |
|
| 2446 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2447 | + 'event_espresso' |
|
| 2448 | + ), |
|
| 2449 | + $org_config->name, |
|
| 2450 | + $opening_a_tag, |
|
| 2451 | + $closing_a_tag |
|
| 2452 | + ) |
|
| 2453 | + ); |
|
| 2454 | + } |
|
| 2455 | + } |
|
| 2456 | + |
|
| 2457 | + |
|
| 2458 | + /** |
|
| 2459 | + * @return boolean |
|
| 2460 | + */ |
|
| 2461 | + public function track_invalid_checkout_access() |
|
| 2462 | + { |
|
| 2463 | + return $this->track_invalid_checkout_access; |
|
| 2464 | + } |
|
| 2465 | + |
|
| 2466 | + |
|
| 2467 | + /** |
|
| 2468 | + * @param boolean $track_invalid_checkout_access |
|
| 2469 | + */ |
|
| 2470 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2471 | + { |
|
| 2472 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2473 | + $track_invalid_checkout_access, |
|
| 2474 | + FILTER_VALIDATE_BOOLEAN |
|
| 2475 | + ); |
|
| 2476 | + } |
|
| 2477 | + |
|
| 2478 | + /** |
|
| 2479 | + * @return boolean |
|
| 2480 | + */ |
|
| 2481 | + public function copyAttendeeInfo() |
|
| 2482 | + { |
|
| 2483 | + return $this->copy_attendee_info; |
|
| 2484 | + } |
|
| 2485 | + |
|
| 2486 | + |
|
| 2487 | + /** |
|
| 2488 | + * @param boolean $copy_attendee_info |
|
| 2489 | + */ |
|
| 2490 | + public function setCopyAttendeeInfo($copy_attendee_info) |
|
| 2491 | + { |
|
| 2492 | + $this->copy_attendee_info = filter_var( |
|
| 2493 | + $copy_attendee_info, |
|
| 2494 | + FILTER_VALIDATE_BOOLEAN |
|
| 2495 | + ); |
|
| 2496 | + } |
|
| 2497 | + |
|
| 2498 | + |
|
| 2499 | + /** |
|
| 2500 | + * Gets the options to make availalbe for the gateway log lifespan |
|
| 2501 | + * @return array |
|
| 2502 | + */ |
|
| 2503 | + public function gatewayLogLifespanOptions() |
|
| 2504 | + { |
|
| 2505 | + return (array) apply_filters( |
|
| 2506 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2507 | + array( |
|
| 2508 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2509 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2510 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2511 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2512 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2513 | + ) |
|
| 2514 | + ); |
|
| 2515 | + } |
|
| 2516 | + |
|
| 2517 | + |
|
| 2518 | + /** |
|
| 2519 | + * @return bool |
|
| 2520 | + */ |
|
| 2521 | + public function isConsentCheckboxEnabled() |
|
| 2522 | + { |
|
| 2523 | + return $this->consent_checkbox_enabled; |
|
| 2524 | + } |
|
| 2525 | + |
|
| 2526 | + |
|
| 2527 | + /** |
|
| 2528 | + * @param bool $consent_checkbox_enabled |
|
| 2529 | + */ |
|
| 2530 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2531 | + { |
|
| 2532 | + $this->consent_checkbox_enabled = filter_var( |
|
| 2533 | + $consent_checkbox_enabled, |
|
| 2534 | + FILTER_VALIDATE_BOOLEAN |
|
| 2535 | + ); |
|
| 2536 | + } |
|
| 2537 | + |
|
| 2538 | + |
|
| 2539 | + /** |
|
| 2540 | + * @return string |
|
| 2541 | + */ |
|
| 2542 | + public function getConsentCheckboxLabelText() |
|
| 2543 | + { |
|
| 2544 | + return $this->consent_checkbox_label_text; |
|
| 2545 | + } |
|
| 2546 | + |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * @param string $consent_checkbox_label_text |
|
| 2550 | + */ |
|
| 2551 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2552 | + { |
|
| 2553 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2554 | + } |
|
| 2555 | 2555 | } |
| 2556 | 2556 | |
| 2557 | 2557 | /** |
@@ -2560,188 +2560,188 @@ discard block |
||
| 2560 | 2560 | class EE_Admin_Config extends EE_Config_Base |
| 2561 | 2561 | { |
| 2562 | 2562 | |
| 2563 | - /** |
|
| 2564 | - * @var boolean $useAdvancedEditor |
|
| 2565 | - */ |
|
| 2566 | - private $useAdvancedEditor; |
|
| 2567 | - |
|
| 2568 | - /** |
|
| 2569 | - * @var boolean $use_personnel_manager |
|
| 2570 | - */ |
|
| 2571 | - public $use_personnel_manager; |
|
| 2572 | - |
|
| 2573 | - /** |
|
| 2574 | - * @var boolean $use_dashboard_widget |
|
| 2575 | - */ |
|
| 2576 | - public $use_dashboard_widget; |
|
| 2577 | - |
|
| 2578 | - /** |
|
| 2579 | - * @var int $events_in_dashboard |
|
| 2580 | - */ |
|
| 2581 | - public $events_in_dashboard; |
|
| 2582 | - |
|
| 2583 | - /** |
|
| 2584 | - * @var boolean $use_event_timezones |
|
| 2585 | - */ |
|
| 2586 | - public $use_event_timezones; |
|
| 2587 | - |
|
| 2588 | - /** |
|
| 2589 | - * @var string $log_file_name |
|
| 2590 | - */ |
|
| 2591 | - public $log_file_name; |
|
| 2592 | - |
|
| 2593 | - /** |
|
| 2594 | - * @var string $debug_file_name |
|
| 2595 | - */ |
|
| 2596 | - public $debug_file_name; |
|
| 2597 | - |
|
| 2598 | - /** |
|
| 2599 | - * @var boolean $use_remote_logging |
|
| 2600 | - */ |
|
| 2601 | - public $use_remote_logging; |
|
| 2602 | - |
|
| 2603 | - /** |
|
| 2604 | - * @var string $remote_logging_url |
|
| 2605 | - */ |
|
| 2606 | - public $remote_logging_url; |
|
| 2607 | - |
|
| 2608 | - /** |
|
| 2609 | - * @var boolean $show_reg_footer |
|
| 2610 | - */ |
|
| 2611 | - public $show_reg_footer; |
|
| 2612 | - |
|
| 2613 | - /** |
|
| 2614 | - * @var string $affiliate_id |
|
| 2615 | - */ |
|
| 2616 | - public $affiliate_id; |
|
| 2617 | - |
|
| 2618 | - /** |
|
| 2619 | - * help tours on or off (global setting) |
|
| 2620 | - * |
|
| 2621 | - * @var boolean |
|
| 2622 | - */ |
|
| 2623 | - public $help_tour_activation; |
|
| 2624 | - |
|
| 2625 | - /** |
|
| 2626 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2627 | - * but is incompatible with some server configuration errors |
|
| 2628 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2629 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2630 | - * |
|
| 2631 | - * @var boolean $encode_session_data |
|
| 2632 | - */ |
|
| 2633 | - private $encode_session_data = false; |
|
| 2634 | - |
|
| 2635 | - /** |
|
| 2636 | - * @var boolean |
|
| 2637 | - */ |
|
| 2638 | - private $is_caffeinated; |
|
| 2639 | - |
|
| 2640 | - |
|
| 2641 | - /** |
|
| 2642 | - * class constructor |
|
| 2643 | - * |
|
| 2644 | - * @access public |
|
| 2645 | - */ |
|
| 2646 | - public function __construct() |
|
| 2647 | - { |
|
| 2648 | - // set default general admin settings |
|
| 2649 | - $this->useAdvancedEditor = true; |
|
| 2650 | - $this->use_personnel_manager = true; |
|
| 2651 | - $this->use_dashboard_widget = true; |
|
| 2652 | - $this->events_in_dashboard = 30; |
|
| 2653 | - $this->use_event_timezones = false; |
|
| 2654 | - $this->use_remote_logging = false; |
|
| 2655 | - $this->remote_logging_url = null; |
|
| 2656 | - $this->show_reg_footer = apply_filters( |
|
| 2657 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2658 | - false |
|
| 2659 | - ); |
|
| 2660 | - $this->affiliate_id = 'default'; |
|
| 2661 | - $this->help_tour_activation = false; |
|
| 2662 | - $this->encode_session_data = false; |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - |
|
| 2666 | - /** |
|
| 2667 | - * @param bool $reset |
|
| 2668 | - * @return string |
|
| 2669 | - */ |
|
| 2670 | - public function log_file_name($reset = false) |
|
| 2671 | - { |
|
| 2672 | - if (empty($this->log_file_name) || $reset) { |
|
| 2673 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2674 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2675 | - } |
|
| 2676 | - return $this->log_file_name; |
|
| 2677 | - } |
|
| 2678 | - |
|
| 2679 | - |
|
| 2680 | - /** |
|
| 2681 | - * @param bool $reset |
|
| 2682 | - * @return string |
|
| 2683 | - */ |
|
| 2684 | - public function debug_file_name($reset = false) |
|
| 2685 | - { |
|
| 2686 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2687 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2688 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2689 | - } |
|
| 2690 | - return $this->debug_file_name; |
|
| 2691 | - } |
|
| 2692 | - |
|
| 2693 | - |
|
| 2694 | - /** |
|
| 2695 | - * @return string |
|
| 2696 | - */ |
|
| 2697 | - public function affiliate_id() |
|
| 2698 | - { |
|
| 2699 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2700 | - } |
|
| 2701 | - |
|
| 2702 | - |
|
| 2703 | - /** |
|
| 2704 | - * @return boolean |
|
| 2705 | - */ |
|
| 2706 | - public function encode_session_data() |
|
| 2707 | - { |
|
| 2708 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2709 | - } |
|
| 2710 | - |
|
| 2711 | - |
|
| 2712 | - /** |
|
| 2713 | - * @param boolean $encode_session_data |
|
| 2714 | - */ |
|
| 2715 | - public function set_encode_session_data($encode_session_data) |
|
| 2716 | - { |
|
| 2717 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - /** |
|
| 2721 | - * @return boolean |
|
| 2722 | - */ |
|
| 2723 | - public function useAdvancedEditor() |
|
| 2724 | - { |
|
| 2725 | - if ($this->is_caffeinated === null) { |
|
| 2726 | - $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
| 2727 | - $this->is_caffeinated = $domain->isCaffeinated(); |
|
| 2728 | - } |
|
| 2729 | - return $this->useAdvancedEditor && $this->is_caffeinated; |
|
| 2730 | - } |
|
| 2731 | - |
|
| 2732 | - /** |
|
| 2733 | - * @param boolean $use_advanced_editor |
|
| 2734 | - */ |
|
| 2735 | - public function setUseAdvancedEditor($use_advanced_editor = true) |
|
| 2736 | - { |
|
| 2737 | - $this->useAdvancedEditor = filter_var( |
|
| 2738 | - apply_filters( |
|
| 2739 | - 'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor', |
|
| 2740 | - $use_advanced_editor |
|
| 2741 | - ), |
|
| 2742 | - FILTER_VALIDATE_BOOLEAN |
|
| 2743 | - ); |
|
| 2744 | - } |
|
| 2563 | + /** |
|
| 2564 | + * @var boolean $useAdvancedEditor |
|
| 2565 | + */ |
|
| 2566 | + private $useAdvancedEditor; |
|
| 2567 | + |
|
| 2568 | + /** |
|
| 2569 | + * @var boolean $use_personnel_manager |
|
| 2570 | + */ |
|
| 2571 | + public $use_personnel_manager; |
|
| 2572 | + |
|
| 2573 | + /** |
|
| 2574 | + * @var boolean $use_dashboard_widget |
|
| 2575 | + */ |
|
| 2576 | + public $use_dashboard_widget; |
|
| 2577 | + |
|
| 2578 | + /** |
|
| 2579 | + * @var int $events_in_dashboard |
|
| 2580 | + */ |
|
| 2581 | + public $events_in_dashboard; |
|
| 2582 | + |
|
| 2583 | + /** |
|
| 2584 | + * @var boolean $use_event_timezones |
|
| 2585 | + */ |
|
| 2586 | + public $use_event_timezones; |
|
| 2587 | + |
|
| 2588 | + /** |
|
| 2589 | + * @var string $log_file_name |
|
| 2590 | + */ |
|
| 2591 | + public $log_file_name; |
|
| 2592 | + |
|
| 2593 | + /** |
|
| 2594 | + * @var string $debug_file_name |
|
| 2595 | + */ |
|
| 2596 | + public $debug_file_name; |
|
| 2597 | + |
|
| 2598 | + /** |
|
| 2599 | + * @var boolean $use_remote_logging |
|
| 2600 | + */ |
|
| 2601 | + public $use_remote_logging; |
|
| 2602 | + |
|
| 2603 | + /** |
|
| 2604 | + * @var string $remote_logging_url |
|
| 2605 | + */ |
|
| 2606 | + public $remote_logging_url; |
|
| 2607 | + |
|
| 2608 | + /** |
|
| 2609 | + * @var boolean $show_reg_footer |
|
| 2610 | + */ |
|
| 2611 | + public $show_reg_footer; |
|
| 2612 | + |
|
| 2613 | + /** |
|
| 2614 | + * @var string $affiliate_id |
|
| 2615 | + */ |
|
| 2616 | + public $affiliate_id; |
|
| 2617 | + |
|
| 2618 | + /** |
|
| 2619 | + * help tours on or off (global setting) |
|
| 2620 | + * |
|
| 2621 | + * @var boolean |
|
| 2622 | + */ |
|
| 2623 | + public $help_tour_activation; |
|
| 2624 | + |
|
| 2625 | + /** |
|
| 2626 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2627 | + * but is incompatible with some server configuration errors |
|
| 2628 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2629 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2630 | + * |
|
| 2631 | + * @var boolean $encode_session_data |
|
| 2632 | + */ |
|
| 2633 | + private $encode_session_data = false; |
|
| 2634 | + |
|
| 2635 | + /** |
|
| 2636 | + * @var boolean |
|
| 2637 | + */ |
|
| 2638 | + private $is_caffeinated; |
|
| 2639 | + |
|
| 2640 | + |
|
| 2641 | + /** |
|
| 2642 | + * class constructor |
|
| 2643 | + * |
|
| 2644 | + * @access public |
|
| 2645 | + */ |
|
| 2646 | + public function __construct() |
|
| 2647 | + { |
|
| 2648 | + // set default general admin settings |
|
| 2649 | + $this->useAdvancedEditor = true; |
|
| 2650 | + $this->use_personnel_manager = true; |
|
| 2651 | + $this->use_dashboard_widget = true; |
|
| 2652 | + $this->events_in_dashboard = 30; |
|
| 2653 | + $this->use_event_timezones = false; |
|
| 2654 | + $this->use_remote_logging = false; |
|
| 2655 | + $this->remote_logging_url = null; |
|
| 2656 | + $this->show_reg_footer = apply_filters( |
|
| 2657 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2658 | + false |
|
| 2659 | + ); |
|
| 2660 | + $this->affiliate_id = 'default'; |
|
| 2661 | + $this->help_tour_activation = false; |
|
| 2662 | + $this->encode_session_data = false; |
|
| 2663 | + } |
|
| 2664 | + |
|
| 2665 | + |
|
| 2666 | + /** |
|
| 2667 | + * @param bool $reset |
|
| 2668 | + * @return string |
|
| 2669 | + */ |
|
| 2670 | + public function log_file_name($reset = false) |
|
| 2671 | + { |
|
| 2672 | + if (empty($this->log_file_name) || $reset) { |
|
| 2673 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2674 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2675 | + } |
|
| 2676 | + return $this->log_file_name; |
|
| 2677 | + } |
|
| 2678 | + |
|
| 2679 | + |
|
| 2680 | + /** |
|
| 2681 | + * @param bool $reset |
|
| 2682 | + * @return string |
|
| 2683 | + */ |
|
| 2684 | + public function debug_file_name($reset = false) |
|
| 2685 | + { |
|
| 2686 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2687 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2688 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2689 | + } |
|
| 2690 | + return $this->debug_file_name; |
|
| 2691 | + } |
|
| 2692 | + |
|
| 2693 | + |
|
| 2694 | + /** |
|
| 2695 | + * @return string |
|
| 2696 | + */ |
|
| 2697 | + public function affiliate_id() |
|
| 2698 | + { |
|
| 2699 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2700 | + } |
|
| 2701 | + |
|
| 2702 | + |
|
| 2703 | + /** |
|
| 2704 | + * @return boolean |
|
| 2705 | + */ |
|
| 2706 | + public function encode_session_data() |
|
| 2707 | + { |
|
| 2708 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2709 | + } |
|
| 2710 | + |
|
| 2711 | + |
|
| 2712 | + /** |
|
| 2713 | + * @param boolean $encode_session_data |
|
| 2714 | + */ |
|
| 2715 | + public function set_encode_session_data($encode_session_data) |
|
| 2716 | + { |
|
| 2717 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2718 | + } |
|
| 2719 | + |
|
| 2720 | + /** |
|
| 2721 | + * @return boolean |
|
| 2722 | + */ |
|
| 2723 | + public function useAdvancedEditor() |
|
| 2724 | + { |
|
| 2725 | + if ($this->is_caffeinated === null) { |
|
| 2726 | + $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
| 2727 | + $this->is_caffeinated = $domain->isCaffeinated(); |
|
| 2728 | + } |
|
| 2729 | + return $this->useAdvancedEditor && $this->is_caffeinated; |
|
| 2730 | + } |
|
| 2731 | + |
|
| 2732 | + /** |
|
| 2733 | + * @param boolean $use_advanced_editor |
|
| 2734 | + */ |
|
| 2735 | + public function setUseAdvancedEditor($use_advanced_editor = true) |
|
| 2736 | + { |
|
| 2737 | + $this->useAdvancedEditor = filter_var( |
|
| 2738 | + apply_filters( |
|
| 2739 | + 'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor', |
|
| 2740 | + $use_advanced_editor |
|
| 2741 | + ), |
|
| 2742 | + FILTER_VALIDATE_BOOLEAN |
|
| 2743 | + ); |
|
| 2744 | + } |
|
| 2745 | 2745 | } |
| 2746 | 2746 | |
| 2747 | 2747 | /** |
@@ -2750,70 +2750,70 @@ discard block |
||
| 2750 | 2750 | class EE_Template_Config extends EE_Config_Base |
| 2751 | 2751 | { |
| 2752 | 2752 | |
| 2753 | - /** |
|
| 2754 | - * @var boolean $enable_default_style |
|
| 2755 | - */ |
|
| 2756 | - public $enable_default_style; |
|
| 2757 | - |
|
| 2758 | - /** |
|
| 2759 | - * @var string $custom_style_sheet |
|
| 2760 | - */ |
|
| 2761 | - public $custom_style_sheet; |
|
| 2762 | - |
|
| 2763 | - /** |
|
| 2764 | - * @var boolean $display_address_in_regform |
|
| 2765 | - */ |
|
| 2766 | - public $display_address_in_regform; |
|
| 2767 | - |
|
| 2768 | - /** |
|
| 2769 | - * @var int $display_description_on_multi_reg_page |
|
| 2770 | - */ |
|
| 2771 | - public $display_description_on_multi_reg_page; |
|
| 2772 | - |
|
| 2773 | - /** |
|
| 2774 | - * @var boolean $use_custom_templates |
|
| 2775 | - */ |
|
| 2776 | - public $use_custom_templates; |
|
| 2777 | - |
|
| 2778 | - /** |
|
| 2779 | - * @var string $current_espresso_theme |
|
| 2780 | - */ |
|
| 2781 | - public $current_espresso_theme; |
|
| 2782 | - |
|
| 2783 | - /** |
|
| 2784 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2785 | - */ |
|
| 2786 | - public $EED_Ticket_Selector; |
|
| 2787 | - |
|
| 2788 | - /** |
|
| 2789 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2790 | - */ |
|
| 2791 | - public $EED_Event_Single; |
|
| 2792 | - |
|
| 2793 | - /** |
|
| 2794 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2795 | - */ |
|
| 2796 | - public $EED_Events_Archive; |
|
| 2797 | - |
|
| 2798 | - |
|
| 2799 | - /** |
|
| 2800 | - * class constructor |
|
| 2801 | - * |
|
| 2802 | - * @access public |
|
| 2803 | - */ |
|
| 2804 | - public function __construct() |
|
| 2805 | - { |
|
| 2806 | - // set default template settings |
|
| 2807 | - $this->enable_default_style = true; |
|
| 2808 | - $this->custom_style_sheet = null; |
|
| 2809 | - $this->display_address_in_regform = true; |
|
| 2810 | - $this->display_description_on_multi_reg_page = false; |
|
| 2811 | - $this->use_custom_templates = false; |
|
| 2812 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2813 | - $this->EED_Event_Single = null; |
|
| 2814 | - $this->EED_Events_Archive = null; |
|
| 2815 | - $this->EED_Ticket_Selector = null; |
|
| 2816 | - } |
|
| 2753 | + /** |
|
| 2754 | + * @var boolean $enable_default_style |
|
| 2755 | + */ |
|
| 2756 | + public $enable_default_style; |
|
| 2757 | + |
|
| 2758 | + /** |
|
| 2759 | + * @var string $custom_style_sheet |
|
| 2760 | + */ |
|
| 2761 | + public $custom_style_sheet; |
|
| 2762 | + |
|
| 2763 | + /** |
|
| 2764 | + * @var boolean $display_address_in_regform |
|
| 2765 | + */ |
|
| 2766 | + public $display_address_in_regform; |
|
| 2767 | + |
|
| 2768 | + /** |
|
| 2769 | + * @var int $display_description_on_multi_reg_page |
|
| 2770 | + */ |
|
| 2771 | + public $display_description_on_multi_reg_page; |
|
| 2772 | + |
|
| 2773 | + /** |
|
| 2774 | + * @var boolean $use_custom_templates |
|
| 2775 | + */ |
|
| 2776 | + public $use_custom_templates; |
|
| 2777 | + |
|
| 2778 | + /** |
|
| 2779 | + * @var string $current_espresso_theme |
|
| 2780 | + */ |
|
| 2781 | + public $current_espresso_theme; |
|
| 2782 | + |
|
| 2783 | + /** |
|
| 2784 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2785 | + */ |
|
| 2786 | + public $EED_Ticket_Selector; |
|
| 2787 | + |
|
| 2788 | + /** |
|
| 2789 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2790 | + */ |
|
| 2791 | + public $EED_Event_Single; |
|
| 2792 | + |
|
| 2793 | + /** |
|
| 2794 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2795 | + */ |
|
| 2796 | + public $EED_Events_Archive; |
|
| 2797 | + |
|
| 2798 | + |
|
| 2799 | + /** |
|
| 2800 | + * class constructor |
|
| 2801 | + * |
|
| 2802 | + * @access public |
|
| 2803 | + */ |
|
| 2804 | + public function __construct() |
|
| 2805 | + { |
|
| 2806 | + // set default template settings |
|
| 2807 | + $this->enable_default_style = true; |
|
| 2808 | + $this->custom_style_sheet = null; |
|
| 2809 | + $this->display_address_in_regform = true; |
|
| 2810 | + $this->display_description_on_multi_reg_page = false; |
|
| 2811 | + $this->use_custom_templates = false; |
|
| 2812 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2813 | + $this->EED_Event_Single = null; |
|
| 2814 | + $this->EED_Events_Archive = null; |
|
| 2815 | + $this->EED_Ticket_Selector = null; |
|
| 2816 | + } |
|
| 2817 | 2817 | } |
| 2818 | 2818 | |
| 2819 | 2819 | /** |
@@ -2822,114 +2822,114 @@ discard block |
||
| 2822 | 2822 | class EE_Map_Config extends EE_Config_Base |
| 2823 | 2823 | { |
| 2824 | 2824 | |
| 2825 | - /** |
|
| 2826 | - * @var boolean $use_google_maps |
|
| 2827 | - */ |
|
| 2828 | - public $use_google_maps; |
|
| 2829 | - |
|
| 2830 | - /** |
|
| 2831 | - * @var string $api_key |
|
| 2832 | - */ |
|
| 2833 | - public $google_map_api_key; |
|
| 2834 | - |
|
| 2835 | - /** |
|
| 2836 | - * @var int $event_details_map_width |
|
| 2837 | - */ |
|
| 2838 | - public $event_details_map_width; |
|
| 2839 | - |
|
| 2840 | - /** |
|
| 2841 | - * @var int $event_details_map_height |
|
| 2842 | - */ |
|
| 2843 | - public $event_details_map_height; |
|
| 2844 | - |
|
| 2845 | - /** |
|
| 2846 | - * @var int $event_details_map_zoom |
|
| 2847 | - */ |
|
| 2848 | - public $event_details_map_zoom; |
|
| 2849 | - |
|
| 2850 | - /** |
|
| 2851 | - * @var boolean $event_details_display_nav |
|
| 2852 | - */ |
|
| 2853 | - public $event_details_display_nav; |
|
| 2854 | - |
|
| 2855 | - /** |
|
| 2856 | - * @var boolean $event_details_nav_size |
|
| 2857 | - */ |
|
| 2858 | - public $event_details_nav_size; |
|
| 2859 | - |
|
| 2860 | - /** |
|
| 2861 | - * @var string $event_details_control_type |
|
| 2862 | - */ |
|
| 2863 | - public $event_details_control_type; |
|
| 2864 | - |
|
| 2865 | - /** |
|
| 2866 | - * @var string $event_details_map_align |
|
| 2867 | - */ |
|
| 2868 | - public $event_details_map_align; |
|
| 2869 | - |
|
| 2870 | - /** |
|
| 2871 | - * @var int $event_list_map_width |
|
| 2872 | - */ |
|
| 2873 | - public $event_list_map_width; |
|
| 2874 | - |
|
| 2875 | - /** |
|
| 2876 | - * @var int $event_list_map_height |
|
| 2877 | - */ |
|
| 2878 | - public $event_list_map_height; |
|
| 2879 | - |
|
| 2880 | - /** |
|
| 2881 | - * @var int $event_list_map_zoom |
|
| 2882 | - */ |
|
| 2883 | - public $event_list_map_zoom; |
|
| 2884 | - |
|
| 2885 | - /** |
|
| 2886 | - * @var boolean $event_list_display_nav |
|
| 2887 | - */ |
|
| 2888 | - public $event_list_display_nav; |
|
| 2889 | - |
|
| 2890 | - /** |
|
| 2891 | - * @var boolean $event_list_nav_size |
|
| 2892 | - */ |
|
| 2893 | - public $event_list_nav_size; |
|
| 2894 | - |
|
| 2895 | - /** |
|
| 2896 | - * @var string $event_list_control_type |
|
| 2897 | - */ |
|
| 2898 | - public $event_list_control_type; |
|
| 2899 | - |
|
| 2900 | - /** |
|
| 2901 | - * @var string $event_list_map_align |
|
| 2902 | - */ |
|
| 2903 | - public $event_list_map_align; |
|
| 2904 | - |
|
| 2905 | - |
|
| 2906 | - /** |
|
| 2907 | - * class constructor |
|
| 2908 | - * |
|
| 2909 | - * @access public |
|
| 2910 | - */ |
|
| 2911 | - public function __construct() |
|
| 2912 | - { |
|
| 2913 | - // set default map settings |
|
| 2914 | - $this->use_google_maps = true; |
|
| 2915 | - $this->google_map_api_key = ''; |
|
| 2916 | - // for event details pages (reg page) |
|
| 2917 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2918 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2919 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2920 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2921 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2922 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2923 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2924 | - // for event list pages |
|
| 2925 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2926 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2927 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2928 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2929 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2930 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2931 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2932 | - } |
|
| 2825 | + /** |
|
| 2826 | + * @var boolean $use_google_maps |
|
| 2827 | + */ |
|
| 2828 | + public $use_google_maps; |
|
| 2829 | + |
|
| 2830 | + /** |
|
| 2831 | + * @var string $api_key |
|
| 2832 | + */ |
|
| 2833 | + public $google_map_api_key; |
|
| 2834 | + |
|
| 2835 | + /** |
|
| 2836 | + * @var int $event_details_map_width |
|
| 2837 | + */ |
|
| 2838 | + public $event_details_map_width; |
|
| 2839 | + |
|
| 2840 | + /** |
|
| 2841 | + * @var int $event_details_map_height |
|
| 2842 | + */ |
|
| 2843 | + public $event_details_map_height; |
|
| 2844 | + |
|
| 2845 | + /** |
|
| 2846 | + * @var int $event_details_map_zoom |
|
| 2847 | + */ |
|
| 2848 | + public $event_details_map_zoom; |
|
| 2849 | + |
|
| 2850 | + /** |
|
| 2851 | + * @var boolean $event_details_display_nav |
|
| 2852 | + */ |
|
| 2853 | + public $event_details_display_nav; |
|
| 2854 | + |
|
| 2855 | + /** |
|
| 2856 | + * @var boolean $event_details_nav_size |
|
| 2857 | + */ |
|
| 2858 | + public $event_details_nav_size; |
|
| 2859 | + |
|
| 2860 | + /** |
|
| 2861 | + * @var string $event_details_control_type |
|
| 2862 | + */ |
|
| 2863 | + public $event_details_control_type; |
|
| 2864 | + |
|
| 2865 | + /** |
|
| 2866 | + * @var string $event_details_map_align |
|
| 2867 | + */ |
|
| 2868 | + public $event_details_map_align; |
|
| 2869 | + |
|
| 2870 | + /** |
|
| 2871 | + * @var int $event_list_map_width |
|
| 2872 | + */ |
|
| 2873 | + public $event_list_map_width; |
|
| 2874 | + |
|
| 2875 | + /** |
|
| 2876 | + * @var int $event_list_map_height |
|
| 2877 | + */ |
|
| 2878 | + public $event_list_map_height; |
|
| 2879 | + |
|
| 2880 | + /** |
|
| 2881 | + * @var int $event_list_map_zoom |
|
| 2882 | + */ |
|
| 2883 | + public $event_list_map_zoom; |
|
| 2884 | + |
|
| 2885 | + /** |
|
| 2886 | + * @var boolean $event_list_display_nav |
|
| 2887 | + */ |
|
| 2888 | + public $event_list_display_nav; |
|
| 2889 | + |
|
| 2890 | + /** |
|
| 2891 | + * @var boolean $event_list_nav_size |
|
| 2892 | + */ |
|
| 2893 | + public $event_list_nav_size; |
|
| 2894 | + |
|
| 2895 | + /** |
|
| 2896 | + * @var string $event_list_control_type |
|
| 2897 | + */ |
|
| 2898 | + public $event_list_control_type; |
|
| 2899 | + |
|
| 2900 | + /** |
|
| 2901 | + * @var string $event_list_map_align |
|
| 2902 | + */ |
|
| 2903 | + public $event_list_map_align; |
|
| 2904 | + |
|
| 2905 | + |
|
| 2906 | + /** |
|
| 2907 | + * class constructor |
|
| 2908 | + * |
|
| 2909 | + * @access public |
|
| 2910 | + */ |
|
| 2911 | + public function __construct() |
|
| 2912 | + { |
|
| 2913 | + // set default map settings |
|
| 2914 | + $this->use_google_maps = true; |
|
| 2915 | + $this->google_map_api_key = ''; |
|
| 2916 | + // for event details pages (reg page) |
|
| 2917 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2918 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2919 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2920 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2921 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2922 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2923 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2924 | + // for event list pages |
|
| 2925 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2926 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2927 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2928 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2929 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2930 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2931 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2932 | + } |
|
| 2933 | 2933 | } |
| 2934 | 2934 | |
| 2935 | 2935 | /** |
@@ -2938,46 +2938,46 @@ discard block |
||
| 2938 | 2938 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2939 | 2939 | { |
| 2940 | 2940 | |
| 2941 | - public $display_status_banner; |
|
| 2941 | + public $display_status_banner; |
|
| 2942 | 2942 | |
| 2943 | - public $display_description; |
|
| 2943 | + public $display_description; |
|
| 2944 | 2944 | |
| 2945 | - public $display_ticket_selector; |
|
| 2945 | + public $display_ticket_selector; |
|
| 2946 | 2946 | |
| 2947 | - public $display_datetimes; |
|
| 2947 | + public $display_datetimes; |
|
| 2948 | 2948 | |
| 2949 | - public $display_venue; |
|
| 2949 | + public $display_venue; |
|
| 2950 | 2950 | |
| 2951 | - public $display_expired_events; |
|
| 2951 | + public $display_expired_events; |
|
| 2952 | 2952 | |
| 2953 | - public $use_sortable_display_order; |
|
| 2953 | + public $use_sortable_display_order; |
|
| 2954 | 2954 | |
| 2955 | - public $display_order_tickets; |
|
| 2955 | + public $display_order_tickets; |
|
| 2956 | 2956 | |
| 2957 | - public $display_order_datetimes; |
|
| 2957 | + public $display_order_datetimes; |
|
| 2958 | 2958 | |
| 2959 | - public $display_order_event; |
|
| 2959 | + public $display_order_event; |
|
| 2960 | 2960 | |
| 2961 | - public $display_order_venue; |
|
| 2961 | + public $display_order_venue; |
|
| 2962 | 2962 | |
| 2963 | 2963 | |
| 2964 | - /** |
|
| 2965 | - * class constructor |
|
| 2966 | - */ |
|
| 2967 | - public function __construct() |
|
| 2968 | - { |
|
| 2969 | - $this->display_status_banner = 0; |
|
| 2970 | - $this->display_description = 1; |
|
| 2971 | - $this->display_ticket_selector = 0; |
|
| 2972 | - $this->display_datetimes = 1; |
|
| 2973 | - $this->display_venue = 0; |
|
| 2974 | - $this->display_expired_events = 0; |
|
| 2975 | - $this->use_sortable_display_order = false; |
|
| 2976 | - $this->display_order_tickets = 100; |
|
| 2977 | - $this->display_order_datetimes = 110; |
|
| 2978 | - $this->display_order_event = 120; |
|
| 2979 | - $this->display_order_venue = 130; |
|
| 2980 | - } |
|
| 2964 | + /** |
|
| 2965 | + * class constructor |
|
| 2966 | + */ |
|
| 2967 | + public function __construct() |
|
| 2968 | + { |
|
| 2969 | + $this->display_status_banner = 0; |
|
| 2970 | + $this->display_description = 1; |
|
| 2971 | + $this->display_ticket_selector = 0; |
|
| 2972 | + $this->display_datetimes = 1; |
|
| 2973 | + $this->display_venue = 0; |
|
| 2974 | + $this->display_expired_events = 0; |
|
| 2975 | + $this->use_sortable_display_order = false; |
|
| 2976 | + $this->display_order_tickets = 100; |
|
| 2977 | + $this->display_order_datetimes = 110; |
|
| 2978 | + $this->display_order_event = 120; |
|
| 2979 | + $this->display_order_venue = 130; |
|
| 2980 | + } |
|
| 2981 | 2981 | } |
| 2982 | 2982 | |
| 2983 | 2983 | /** |
@@ -2986,34 +2986,34 @@ discard block |
||
| 2986 | 2986 | class EE_Event_Single_Config extends EE_Config_Base |
| 2987 | 2987 | { |
| 2988 | 2988 | |
| 2989 | - public $display_status_banner_single; |
|
| 2989 | + public $display_status_banner_single; |
|
| 2990 | 2990 | |
| 2991 | - public $display_venue; |
|
| 2991 | + public $display_venue; |
|
| 2992 | 2992 | |
| 2993 | - public $use_sortable_display_order; |
|
| 2993 | + public $use_sortable_display_order; |
|
| 2994 | 2994 | |
| 2995 | - public $display_order_tickets; |
|
| 2995 | + public $display_order_tickets; |
|
| 2996 | 2996 | |
| 2997 | - public $display_order_datetimes; |
|
| 2997 | + public $display_order_datetimes; |
|
| 2998 | 2998 | |
| 2999 | - public $display_order_event; |
|
| 2999 | + public $display_order_event; |
|
| 3000 | 3000 | |
| 3001 | - public $display_order_venue; |
|
| 3001 | + public $display_order_venue; |
|
| 3002 | 3002 | |
| 3003 | 3003 | |
| 3004 | - /** |
|
| 3005 | - * class constructor |
|
| 3006 | - */ |
|
| 3007 | - public function __construct() |
|
| 3008 | - { |
|
| 3009 | - $this->display_status_banner_single = 0; |
|
| 3010 | - $this->display_venue = 1; |
|
| 3011 | - $this->use_sortable_display_order = false; |
|
| 3012 | - $this->display_order_tickets = 100; |
|
| 3013 | - $this->display_order_datetimes = 110; |
|
| 3014 | - $this->display_order_event = 120; |
|
| 3015 | - $this->display_order_venue = 130; |
|
| 3016 | - } |
|
| 3004 | + /** |
|
| 3005 | + * class constructor |
|
| 3006 | + */ |
|
| 3007 | + public function __construct() |
|
| 3008 | + { |
|
| 3009 | + $this->display_status_banner_single = 0; |
|
| 3010 | + $this->display_venue = 1; |
|
| 3011 | + $this->use_sortable_display_order = false; |
|
| 3012 | + $this->display_order_tickets = 100; |
|
| 3013 | + $this->display_order_datetimes = 110; |
|
| 3014 | + $this->display_order_event = 120; |
|
| 3015 | + $this->display_order_venue = 130; |
|
| 3016 | + } |
|
| 3017 | 3017 | } |
| 3018 | 3018 | |
| 3019 | 3019 | /** |
@@ -3022,172 +3022,172 @@ discard block |
||
| 3022 | 3022 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 3023 | 3023 | { |
| 3024 | 3024 | |
| 3025 | - /** |
|
| 3026 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 3027 | - */ |
|
| 3028 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 3029 | - |
|
| 3030 | - /** |
|
| 3031 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 3032 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 3033 | - */ |
|
| 3034 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 3035 | - |
|
| 3036 | - /** |
|
| 3037 | - * @var boolean $show_ticket_sale_columns |
|
| 3038 | - */ |
|
| 3039 | - public $show_ticket_sale_columns; |
|
| 3040 | - |
|
| 3041 | - /** |
|
| 3042 | - * @var boolean $show_ticket_details |
|
| 3043 | - */ |
|
| 3044 | - public $show_ticket_details; |
|
| 3045 | - |
|
| 3046 | - /** |
|
| 3047 | - * @var boolean $show_expired_tickets |
|
| 3048 | - */ |
|
| 3049 | - public $show_expired_tickets; |
|
| 3050 | - |
|
| 3051 | - /** |
|
| 3052 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 3053 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 3054 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3055 | - * |
|
| 3056 | - * @var string $show_datetime_selector |
|
| 3057 | - */ |
|
| 3058 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3059 | - |
|
| 3060 | - /** |
|
| 3061 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3062 | - * |
|
| 3063 | - * @var int $datetime_selector_threshold |
|
| 3064 | - */ |
|
| 3065 | - private $datetime_selector_threshold = 3; |
|
| 3066 | - |
|
| 3067 | - /** |
|
| 3068 | - * determines the maximum number of "checked" dates in the date and time filter |
|
| 3069 | - * |
|
| 3070 | - * @var int $datetime_selector_checked |
|
| 3071 | - */ |
|
| 3072 | - private $datetime_selector_max_checked = 10; |
|
| 3073 | - |
|
| 3074 | - |
|
| 3075 | - /** |
|
| 3076 | - * class constructor |
|
| 3077 | - */ |
|
| 3078 | - public function __construct() |
|
| 3079 | - { |
|
| 3080 | - $this->show_ticket_sale_columns = true; |
|
| 3081 | - $this->show_ticket_details = true; |
|
| 3082 | - $this->show_expired_tickets = true; |
|
| 3083 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3084 | - $this->datetime_selector_threshold = 3; |
|
| 3085 | - $this->datetime_selector_max_checked = 10; |
|
| 3086 | - } |
|
| 3087 | - |
|
| 3088 | - |
|
| 3089 | - /** |
|
| 3090 | - * returns true if a datetime selector should be displayed |
|
| 3091 | - * |
|
| 3092 | - * @param array $datetimes |
|
| 3093 | - * @return bool |
|
| 3094 | - */ |
|
| 3095 | - public function showDatetimeSelector(array $datetimes) |
|
| 3096 | - { |
|
| 3097 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3098 | - return ! ( |
|
| 3099 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3100 | - || ( |
|
| 3101 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3102 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3103 | - ) |
|
| 3104 | - ); |
|
| 3105 | - } |
|
| 3106 | - |
|
| 3107 | - |
|
| 3108 | - /** |
|
| 3109 | - * @return string |
|
| 3110 | - */ |
|
| 3111 | - public function getShowDatetimeSelector() |
|
| 3112 | - { |
|
| 3113 | - return $this->show_datetime_selector; |
|
| 3114 | - } |
|
| 3115 | - |
|
| 3116 | - |
|
| 3117 | - /** |
|
| 3118 | - * @param bool $keys_only |
|
| 3119 | - * @return array |
|
| 3120 | - */ |
|
| 3121 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3122 | - { |
|
| 3123 | - return $keys_only |
|
| 3124 | - ? array( |
|
| 3125 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3126 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3127 | - ) |
|
| 3128 | - : array( |
|
| 3129 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3130 | - 'Do not show date & time filter', |
|
| 3131 | - 'event_espresso' |
|
| 3132 | - ), |
|
| 3133 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3134 | - 'Maybe show date & time filter', |
|
| 3135 | - 'event_espresso' |
|
| 3136 | - ), |
|
| 3137 | - ); |
|
| 3138 | - } |
|
| 3139 | - |
|
| 3140 | - |
|
| 3141 | - /** |
|
| 3142 | - * @param string $show_datetime_selector |
|
| 3143 | - */ |
|
| 3144 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3145 | - { |
|
| 3146 | - $this->show_datetime_selector = in_array( |
|
| 3147 | - $show_datetime_selector, |
|
| 3148 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3149 | - true |
|
| 3150 | - ) |
|
| 3151 | - ? $show_datetime_selector |
|
| 3152 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3153 | - } |
|
| 3154 | - |
|
| 3155 | - |
|
| 3156 | - /** |
|
| 3157 | - * @return int |
|
| 3158 | - */ |
|
| 3159 | - public function getDatetimeSelectorThreshold() |
|
| 3160 | - { |
|
| 3161 | - return $this->datetime_selector_threshold; |
|
| 3162 | - } |
|
| 3163 | - |
|
| 3164 | - |
|
| 3165 | - /** |
|
| 3166 | - * @param int $datetime_selector_threshold |
|
| 3167 | - */ |
|
| 3168 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3169 | - { |
|
| 3170 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3171 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3172 | - } |
|
| 3173 | - |
|
| 3174 | - |
|
| 3175 | - /** |
|
| 3176 | - * @return int |
|
| 3177 | - */ |
|
| 3178 | - public function getDatetimeSelectorMaxChecked() |
|
| 3179 | - { |
|
| 3180 | - return $this->datetime_selector_max_checked; |
|
| 3181 | - } |
|
| 3182 | - |
|
| 3183 | - |
|
| 3184 | - /** |
|
| 3185 | - * @param int $datetime_selector_max_checked |
|
| 3186 | - */ |
|
| 3187 | - public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3188 | - { |
|
| 3189 | - $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3190 | - } |
|
| 3025 | + /** |
|
| 3026 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 3027 | + */ |
|
| 3028 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 3029 | + |
|
| 3030 | + /** |
|
| 3031 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 3032 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 3033 | + */ |
|
| 3034 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 3035 | + |
|
| 3036 | + /** |
|
| 3037 | + * @var boolean $show_ticket_sale_columns |
|
| 3038 | + */ |
|
| 3039 | + public $show_ticket_sale_columns; |
|
| 3040 | + |
|
| 3041 | + /** |
|
| 3042 | + * @var boolean $show_ticket_details |
|
| 3043 | + */ |
|
| 3044 | + public $show_ticket_details; |
|
| 3045 | + |
|
| 3046 | + /** |
|
| 3047 | + * @var boolean $show_expired_tickets |
|
| 3048 | + */ |
|
| 3049 | + public $show_expired_tickets; |
|
| 3050 | + |
|
| 3051 | + /** |
|
| 3052 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 3053 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 3054 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3055 | + * |
|
| 3056 | + * @var string $show_datetime_selector |
|
| 3057 | + */ |
|
| 3058 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3059 | + |
|
| 3060 | + /** |
|
| 3061 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3062 | + * |
|
| 3063 | + * @var int $datetime_selector_threshold |
|
| 3064 | + */ |
|
| 3065 | + private $datetime_selector_threshold = 3; |
|
| 3066 | + |
|
| 3067 | + /** |
|
| 3068 | + * determines the maximum number of "checked" dates in the date and time filter |
|
| 3069 | + * |
|
| 3070 | + * @var int $datetime_selector_checked |
|
| 3071 | + */ |
|
| 3072 | + private $datetime_selector_max_checked = 10; |
|
| 3073 | + |
|
| 3074 | + |
|
| 3075 | + /** |
|
| 3076 | + * class constructor |
|
| 3077 | + */ |
|
| 3078 | + public function __construct() |
|
| 3079 | + { |
|
| 3080 | + $this->show_ticket_sale_columns = true; |
|
| 3081 | + $this->show_ticket_details = true; |
|
| 3082 | + $this->show_expired_tickets = true; |
|
| 3083 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3084 | + $this->datetime_selector_threshold = 3; |
|
| 3085 | + $this->datetime_selector_max_checked = 10; |
|
| 3086 | + } |
|
| 3087 | + |
|
| 3088 | + |
|
| 3089 | + /** |
|
| 3090 | + * returns true if a datetime selector should be displayed |
|
| 3091 | + * |
|
| 3092 | + * @param array $datetimes |
|
| 3093 | + * @return bool |
|
| 3094 | + */ |
|
| 3095 | + public function showDatetimeSelector(array $datetimes) |
|
| 3096 | + { |
|
| 3097 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3098 | + return ! ( |
|
| 3099 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3100 | + || ( |
|
| 3101 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3102 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3103 | + ) |
|
| 3104 | + ); |
|
| 3105 | + } |
|
| 3106 | + |
|
| 3107 | + |
|
| 3108 | + /** |
|
| 3109 | + * @return string |
|
| 3110 | + */ |
|
| 3111 | + public function getShowDatetimeSelector() |
|
| 3112 | + { |
|
| 3113 | + return $this->show_datetime_selector; |
|
| 3114 | + } |
|
| 3115 | + |
|
| 3116 | + |
|
| 3117 | + /** |
|
| 3118 | + * @param bool $keys_only |
|
| 3119 | + * @return array |
|
| 3120 | + */ |
|
| 3121 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3122 | + { |
|
| 3123 | + return $keys_only |
|
| 3124 | + ? array( |
|
| 3125 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3126 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3127 | + ) |
|
| 3128 | + : array( |
|
| 3129 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3130 | + 'Do not show date & time filter', |
|
| 3131 | + 'event_espresso' |
|
| 3132 | + ), |
|
| 3133 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3134 | + 'Maybe show date & time filter', |
|
| 3135 | + 'event_espresso' |
|
| 3136 | + ), |
|
| 3137 | + ); |
|
| 3138 | + } |
|
| 3139 | + |
|
| 3140 | + |
|
| 3141 | + /** |
|
| 3142 | + * @param string $show_datetime_selector |
|
| 3143 | + */ |
|
| 3144 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3145 | + { |
|
| 3146 | + $this->show_datetime_selector = in_array( |
|
| 3147 | + $show_datetime_selector, |
|
| 3148 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3149 | + true |
|
| 3150 | + ) |
|
| 3151 | + ? $show_datetime_selector |
|
| 3152 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3153 | + } |
|
| 3154 | + |
|
| 3155 | + |
|
| 3156 | + /** |
|
| 3157 | + * @return int |
|
| 3158 | + */ |
|
| 3159 | + public function getDatetimeSelectorThreshold() |
|
| 3160 | + { |
|
| 3161 | + return $this->datetime_selector_threshold; |
|
| 3162 | + } |
|
| 3163 | + |
|
| 3164 | + |
|
| 3165 | + /** |
|
| 3166 | + * @param int $datetime_selector_threshold |
|
| 3167 | + */ |
|
| 3168 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3169 | + { |
|
| 3170 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3171 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3172 | + } |
|
| 3173 | + |
|
| 3174 | + |
|
| 3175 | + /** |
|
| 3176 | + * @return int |
|
| 3177 | + */ |
|
| 3178 | + public function getDatetimeSelectorMaxChecked() |
|
| 3179 | + { |
|
| 3180 | + return $this->datetime_selector_max_checked; |
|
| 3181 | + } |
|
| 3182 | + |
|
| 3183 | + |
|
| 3184 | + /** |
|
| 3185 | + * @param int $datetime_selector_max_checked |
|
| 3186 | + */ |
|
| 3187 | + public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3188 | + { |
|
| 3189 | + $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3190 | + } |
|
| 3191 | 3191 | } |
| 3192 | 3192 | |
| 3193 | 3193 | /** |
@@ -3200,87 +3200,87 @@ discard block |
||
| 3200 | 3200 | class EE_Environment_Config extends EE_Config_Base |
| 3201 | 3201 | { |
| 3202 | 3202 | |
| 3203 | - /** |
|
| 3204 | - * Hold any php environment variables that we want to track. |
|
| 3205 | - * |
|
| 3206 | - * @var stdClass; |
|
| 3207 | - */ |
|
| 3208 | - public $php; |
|
| 3209 | - |
|
| 3210 | - |
|
| 3211 | - /** |
|
| 3212 | - * constructor |
|
| 3213 | - */ |
|
| 3214 | - public function __construct() |
|
| 3215 | - { |
|
| 3216 | - $this->php = new stdClass(); |
|
| 3217 | - $this->_set_php_values(); |
|
| 3218 | - } |
|
| 3219 | - |
|
| 3220 | - |
|
| 3221 | - /** |
|
| 3222 | - * This sets the php environment variables. |
|
| 3223 | - * |
|
| 3224 | - * @since 4.4.0 |
|
| 3225 | - * @return void |
|
| 3226 | - */ |
|
| 3227 | - protected function _set_php_values() |
|
| 3228 | - { |
|
| 3229 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3230 | - $this->php->version = phpversion(); |
|
| 3231 | - } |
|
| 3232 | - |
|
| 3233 | - |
|
| 3234 | - /** |
|
| 3235 | - * helper method for determining whether input_count is |
|
| 3236 | - * reaching the potential maximum the server can handle |
|
| 3237 | - * according to max_input_vars |
|
| 3238 | - * |
|
| 3239 | - * @param int $input_count the count of input vars. |
|
| 3240 | - * @return array { |
|
| 3241 | - * An array that represents whether available space and if no available space the error |
|
| 3242 | - * message. |
|
| 3243 | - * @type bool $has_space whether more inputs can be added. |
|
| 3244 | - * @type string $msg Any message to be displayed. |
|
| 3245 | - * } |
|
| 3246 | - */ |
|
| 3247 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3248 | - { |
|
| 3249 | - if ( |
|
| 3250 | - ! empty($this->php->max_input_vars) |
|
| 3251 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3252 | - ) { |
|
| 3253 | - // check the server setting because the config value could be stale |
|
| 3254 | - $max_input_vars = ini_get('max_input_vars'); |
|
| 3255 | - if ($input_count >= $max_input_vars) { |
|
| 3256 | - return sprintf( |
|
| 3257 | - esc_html__( |
|
| 3258 | - 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3259 | - 'event_espresso' |
|
| 3260 | - ), |
|
| 3261 | - '<br>', |
|
| 3262 | - $input_count, |
|
| 3263 | - $max_input_vars |
|
| 3264 | - ); |
|
| 3265 | - } else { |
|
| 3266 | - return ''; |
|
| 3267 | - } |
|
| 3268 | - } else { |
|
| 3269 | - return ''; |
|
| 3270 | - } |
|
| 3271 | - } |
|
| 3272 | - |
|
| 3273 | - |
|
| 3274 | - /** |
|
| 3275 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3276 | - * |
|
| 3277 | - * @since 4.4.1 |
|
| 3278 | - * @return void |
|
| 3279 | - */ |
|
| 3280 | - public function recheck_values() |
|
| 3281 | - { |
|
| 3282 | - $this->_set_php_values(); |
|
| 3283 | - } |
|
| 3203 | + /** |
|
| 3204 | + * Hold any php environment variables that we want to track. |
|
| 3205 | + * |
|
| 3206 | + * @var stdClass; |
|
| 3207 | + */ |
|
| 3208 | + public $php; |
|
| 3209 | + |
|
| 3210 | + |
|
| 3211 | + /** |
|
| 3212 | + * constructor |
|
| 3213 | + */ |
|
| 3214 | + public function __construct() |
|
| 3215 | + { |
|
| 3216 | + $this->php = new stdClass(); |
|
| 3217 | + $this->_set_php_values(); |
|
| 3218 | + } |
|
| 3219 | + |
|
| 3220 | + |
|
| 3221 | + /** |
|
| 3222 | + * This sets the php environment variables. |
|
| 3223 | + * |
|
| 3224 | + * @since 4.4.0 |
|
| 3225 | + * @return void |
|
| 3226 | + */ |
|
| 3227 | + protected function _set_php_values() |
|
| 3228 | + { |
|
| 3229 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3230 | + $this->php->version = phpversion(); |
|
| 3231 | + } |
|
| 3232 | + |
|
| 3233 | + |
|
| 3234 | + /** |
|
| 3235 | + * helper method for determining whether input_count is |
|
| 3236 | + * reaching the potential maximum the server can handle |
|
| 3237 | + * according to max_input_vars |
|
| 3238 | + * |
|
| 3239 | + * @param int $input_count the count of input vars. |
|
| 3240 | + * @return array { |
|
| 3241 | + * An array that represents whether available space and if no available space the error |
|
| 3242 | + * message. |
|
| 3243 | + * @type bool $has_space whether more inputs can be added. |
|
| 3244 | + * @type string $msg Any message to be displayed. |
|
| 3245 | + * } |
|
| 3246 | + */ |
|
| 3247 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3248 | + { |
|
| 3249 | + if ( |
|
| 3250 | + ! empty($this->php->max_input_vars) |
|
| 3251 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3252 | + ) { |
|
| 3253 | + // check the server setting because the config value could be stale |
|
| 3254 | + $max_input_vars = ini_get('max_input_vars'); |
|
| 3255 | + if ($input_count >= $max_input_vars) { |
|
| 3256 | + return sprintf( |
|
| 3257 | + esc_html__( |
|
| 3258 | + 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3259 | + 'event_espresso' |
|
| 3260 | + ), |
|
| 3261 | + '<br>', |
|
| 3262 | + $input_count, |
|
| 3263 | + $max_input_vars |
|
| 3264 | + ); |
|
| 3265 | + } else { |
|
| 3266 | + return ''; |
|
| 3267 | + } |
|
| 3268 | + } else { |
|
| 3269 | + return ''; |
|
| 3270 | + } |
|
| 3271 | + } |
|
| 3272 | + |
|
| 3273 | + |
|
| 3274 | + /** |
|
| 3275 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3276 | + * |
|
| 3277 | + * @since 4.4.1 |
|
| 3278 | + * @return void |
|
| 3279 | + */ |
|
| 3280 | + public function recheck_values() |
|
| 3281 | + { |
|
| 3282 | + $this->_set_php_values(); |
|
| 3283 | + } |
|
| 3284 | 3284 | } |
| 3285 | 3285 | |
| 3286 | 3286 | /** |
@@ -3293,21 +3293,21 @@ discard block |
||
| 3293 | 3293 | class EE_Tax_Config extends EE_Config_Base |
| 3294 | 3294 | { |
| 3295 | 3295 | |
| 3296 | - /* |
|
| 3296 | + /* |
|
| 3297 | 3297 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3298 | 3298 | * |
| 3299 | 3299 | * @var boolean $prices_displayed_including_taxes |
| 3300 | 3300 | */ |
| 3301 | - public $prices_displayed_including_taxes; |
|
| 3301 | + public $prices_displayed_including_taxes; |
|
| 3302 | 3302 | |
| 3303 | 3303 | |
| 3304 | - /** |
|
| 3305 | - * class constructor |
|
| 3306 | - */ |
|
| 3307 | - public function __construct() |
|
| 3308 | - { |
|
| 3309 | - $this->prices_displayed_including_taxes = true; |
|
| 3310 | - } |
|
| 3304 | + /** |
|
| 3305 | + * class constructor |
|
| 3306 | + */ |
|
| 3307 | + public function __construct() |
|
| 3308 | + { |
|
| 3309 | + $this->prices_displayed_including_taxes = true; |
|
| 3310 | + } |
|
| 3311 | 3311 | } |
| 3312 | 3312 | |
| 3313 | 3313 | /** |
@@ -3321,19 +3321,19 @@ discard block |
||
| 3321 | 3321 | class EE_Messages_Config extends EE_Config_Base |
| 3322 | 3322 | { |
| 3323 | 3323 | |
| 3324 | - /** |
|
| 3325 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3326 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3327 | - * |
|
| 3328 | - * @var integer |
|
| 3329 | - */ |
|
| 3330 | - public $delete_threshold; |
|
| 3324 | + /** |
|
| 3325 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3326 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3327 | + * |
|
| 3328 | + * @var integer |
|
| 3329 | + */ |
|
| 3330 | + public $delete_threshold; |
|
| 3331 | 3331 | |
| 3332 | 3332 | |
| 3333 | - public function __construct() |
|
| 3334 | - { |
|
| 3335 | - $this->delete_threshold = 0; |
|
| 3336 | - } |
|
| 3333 | + public function __construct() |
|
| 3334 | + { |
|
| 3335 | + $this->delete_threshold = 0; |
|
| 3336 | + } |
|
| 3337 | 3337 | } |
| 3338 | 3338 | |
| 3339 | 3339 | /** |
@@ -3344,31 +3344,31 @@ discard block |
||
| 3344 | 3344 | class EE_Gateway_Config extends EE_Config_Base |
| 3345 | 3345 | { |
| 3346 | 3346 | |
| 3347 | - /** |
|
| 3348 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3349 | - * with any config info the gateway wants to store |
|
| 3350 | - * |
|
| 3351 | - * @var array |
|
| 3352 | - */ |
|
| 3353 | - public $payment_settings; |
|
| 3354 | - |
|
| 3355 | - /** |
|
| 3356 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3357 | - * the gateway is stored in the uploads directory |
|
| 3358 | - * |
|
| 3359 | - * @var array |
|
| 3360 | - */ |
|
| 3361 | - public $active_gateways; |
|
| 3362 | - |
|
| 3363 | - |
|
| 3364 | - /** |
|
| 3365 | - * class constructor |
|
| 3366 | - * |
|
| 3367 | - * @deprecated |
|
| 3368 | - */ |
|
| 3369 | - public function __construct() |
|
| 3370 | - { |
|
| 3371 | - $this->payment_settings = array(); |
|
| 3372 | - $this->active_gateways = array('Invoice' => false); |
|
| 3373 | - } |
|
| 3347 | + /** |
|
| 3348 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3349 | + * with any config info the gateway wants to store |
|
| 3350 | + * |
|
| 3351 | + * @var array |
|
| 3352 | + */ |
|
| 3353 | + public $payment_settings; |
|
| 3354 | + |
|
| 3355 | + /** |
|
| 3356 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3357 | + * the gateway is stored in the uploads directory |
|
| 3358 | + * |
|
| 3359 | + * @var array |
|
| 3360 | + */ |
|
| 3361 | + public $active_gateways; |
|
| 3362 | + |
|
| 3363 | + |
|
| 3364 | + /** |
|
| 3365 | + * class constructor |
|
| 3366 | + * |
|
| 3367 | + * @deprecated |
|
| 3368 | + */ |
|
| 3369 | + public function __construct() |
|
| 3370 | + { |
|
| 3371 | + $this->payment_settings = array(); |
|
| 3372 | + $this->active_gateways = array('Invoice' => false); |
|
| 3373 | + } |
|
| 3374 | 3374 | } |
@@ -18,4168 +18,4168 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var EE_Admin_Config |
|
| 23 | - */ |
|
| 24 | - protected $admin_config; |
|
| 21 | + /** |
|
| 22 | + * @var EE_Admin_Config |
|
| 23 | + */ |
|
| 24 | + protected $admin_config; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var LoaderInterface $loader |
|
| 28 | - */ |
|
| 29 | - protected $loader; |
|
| 26 | + /** |
|
| 27 | + * @var LoaderInterface $loader |
|
| 28 | + */ |
|
| 29 | + protected $loader; |
|
| 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 | - // nav tabs |
|
| 52 | - protected $_nav_tabs; |
|
| 51 | + // nav tabs |
|
| 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 = array(); |
|
| 56 | + /** |
|
| 57 | + * @var array $_help_tour |
|
| 58 | + */ |
|
| 59 | + protected $_help_tour = array(); |
|
| 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 = array(); |
|
| 67 | + /** |
|
| 68 | + * @var array $_template_args |
|
| 69 | + */ |
|
| 70 | + protected $_template_args = array(); |
|
| 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 | - // boolean |
|
| 80 | - protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states. |
|
| 79 | + // boolean |
|
| 80 | + protected $_is_UI_request; // 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; |
|
| 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 | 123 | |
| 124 | - // set via request page and action args. |
|
| 125 | - protected $_current_page; |
|
| 124 | + // set via request page and action args. |
|
| 125 | + protected $_current_page; |
|
| 126 | 126 | |
| 127 | - protected $_current_view; |
|
| 127 | + protected $_current_view; |
|
| 128 | 128 | |
| 129 | - protected $_current_page_view_url; |
|
| 129 | + protected $_current_page_view_url; |
|
| 130 | 130 | |
| 131 | - // sanitized request action (and nonce) |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @var string $_req_action |
|
| 135 | - */ |
|
| 136 | - protected $_req_action; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @var string $_req_nonce |
|
| 140 | - */ |
|
| 141 | - protected $_req_nonce; |
|
| 142 | - |
|
| 143 | - // search related |
|
| 144 | - protected $_search_btn_label; |
|
| 145 | - |
|
| 146 | - protected $_search_box_callback; |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * WP Current Screen object |
|
| 150 | - * |
|
| 151 | - * @var WP_Screen |
|
| 152 | - */ |
|
| 153 | - protected $_current_screen; |
|
| 154 | - |
|
| 155 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 156 | - protected $_hook_obj; |
|
| 157 | - |
|
| 158 | - // for holding incoming request data |
|
| 159 | - protected $_req_data = []; |
|
| 160 | - |
|
| 161 | - // yes / no array for admin form fields |
|
| 162 | - protected $_yes_no_values = array(); |
|
| 163 | - |
|
| 164 | - // some default things shared by all child classes |
|
| 165 | - protected $_default_espresso_metaboxes; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * EE_Registry Object |
|
| 169 | - * |
|
| 170 | - * @var EE_Registry |
|
| 171 | - */ |
|
| 172 | - protected $EE; |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 177 | - * |
|
| 178 | - * @var boolean |
|
| 179 | - */ |
|
| 180 | - protected $_is_caf = false; |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * whether or not initializePage() has run |
|
| 184 | - * |
|
| 185 | - * @var boolean |
|
| 186 | - */ |
|
| 187 | - protected $initialized = false; |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @var FeatureFlags |
|
| 191 | - */ |
|
| 192 | - protected $feature; |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @Constructor |
|
| 197 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 198 | - * @throws InvalidArgumentException |
|
| 199 | - * @throws InvalidDataTypeException |
|
| 200 | - * @throws InvalidInterfaceException |
|
| 201 | - * @throws ReflectionException |
|
| 202 | - */ |
|
| 203 | - public function __construct($routing = true) |
|
| 204 | - { |
|
| 205 | - $this->loader = LoaderFactory::getLoader(); |
|
| 206 | - $this->feature = $this->loader->getShared(FeatureFlags::class); |
|
| 207 | - $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 208 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 209 | - $this->_is_caf = true; |
|
| 210 | - } |
|
| 211 | - $this->_yes_no_values = array( |
|
| 212 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 213 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 214 | - ); |
|
| 215 | - // set the _req_data property. |
|
| 216 | - $this->_req_data = array_merge($_GET, $_POST); |
|
| 217 | - // routing enabled? |
|
| 218 | - $this->_routing = $routing; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * This logic used to be in the constructor, but that caused a chicken <--> egg scenario |
|
| 224 | - * for child classes that needed to set properties prior to these methods getting called, |
|
| 225 | - * but also needed the parent class to have its construction completed as well. |
|
| 226 | - * Bottom line is that constructors should ONLY be used for setting initial properties |
|
| 227 | - * and any complex initialization logic should only run after instantiation is complete. |
|
| 228 | - * |
|
| 229 | - * This method gets called immediately after construction from within |
|
| 230 | - * EE_Admin_Page_Init::_initialize_admin_page() |
|
| 231 | - * |
|
| 232 | - * @throws EE_Error |
|
| 233 | - * @throws InvalidArgumentException |
|
| 234 | - * @throws InvalidDataTypeException |
|
| 235 | - * @throws InvalidInterfaceException |
|
| 236 | - * @throws ReflectionException |
|
| 237 | - * @since $VID:$ |
|
| 238 | - */ |
|
| 239 | - public function initializePage() |
|
| 240 | - { |
|
| 241 | - if ($this->initialized) { |
|
| 242 | - return; |
|
| 243 | - } |
|
| 244 | - // set initial page props (child method) |
|
| 245 | - $this->_init_page_props(); |
|
| 246 | - // set global defaults |
|
| 247 | - $this->_set_defaults(); |
|
| 248 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 249 | - $this->_global_ajax_hooks(); |
|
| 250 | - $this->_ajax_hooks(); |
|
| 251 | - // other_page_hooks have to be early too. |
|
| 252 | - $this->_do_other_page_hooks(); |
|
| 253 | - // This just allows us to have extending classes do something specific |
|
| 254 | - // before the parent constructor runs _page_setup(). |
|
| 255 | - if (method_exists($this, '_before_page_setup')) { |
|
| 256 | - $this->_before_page_setup(); |
|
| 257 | - } |
|
| 258 | - // set up page dependencies |
|
| 259 | - $this->_page_setup(); |
|
| 260 | - $this->initialized = true; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * _init_page_props |
|
| 266 | - * Child classes use to set at least the following properties: |
|
| 267 | - * $page_slug. |
|
| 268 | - * $page_label. |
|
| 269 | - * |
|
| 270 | - * @abstract |
|
| 271 | - * @return void |
|
| 272 | - */ |
|
| 273 | - abstract protected function _init_page_props(); |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * _ajax_hooks |
|
| 278 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 279 | - * Note: within the ajax callback methods. |
|
| 280 | - * |
|
| 281 | - * @abstract |
|
| 282 | - * @return void |
|
| 283 | - */ |
|
| 284 | - abstract protected function _ajax_hooks(); |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * _define_page_props |
|
| 289 | - * child classes define page properties in here. Must include at least: |
|
| 290 | - * $_admin_base_url = base_url for all admin pages |
|
| 291 | - * $_admin_page_title = default admin_page_title for admin pages |
|
| 292 | - * $_labels = array of default labels for various automatically generated elements: |
|
| 293 | - * array( |
|
| 294 | - * 'buttons' => array( |
|
| 295 | - * 'add' => esc_html__('label for add new button'), |
|
| 296 | - * 'edit' => esc_html__('label for edit button'), |
|
| 297 | - * 'delete' => esc_html__('label for delete button') |
|
| 298 | - * ) |
|
| 299 | - * ) |
|
| 300 | - * |
|
| 301 | - * @abstract |
|
| 302 | - * @return void |
|
| 303 | - */ |
|
| 304 | - abstract protected function _define_page_props(); |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * _set_page_routes |
|
| 309 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 310 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 311 | - * have a 'default' route. Here's the format |
|
| 312 | - * $this->_page_routes = array( |
|
| 313 | - * 'default' => array( |
|
| 314 | - * 'func' => '_default_method_handling_route', |
|
| 315 | - * 'args' => array('array','of','args'), |
|
| 316 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 317 | - * ajax request, backend processing) |
|
| 318 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 319 | - * headers route after. The string you enter here should match the defined route reference for a |
|
| 320 | - * headers sent route. |
|
| 321 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 322 | - * this route. |
|
| 323 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 324 | - * checks). |
|
| 325 | - * ), |
|
| 326 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 327 | - * handling method. |
|
| 328 | - * ) |
|
| 329 | - * ) |
|
| 330 | - * |
|
| 331 | - * @abstract |
|
| 332 | - * @return void |
|
| 333 | - */ |
|
| 334 | - abstract protected function _set_page_routes(); |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * _set_page_config |
|
| 339 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 340 | - * array corresponds to the page_route for the loaded page. Format: |
|
| 341 | - * $this->_page_config = array( |
|
| 342 | - * 'default' => array( |
|
| 343 | - * 'labels' => array( |
|
| 344 | - * 'buttons' => array( |
|
| 345 | - * 'add' => esc_html__('label for adding item'), |
|
| 346 | - * 'edit' => esc_html__('label for editing item'), |
|
| 347 | - * 'delete' => esc_html__('label for deleting item') |
|
| 348 | - * ), |
|
| 349 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 350 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 351 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 352 | - * _define_page_props() method |
|
| 353 | - * 'nav' => array( |
|
| 354 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 355 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 356 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 357 | - * 'order' => 10, //required to indicate tab position. |
|
| 358 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 359 | - * displayed then add this parameter. |
|
| 360 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 361 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 362 | - * metaboxes set for eventespresso admin pages. |
|
| 363 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 364 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 365 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 366 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 367 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 368 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 369 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 370 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 371 | - * want to display. |
|
| 372 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 373 | - * 'tab_id' => array( |
|
| 374 | - * 'title' => 'tab_title', |
|
| 375 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 376 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 377 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 378 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 379 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 380 | - * attempt to use the callback which should match the name of a method in the class |
|
| 381 | - * ), |
|
| 382 | - * 'tab2_id' => array( |
|
| 383 | - * 'title' => 'tab2 title', |
|
| 384 | - * 'filename' => 'file_name_2' |
|
| 385 | - * 'callback' => 'callback_method_for_content', |
|
| 386 | - * ), |
|
| 387 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 388 | - * help tab area on an admin page. @link |
|
| 389 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 390 | - * 'help_tour' => array( |
|
| 391 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 392 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 393 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 394 | - * ), |
|
| 395 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 396 | - * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 397 | - * just set |
|
| 398 | - * 'require_nonce' to FALSE |
|
| 399 | - * ) |
|
| 400 | - * ) |
|
| 401 | - * |
|
| 402 | - * @abstract |
|
| 403 | - * @return void |
|
| 404 | - */ |
|
| 405 | - abstract protected function _set_page_config(); |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - /** end sample help_tour methods **/ |
|
| 412 | - /** |
|
| 413 | - * _add_screen_options |
|
| 414 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 415 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 416 | - * to a particular view. |
|
| 417 | - * |
|
| 418 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 419 | - * see also WP_Screen object documents... |
|
| 420 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 421 | - * @abstract |
|
| 422 | - * @return void |
|
| 423 | - */ |
|
| 424 | - abstract protected function _add_screen_options(); |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * _add_feature_pointers |
|
| 429 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 430 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 431 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 432 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 433 | - * extended) also see: |
|
| 434 | - * |
|
| 435 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 436 | - * @abstract |
|
| 437 | - * @return void |
|
| 438 | - */ |
|
| 439 | - abstract protected function _add_feature_pointers(); |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * load_scripts_styles |
|
| 444 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 445 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 446 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
| 447 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 448 | - * |
|
| 449 | - * @abstract |
|
| 450 | - * @return void |
|
| 451 | - */ |
|
| 452 | - abstract public function load_scripts_styles(); |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * admin_init |
|
| 457 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 458 | - * all pages/views loaded by child class. |
|
| 459 | - * |
|
| 460 | - * @abstract |
|
| 461 | - * @return void |
|
| 462 | - */ |
|
| 463 | - abstract public function admin_init(); |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * admin_notices |
|
| 468 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 469 | - * all pages/views loaded by child class. |
|
| 470 | - * |
|
| 471 | - * @abstract |
|
| 472 | - * @return void |
|
| 473 | - */ |
|
| 474 | - abstract public function admin_notices(); |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * admin_footer_scripts |
|
| 479 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 480 | - * will apply to all pages/views loaded by child class. |
|
| 481 | - * |
|
| 482 | - * @return void |
|
| 483 | - */ |
|
| 484 | - abstract public function admin_footer_scripts(); |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * admin_footer |
|
| 489 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 490 | - * apply to all pages/views loaded by child class. |
|
| 491 | - * |
|
| 492 | - * @return void |
|
| 493 | - */ |
|
| 494 | - public function admin_footer() |
|
| 495 | - { |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * _global_ajax_hooks |
|
| 501 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 502 | - * Note: within the ajax callback methods. |
|
| 503 | - * |
|
| 504 | - * @abstract |
|
| 505 | - * @return void |
|
| 506 | - */ |
|
| 507 | - protected function _global_ajax_hooks() |
|
| 508 | - { |
|
| 509 | - // for lazy loading of metabox content |
|
| 510 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 511 | - |
|
| 512 | - add_action( |
|
| 513 | - 'wp_ajax_espresso_hide_status_change_notice', |
|
| 514 | - [$this, 'hideStatusChangeNotice'] |
|
| 515 | - ); |
|
| 516 | - add_action( |
|
| 517 | - 'wp_ajax_nopriv_espresso_hide_status_change_notice', |
|
| 518 | - [$this, 'hideStatusChangeNotice'] |
|
| 519 | - ); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - public function ajax_metabox_content() |
|
| 524 | - { |
|
| 525 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 526 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 527 | - EE_Admin_Page::cached_rss_display($contentid, $url); |
|
| 528 | - wp_die(); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - public function hideStatusChangeNotice() |
|
| 533 | - { |
|
| 534 | - $response = []; |
|
| 535 | - try { |
|
| 536 | - /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
|
| 537 | - $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
|
| 538 | - $response['success'] = $status_change_notice->dismiss() > -1; |
|
| 539 | - } catch (Exception $exception) { |
|
| 540 | - $response['errors'] = $exception->getMessage(); |
|
| 541 | - } |
|
| 542 | - echo wp_json_encode($response); |
|
| 543 | - exit(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * _page_setup |
|
| 549 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 550 | - * doesn't match the object. |
|
| 551 | - * |
|
| 552 | - * @final |
|
| 553 | - * @return void |
|
| 554 | - * @throws EE_Error |
|
| 555 | - * @throws InvalidArgumentException |
|
| 556 | - * @throws ReflectionException |
|
| 557 | - * @throws InvalidDataTypeException |
|
| 558 | - * @throws InvalidInterfaceException |
|
| 559 | - */ |
|
| 560 | - final protected function _page_setup() |
|
| 561 | - { |
|
| 562 | - // requires? |
|
| 563 | - // admin_init stuff - global - we're setting this REALLY early |
|
| 564 | - // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 565 | - // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 566 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 567 | - // next verify if we need to load anything... |
|
| 568 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 569 | - $this->page_folder = strtolower( |
|
| 570 | - str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 571 | - ); |
|
| 572 | - global $ee_menu_slugs; |
|
| 573 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 574 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 575 | - return; |
|
| 576 | - } |
|
| 577 | - // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 578 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 579 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 580 | - ? $this->_req_data['action2'] |
|
| 581 | - : $this->_req_data['action']; |
|
| 582 | - } |
|
| 583 | - // then set blank or -1 action values to 'default' |
|
| 584 | - $this->_req_action = isset($this->_req_data['action']) |
|
| 585 | - && ! empty($this->_req_data['action']) |
|
| 586 | - && $this->_req_data['action'] !== '-1' |
|
| 587 | - ? sanitize_key($this->_req_data['action']) |
|
| 588 | - : 'default'; |
|
| 589 | - // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 590 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 591 | - $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 592 | - ? $this->_req_data['route'] : $this->_req_action; |
|
| 593 | - // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 594 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 595 | - ? $this->_req_data['route'] |
|
| 596 | - : $this->_req_action; |
|
| 597 | - $this->_current_view = $this->_req_action; |
|
| 598 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 599 | - $this->_define_page_props(); |
|
| 600 | - $this->_current_page_view_url = add_query_arg( |
|
| 601 | - array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 602 | - $this->_admin_base_url |
|
| 603 | - ); |
|
| 604 | - // default things |
|
| 605 | - $this->_default_espresso_metaboxes = array( |
|
| 606 | - '_espresso_news_post_box', |
|
| 607 | - '_espresso_links_post_box', |
|
| 608 | - '_espresso_ratings_request', |
|
| 609 | - '_espresso_sponsors_post_box', |
|
| 610 | - ); |
|
| 611 | - // set page configs |
|
| 612 | - $this->_set_page_routes(); |
|
| 613 | - $this->_set_page_config(); |
|
| 614 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 615 | - if (isset($this->_req_data['wp_referer'])) { |
|
| 616 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 617 | - } |
|
| 618 | - // for caffeinated and other extended functionality. |
|
| 619 | - // If there is a _extend_page_config method |
|
| 620 | - // then let's run that to modify the all the various page configuration arrays |
|
| 621 | - if (method_exists($this, '_extend_page_config')) { |
|
| 622 | - $this->_extend_page_config(); |
|
| 623 | - } |
|
| 624 | - // for CPT and other extended functionality. |
|
| 625 | - // If there is an _extend_page_config_for_cpt |
|
| 626 | - // then let's run that to modify all the various page configuration arrays. |
|
| 627 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 628 | - $this->_extend_page_config_for_cpt(); |
|
| 629 | - } |
|
| 630 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 631 | - $this->_page_routes = apply_filters( |
|
| 632 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 633 | - $this->_page_routes, |
|
| 634 | - $this |
|
| 635 | - ); |
|
| 636 | - $this->_page_config = apply_filters( |
|
| 637 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 638 | - $this->_page_config, |
|
| 639 | - $this |
|
| 640 | - ); |
|
| 641 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 642 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 643 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 644 | - add_action( |
|
| 645 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 646 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 647 | - 10, |
|
| 648 | - 2 |
|
| 649 | - ); |
|
| 650 | - } |
|
| 651 | - // next route only if routing enabled |
|
| 652 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 653 | - $this->_verify_routes(); |
|
| 654 | - // next let's just check user_access and kill if no access |
|
| 655 | - $this->check_user_access(); |
|
| 656 | - if ($this->_is_UI_request) { |
|
| 657 | - // admin_init stuff - global, all views for this page class, specific view |
|
| 658 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 659 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 660 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 661 | - } |
|
| 662 | - } else { |
|
| 663 | - // hijack regular WP loading and route admin request immediately |
|
| 664 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 665 | - $this->route_admin_request(); |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 673 | - * |
|
| 674 | - * @return void |
|
| 675 | - * @throws EE_Error |
|
| 676 | - */ |
|
| 677 | - private function _do_other_page_hooks() |
|
| 678 | - { |
|
| 679 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 680 | - foreach ($registered_pages as $page) { |
|
| 681 | - // now let's setup the file name and class that should be present |
|
| 682 | - $classname = str_replace('.class.php', '', $page); |
|
| 683 | - // autoloaders should take care of loading file |
|
| 684 | - if (! class_exists($classname)) { |
|
| 685 | - $error_msg[] = sprintf( |
|
| 686 | - esc_html__( |
|
| 687 | - 'Something went wrong with loading the %s admin hooks page.', |
|
| 688 | - 'event_espresso' |
|
| 689 | - ), |
|
| 690 | - $page |
|
| 691 | - ); |
|
| 692 | - $error_msg[] = $error_msg[0] |
|
| 693 | - . "\r\n" |
|
| 694 | - . sprintf( |
|
| 695 | - esc_html__( |
|
| 696 | - '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', |
|
| 697 | - 'event_espresso' |
|
| 698 | - ), |
|
| 699 | - $page, |
|
| 700 | - '<br />', |
|
| 701 | - '<strong>' . $classname . '</strong>' |
|
| 702 | - ); |
|
| 703 | - throw new EE_Error(implode('||', $error_msg)); |
|
| 704 | - } |
|
| 705 | - // // notice we are passing the instance of this class to the hook object. |
|
| 706 | - $this->loader->getShared($classname, [$this]); |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * @throws DomainException |
|
| 713 | - * @throws EE_Error |
|
| 714 | - * @throws InvalidArgumentException |
|
| 715 | - * @throws InvalidDataTypeException |
|
| 716 | - * @throws InvalidInterfaceException |
|
| 717 | - * @throws ReflectionException |
|
| 718 | - * @since $VID:$ |
|
| 719 | - */ |
|
| 720 | - public function load_page_dependencies() |
|
| 721 | - { |
|
| 722 | - try { |
|
| 723 | - $this->_load_page_dependencies(); |
|
| 724 | - } catch (EE_Error $e) { |
|
| 725 | - $e->get_error(); |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * load_page_dependencies |
|
| 732 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 733 | - * |
|
| 734 | - * @return void |
|
| 735 | - * @throws DomainException |
|
| 736 | - * @throws EE_Error |
|
| 737 | - * @throws InvalidArgumentException |
|
| 738 | - * @throws InvalidDataTypeException |
|
| 739 | - * @throws InvalidInterfaceException |
|
| 740 | - * @throws ReflectionException |
|
| 741 | - */ |
|
| 742 | - protected function _load_page_dependencies() |
|
| 743 | - { |
|
| 744 | - // let's set the current_screen and screen options to override what WP set |
|
| 745 | - $this->_current_screen = get_current_screen(); |
|
| 746 | - // load admin_notices - global, page class, and view specific |
|
| 747 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 748 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 749 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 750 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 751 | - } |
|
| 752 | - // load network admin_notices - global, page class, and view specific |
|
| 753 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 754 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 755 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 756 | - } |
|
| 757 | - // this will save any per_page screen options if they are present |
|
| 758 | - $this->_set_per_page_screen_options(); |
|
| 759 | - // setup list table properties |
|
| 760 | - $this->_set_list_table(); |
|
| 761 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 762 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 763 | - $this->_add_registered_meta_boxes(); |
|
| 764 | - $this->_add_screen_columns(); |
|
| 765 | - // add screen options - global, page child class, and view specific |
|
| 766 | - $this->_add_global_screen_options(); |
|
| 767 | - $this->_add_screen_options(); |
|
| 768 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 769 | - if (method_exists($this, $add_screen_options)) { |
|
| 770 | - $this->{$add_screen_options}(); |
|
| 771 | - } |
|
| 772 | - // add help tab(s) and tours- set via page_config and qtips. |
|
| 773 | - // $this->_add_help_tour(); |
|
| 774 | - $this->_add_help_tabs(); |
|
| 775 | - $this->_add_qtips(); |
|
| 776 | - // add feature_pointers - global, page child class, and view specific |
|
| 777 | - $this->_add_feature_pointers(); |
|
| 778 | - $this->_add_global_feature_pointers(); |
|
| 779 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 780 | - if (method_exists($this, $add_feature_pointer)) { |
|
| 781 | - $this->{$add_feature_pointer}(); |
|
| 782 | - } |
|
| 783 | - // enqueue scripts/styles - global, page class, and view specific |
|
| 784 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 785 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 786 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 787 | - add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 788 | - } |
|
| 789 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 790 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 791 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 792 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 793 | - // is a good use case. Notice the late priority we're giving these |
|
| 794 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 795 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 796 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 797 | - add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 798 | - } |
|
| 799 | - // admin footer scripts |
|
| 800 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 801 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 802 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 803 | - add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 804 | - } |
|
| 805 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 806 | - // targeted hook |
|
| 807 | - do_action( |
|
| 808 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 809 | - ); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * _set_defaults |
|
| 815 | - * This sets some global defaults for class properties. |
|
| 816 | - */ |
|
| 817 | - private function _set_defaults() |
|
| 818 | - { |
|
| 819 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 820 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 821 | - $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 822 | - $this->_page_config = $this->_default_route_query_args = array(); |
|
| 823 | - $this->_default_nav_tab_name = 'overview'; |
|
| 824 | - // init template args |
|
| 825 | - $this->_template_args = array( |
|
| 826 | - 'admin_page_header' => '', |
|
| 827 | - 'admin_page_content' => '', |
|
| 828 | - 'post_body_content' => '', |
|
| 829 | - 'before_list_table' => '', |
|
| 830 | - 'after_list_table' => '', |
|
| 831 | - ); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * route_admin_request |
|
| 837 | - * |
|
| 838 | - * @see _route_admin_request() |
|
| 839 | - * @return exception|void error |
|
| 840 | - * @throws InvalidArgumentException |
|
| 841 | - * @throws InvalidInterfaceException |
|
| 842 | - * @throws InvalidDataTypeException |
|
| 843 | - * @throws EE_Error |
|
| 844 | - * @throws ReflectionException |
|
| 845 | - */ |
|
| 846 | - public function route_admin_request() |
|
| 847 | - { |
|
| 848 | - try { |
|
| 849 | - $this->_route_admin_request(); |
|
| 850 | - } catch (EE_Error $e) { |
|
| 851 | - $e->get_error(); |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - public function set_wp_page_slug($wp_page_slug) |
|
| 857 | - { |
|
| 858 | - $this->_wp_page_slug = $wp_page_slug; |
|
| 859 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 860 | - if (is_network_admin()) { |
|
| 861 | - $this->_wp_page_slug .= '-network'; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * _verify_routes |
|
| 868 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 869 | - * we know if we need to drop out. |
|
| 870 | - * |
|
| 871 | - * @return bool |
|
| 872 | - * @throws EE_Error |
|
| 873 | - */ |
|
| 874 | - protected function _verify_routes() |
|
| 875 | - { |
|
| 876 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 877 | - return false; |
|
| 878 | - } |
|
| 879 | - $this->_route = false; |
|
| 880 | - // check that the page_routes array is not empty |
|
| 881 | - if (empty($this->_page_routes)) { |
|
| 882 | - // user error msg |
|
| 883 | - $error_msg = sprintf( |
|
| 884 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 885 | - $this->_admin_page_title |
|
| 886 | - ); |
|
| 887 | - // developer error msg |
|
| 888 | - $error_msg .= '||' . $error_msg |
|
| 889 | - . esc_html__( |
|
| 890 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 891 | - 'event_espresso' |
|
| 892 | - ); |
|
| 893 | - throw new EE_Error($error_msg); |
|
| 894 | - } |
|
| 895 | - // and that the requested page route exists |
|
| 896 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 897 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 898 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 899 | - ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 900 | - } else { |
|
| 901 | - // user error msg |
|
| 902 | - $error_msg = sprintf( |
|
| 903 | - esc_html__( |
|
| 904 | - 'The requested page route does not exist for the %s admin page.', |
|
| 905 | - 'event_espresso' |
|
| 906 | - ), |
|
| 907 | - $this->_admin_page_title |
|
| 908 | - ); |
|
| 909 | - // developer error msg |
|
| 910 | - $error_msg .= '||' . $error_msg |
|
| 911 | - . sprintf( |
|
| 912 | - esc_html__( |
|
| 913 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 914 | - 'event_espresso' |
|
| 915 | - ), |
|
| 916 | - $this->_req_action |
|
| 917 | - ); |
|
| 918 | - throw new EE_Error($error_msg); |
|
| 919 | - } |
|
| 920 | - // and that a default route exists |
|
| 921 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 922 | - // user error msg |
|
| 923 | - $error_msg = sprintf( |
|
| 924 | - esc_html__( |
|
| 925 | - 'A default page route has not been set for the % admin page.', |
|
| 926 | - 'event_espresso' |
|
| 927 | - ), |
|
| 928 | - $this->_admin_page_title |
|
| 929 | - ); |
|
| 930 | - // developer error msg |
|
| 931 | - $error_msg .= '||' . $error_msg |
|
| 932 | - . esc_html__( |
|
| 933 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 934 | - 'event_espresso' |
|
| 935 | - ); |
|
| 936 | - throw new EE_Error($error_msg); |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - // first lets' catch if the UI request has EVER been set. |
|
| 940 | - if ($this->_is_UI_request === null) { |
|
| 941 | - // lets set if this is a UI request or not. |
|
| 942 | - $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 943 | - // wait a minute... we might have a noheader in the route array |
|
| 944 | - $this->_is_UI_request = is_array($this->_route) |
|
| 945 | - && isset($this->_route['noheader']) |
|
| 946 | - && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 947 | - } |
|
| 948 | - $this->_set_current_labels(); |
|
| 949 | - return true; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 955 | - * |
|
| 956 | - * @param string $route the route name we're verifying |
|
| 957 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 958 | - * @throws EE_Error |
|
| 959 | - */ |
|
| 960 | - protected function _verify_route($route) |
|
| 961 | - { |
|
| 962 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 963 | - return true; |
|
| 964 | - } |
|
| 965 | - // user error msg |
|
| 966 | - $error_msg = sprintf( |
|
| 967 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 968 | - $this->_admin_page_title |
|
| 969 | - ); |
|
| 970 | - // developer error msg |
|
| 971 | - $error_msg .= '||' . $error_msg |
|
| 972 | - . sprintf( |
|
| 973 | - esc_html__( |
|
| 974 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 975 | - 'event_espresso' |
|
| 976 | - ), |
|
| 977 | - $route |
|
| 978 | - ); |
|
| 979 | - throw new EE_Error($error_msg); |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - |
|
| 983 | - /** |
|
| 984 | - * perform nonce verification |
|
| 985 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 986 | - * using this method (and save retyping!) |
|
| 987 | - * |
|
| 988 | - * @param string $nonce The nonce sent |
|
| 989 | - * @param string $nonce_ref The nonce reference string (name0) |
|
| 990 | - * @return void |
|
| 991 | - * @throws EE_Error |
|
| 992 | - * @throws InvalidArgumentException |
|
| 993 | - * @throws InvalidDataTypeException |
|
| 994 | - * @throws InvalidInterfaceException |
|
| 995 | - */ |
|
| 996 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
| 997 | - { |
|
| 998 | - // verify nonce against expected value |
|
| 999 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1000 | - // these are not the droids you are looking for !!! |
|
| 1001 | - $msg = sprintf( |
|
| 1002 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 1003 | - '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 1004 | - '</a>' |
|
| 1005 | - ); |
|
| 1006 | - if (WP_DEBUG) { |
|
| 1007 | - $msg .= "\n " |
|
| 1008 | - . sprintf( |
|
| 1009 | - esc_html__( |
|
| 1010 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 1011 | - 'event_espresso' |
|
| 1012 | - ), |
|
| 1013 | - EE_Admin_Page::class |
|
| 1014 | - ); |
|
| 1015 | - } |
|
| 1016 | - if (! defined('DOING_AJAX')) { |
|
| 1017 | - wp_die($msg); |
|
| 1018 | - } else { |
|
| 1019 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1020 | - $this->_return_json(); |
|
| 1021 | - } |
|
| 1022 | - } |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * _route_admin_request() |
|
| 1028 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if there are |
|
| 1029 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 1030 | - * in the page routes and then will try to load the corresponding method. |
|
| 1031 | - * |
|
| 1032 | - * @return void |
|
| 1033 | - * @throws EE_Error |
|
| 1034 | - * @throws InvalidArgumentException |
|
| 1035 | - * @throws InvalidDataTypeException |
|
| 1036 | - * @throws InvalidInterfaceException |
|
| 1037 | - * @throws ReflectionException |
|
| 1038 | - */ |
|
| 1039 | - protected function _route_admin_request() |
|
| 1040 | - { |
|
| 1041 | - if (! $this->_is_UI_request) { |
|
| 1042 | - $this->_verify_routes(); |
|
| 1043 | - } |
|
| 1044 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 1045 | - ? $this->_route_config['require_nonce'] |
|
| 1046 | - : true; |
|
| 1047 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1048 | - // set nonce from post data |
|
| 1049 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 1050 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 1051 | - : ''; |
|
| 1052 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1053 | - } |
|
| 1054 | - // set the nav_tabs array but ONLY if this is UI_request |
|
| 1055 | - if ($this->_is_UI_request) { |
|
| 1056 | - $this->_set_nav_tabs(); |
|
| 1057 | - } |
|
| 1058 | - // grab callback function |
|
| 1059 | - $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route; |
|
| 1060 | - // check if callback has args |
|
| 1061 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 1062 | - $error_msg = ''; |
|
| 1063 | - // action right before calling route |
|
| 1064 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1065 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1066 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1067 | - } |
|
| 1068 | - // right before calling the route, let's remove _wp_http_referer from the |
|
| 1069 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 1070 | - $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 1071 | - '_wp_http_referer', |
|
| 1072 | - wp_unslash($_SERVER['REQUEST_URI']) |
|
| 1073 | - ); |
|
| 1074 | - if (! empty($func)) { |
|
| 1075 | - if (is_array($func)) { |
|
| 1076 | - [$class, $method] = $func; |
|
| 1077 | - } elseif (strpos($func, '::') !== false) { |
|
| 1078 | - [$class, $method] = explode('::', $func); |
|
| 1079 | - } else { |
|
| 1080 | - $class = $this; |
|
| 1081 | - $method = $func; |
|
| 1082 | - } |
|
| 1083 | - if (! (is_object($class) && $class === $this)) { |
|
| 1084 | - // send along this admin page object for access by addons. |
|
| 1085 | - $args['admin_page_object'] = $this; |
|
| 1086 | - } |
|
| 1087 | - // is it a method on a class that doesn't work? |
|
| 1088 | - if ( |
|
| 1089 | - ((method_exists($class, $method) |
|
| 1090 | - && call_user_func_array(array($class, $method), $args) === false) |
|
| 1091 | - && (// is it a standalone function that doesn't work? |
|
| 1092 | - function_exists($method) |
|
| 1093 | - && call_user_func_array( |
|
| 1094 | - $func, |
|
| 1095 | - array_merge(array('admin_page_object' => $this), $args) |
|
| 1096 | - ) === false |
|
| 1097 | - )) || (// is it neither a class method NOR a standalone function? |
|
| 1098 | - ! function_exists($method) |
|
| 1099 | - && ! method_exists($class, $method) |
|
| 1100 | - ) |
|
| 1101 | - ) { |
|
| 1102 | - // user error msg |
|
| 1103 | - $error_msg = esc_html__( |
|
| 1104 | - 'An error occurred. The requested page route could not be found.', |
|
| 1105 | - 'event_espresso' |
|
| 1106 | - ); |
|
| 1107 | - // developer error msg |
|
| 1108 | - $error_msg .= '||'; |
|
| 1109 | - $error_msg .= sprintf( |
|
| 1110 | - esc_html__( |
|
| 1111 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1112 | - 'event_espresso' |
|
| 1113 | - ), |
|
| 1114 | - $method |
|
| 1115 | - ); |
|
| 1116 | - } |
|
| 1117 | - if (! empty($error_msg)) { |
|
| 1118 | - throw new EE_Error($error_msg); |
|
| 1119 | - } |
|
| 1120 | - } |
|
| 1121 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1122 | - // then we need to reset the routing properties to the new route. |
|
| 1123 | - // 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. |
|
| 1124 | - if ( |
|
| 1125 | - $this->_is_UI_request === false |
|
| 1126 | - && is_array($this->_route) |
|
| 1127 | - && ! empty($this->_route['headers_sent_route']) |
|
| 1128 | - ) { |
|
| 1129 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * This method just allows the resetting of page properties in the case where a no headers |
|
| 1136 | - * route redirects to a headers route in its route config. |
|
| 1137 | - * |
|
| 1138 | - * @since 4.3.0 |
|
| 1139 | - * @param string $new_route New (non header) route to redirect to. |
|
| 1140 | - * @return void |
|
| 1141 | - * @throws ReflectionException |
|
| 1142 | - * @throws InvalidArgumentException |
|
| 1143 | - * @throws InvalidInterfaceException |
|
| 1144 | - * @throws InvalidDataTypeException |
|
| 1145 | - * @throws EE_Error |
|
| 1146 | - */ |
|
| 1147 | - protected function _reset_routing_properties($new_route) |
|
| 1148 | - { |
|
| 1149 | - $this->_is_UI_request = true; |
|
| 1150 | - // now we set the current route to whatever the headers_sent_route is set at |
|
| 1151 | - $this->_req_data['action'] = $new_route; |
|
| 1152 | - // rerun page setup |
|
| 1153 | - $this->_page_setup(); |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * _add_query_arg |
|
| 1159 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1160 | - *(internally just uses EEH_URL's function with the same name) |
|
| 1161 | - * |
|
| 1162 | - * @param array $args |
|
| 1163 | - * @param string $url |
|
| 1164 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1165 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1166 | - * Example usage: If the current page is: |
|
| 1167 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1168 | - * &action=default&event_id=20&month_range=March%202015 |
|
| 1169 | - * &_wpnonce=5467821 |
|
| 1170 | - * and you call: |
|
| 1171 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1172 | - * array( |
|
| 1173 | - * 'action' => 'resend_something', |
|
| 1174 | - * 'page=>espresso_registrations' |
|
| 1175 | - * ), |
|
| 1176 | - * $some_url, |
|
| 1177 | - * true |
|
| 1178 | - * ); |
|
| 1179 | - * It will produce a url in this structure: |
|
| 1180 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1181 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1182 | - * month_range]=March%202015 |
|
| 1183 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1184 | - * @return string |
|
| 1185 | - */ |
|
| 1186 | - public static function add_query_args_and_nonce( |
|
| 1187 | - $args = array(), |
|
| 1188 | - $url = '', |
|
| 1189 | - $sticky = false, |
|
| 1190 | - $exclude_nonce = false |
|
| 1191 | - ) { |
|
| 1192 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1193 | - if ($sticky) { |
|
| 1194 | - $request = $_REQUEST; |
|
| 1195 | - unset($request['_wp_http_referer'], $request['wp_referer']); |
|
| 1196 | - foreach ($request as $key => $value) { |
|
| 1197 | - // do not add nonces |
|
| 1198 | - if (strpos($key, 'nonce') !== false) { |
|
| 1199 | - continue; |
|
| 1200 | - } |
|
| 1201 | - $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1202 | - } |
|
| 1203 | - } |
|
| 1204 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * This returns a generated link that will load the related help tab. |
|
| 1210 | - * |
|
| 1211 | - * @param string $help_tab_id the id for the connected help tab |
|
| 1212 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1213 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1214 | - * @uses EEH_Template::get_help_tab_link() |
|
| 1215 | - * @return string generated link |
|
| 1216 | - */ |
|
| 1217 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1218 | - { |
|
| 1219 | - return EEH_Template::get_help_tab_link( |
|
| 1220 | - $help_tab_id, |
|
| 1221 | - $this->page_slug, |
|
| 1222 | - $this->_req_action, |
|
| 1223 | - $icon_style, |
|
| 1224 | - $help_text |
|
| 1225 | - ); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * _add_help_tabs |
|
| 1231 | - * Note child classes define their help tabs within the page_config array. |
|
| 1232 | - * |
|
| 1233 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1234 | - * @return void |
|
| 1235 | - * @throws DomainException |
|
| 1236 | - * @throws EE_Error |
|
| 1237 | - * @throws ReflectionException |
|
| 1238 | - */ |
|
| 1239 | - protected function _add_help_tabs() |
|
| 1240 | - { |
|
| 1241 | - $tour_buttons = ''; |
|
| 1242 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1243 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1244 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1245 | - // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1246 | - // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1247 | - // $tb = array(); |
|
| 1248 | - // $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1249 | - // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1250 | - // // if this is the end tour then we don't need to setup a button |
|
| 1251 | - // if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1252 | - // continue; |
|
| 1253 | - // } |
|
| 1254 | - // $tb[] = '<button id="trigger-tour-' |
|
| 1255 | - // . $tour->get_slug() |
|
| 1256 | - // . '" class="button-primary trigger-ee-help-tour">' |
|
| 1257 | - // . $tour->get_label() |
|
| 1258 | - // . '</button>'; |
|
| 1259 | - // } |
|
| 1260 | - // $tour_buttons .= implode('<br />', $tb); |
|
| 1261 | - // $tour_buttons .= '</div></div>'; |
|
| 1262 | - // } |
|
| 1263 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1264 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1265 | - // check that the callback given is valid |
|
| 1266 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1267 | - throw new EE_Error( |
|
| 1268 | - sprintf( |
|
| 1269 | - esc_html__( |
|
| 1270 | - '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', |
|
| 1271 | - 'event_espresso' |
|
| 1272 | - ), |
|
| 1273 | - $config['help_sidebar'], |
|
| 1274 | - get_class($this) |
|
| 1275 | - ) |
|
| 1276 | - ); |
|
| 1277 | - } |
|
| 1278 | - $content = apply_filters( |
|
| 1279 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1280 | - $this->{$config['help_sidebar']}() |
|
| 1281 | - ); |
|
| 1282 | - $content .= $tour_buttons; // add help tour buttons. |
|
| 1283 | - // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1284 | - $this->_current_screen->set_help_sidebar($content); |
|
| 1285 | - } |
|
| 1286 | - // if there ARE tour buttons... |
|
| 1287 | - if (! empty($tour_buttons)) { |
|
| 1288 | - // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar. |
|
| 1289 | - if (! isset($config['help_sidebar'])) { |
|
| 1290 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1291 | - } |
|
| 1292 | - // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1293 | - if (! isset($config['help_tabs'])) { |
|
| 1294 | - $_ht['id'] = $this->page_slug; |
|
| 1295 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1296 | - $_ht['content'] = '<p>' |
|
| 1297 | - . esc_html__( |
|
| 1298 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1299 | - 'event_espresso' |
|
| 1300 | - ) . '</p>'; |
|
| 1301 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1304 | - if (! isset($config['help_tabs'])) { |
|
| 1305 | - return; |
|
| 1306 | - } //no help tabs for this route |
|
| 1307 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1308 | - // we're here so there ARE help tabs! |
|
| 1309 | - // make sure we've got what we need |
|
| 1310 | - if (! isset($cfg['title'])) { |
|
| 1311 | - throw new EE_Error( |
|
| 1312 | - esc_html__( |
|
| 1313 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1314 | - 'event_espresso' |
|
| 1315 | - ) |
|
| 1316 | - ); |
|
| 1317 | - } |
|
| 1318 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1319 | - throw new EE_Error( |
|
| 1320 | - esc_html__( |
|
| 1321 | - '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', |
|
| 1322 | - 'event_espresso' |
|
| 1323 | - ) |
|
| 1324 | - ); |
|
| 1325 | - } |
|
| 1326 | - // first priority goes to content. |
|
| 1327 | - if (! empty($cfg['content'])) { |
|
| 1328 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1329 | - // second priority goes to filename |
|
| 1330 | - } elseif (! empty($cfg['filename'])) { |
|
| 1331 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1332 | - // 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) |
|
| 1333 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1334 | - . basename($this->_get_dir()) |
|
| 1335 | - . '/help_tabs/' |
|
| 1336 | - . $cfg['filename'] |
|
| 1337 | - . '.help_tab.php' : $file_path; |
|
| 1338 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1339 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1340 | - EE_Error::add_error( |
|
| 1341 | - sprintf( |
|
| 1342 | - esc_html__( |
|
| 1343 | - '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', |
|
| 1344 | - 'event_espresso' |
|
| 1345 | - ), |
|
| 1346 | - $tab_id, |
|
| 1347 | - key($config), |
|
| 1348 | - $file_path |
|
| 1349 | - ), |
|
| 1350 | - __FILE__, |
|
| 1351 | - __FUNCTION__, |
|
| 1352 | - __LINE__ |
|
| 1353 | - ); |
|
| 1354 | - return; |
|
| 1355 | - } |
|
| 1356 | - $template_args['admin_page_obj'] = $this; |
|
| 1357 | - $content = EEH_Template::display_template( |
|
| 1358 | - $file_path, |
|
| 1359 | - $template_args, |
|
| 1360 | - true |
|
| 1361 | - ); |
|
| 1362 | - } else { |
|
| 1363 | - $content = ''; |
|
| 1364 | - } |
|
| 1365 | - // check if callback is valid |
|
| 1366 | - if ( |
|
| 1367 | - empty($content) && ( |
|
| 1368 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1369 | - ) |
|
| 1370 | - ) { |
|
| 1371 | - EE_Error::add_error( |
|
| 1372 | - sprintf( |
|
| 1373 | - esc_html__( |
|
| 1374 | - '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.', |
|
| 1375 | - 'event_espresso' |
|
| 1376 | - ), |
|
| 1377 | - $cfg['title'] |
|
| 1378 | - ), |
|
| 1379 | - __FILE__, |
|
| 1380 | - __FUNCTION__, |
|
| 1381 | - __LINE__ |
|
| 1382 | - ); |
|
| 1383 | - return; |
|
| 1384 | - } |
|
| 1385 | - // setup config array for help tab method |
|
| 1386 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1387 | - $_ht = array( |
|
| 1388 | - 'id' => $id, |
|
| 1389 | - 'title' => $cfg['title'], |
|
| 1390 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1391 | - 'content' => $content, |
|
| 1392 | - ); |
|
| 1393 | - $this->_current_screen->add_help_tab($_ht); |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - |
|
| 1399 | - /** |
|
| 1400 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1401 | - * an array with properties for setting up usage of the joyride plugin |
|
| 1402 | - * |
|
| 1403 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1404 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1405 | - * _set_page_config() comments |
|
| 1406 | - * @return void |
|
| 1407 | - * @throws EE_Error |
|
| 1408 | - * @throws InvalidArgumentException |
|
| 1409 | - * @throws InvalidDataTypeException |
|
| 1410 | - * @throws InvalidInterfaceException |
|
| 1411 | - * @throws ReflectionException |
|
| 1412 | - */ |
|
| 1413 | - protected function _add_help_tour() |
|
| 1414 | - { |
|
| 1415 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1416 | - // $tours = array(); |
|
| 1417 | - // $this->_help_tour = array(); |
|
| 1418 | - // // exit early if help tours are turned off globally |
|
| 1419 | - // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1420 | - // || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1421 | - // ) { |
|
| 1422 | - // return; |
|
| 1423 | - // } |
|
| 1424 | - // // loop through _page_config to find any help_tour defined |
|
| 1425 | - // foreach ($this->_page_config as $route => $config) { |
|
| 1426 | - // // we're only going to set things up for this route |
|
| 1427 | - // if ($route !== $this->_req_action) { |
|
| 1428 | - // continue; |
|
| 1429 | - // } |
|
| 1430 | - // if (isset($config['help_tour'])) { |
|
| 1431 | - // foreach ($config['help_tour'] as $tour) { |
|
| 1432 | - // $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1433 | - // // let's see if we can get that file... |
|
| 1434 | - // // if not its possible this is a decaf route not set in caffeinated |
|
| 1435 | - // // so lets try and get the caffeinated equivalent |
|
| 1436 | - // $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1437 | - // . basename($this->_get_dir()) |
|
| 1438 | - // . '/help_tours/' |
|
| 1439 | - // . $tour |
|
| 1440 | - // . '.class.php' : $file_path; |
|
| 1441 | - // // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1442 | - // if (! is_readable($file_path)) { |
|
| 1443 | - // EE_Error::add_error( |
|
| 1444 | - // sprintf( |
|
| 1445 | - // esc_html__( |
|
| 1446 | - // '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', |
|
| 1447 | - // 'event_espresso' |
|
| 1448 | - // ), |
|
| 1449 | - // $file_path, |
|
| 1450 | - // $tour |
|
| 1451 | - // ), |
|
| 1452 | - // __FILE__, |
|
| 1453 | - // __FUNCTION__, |
|
| 1454 | - // __LINE__ |
|
| 1455 | - // ); |
|
| 1456 | - // return; |
|
| 1457 | - // } |
|
| 1458 | - // require_once $file_path; |
|
| 1459 | - // if (! class_exists($tour)) { |
|
| 1460 | - // $error_msg[] = sprintf( |
|
| 1461 | - // esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1462 | - // $tour |
|
| 1463 | - // ); |
|
| 1464 | - // $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1465 | - // . sprintf( |
|
| 1466 | - // esc_html__( |
|
| 1467 | - // '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.', |
|
| 1468 | - // 'event_espresso' |
|
| 1469 | - // ), |
|
| 1470 | - // $tour, |
|
| 1471 | - // '<br />', |
|
| 1472 | - // $tour, |
|
| 1473 | - // $this->_req_action, |
|
| 1474 | - // get_class($this) |
|
| 1475 | - // ); |
|
| 1476 | - // throw new EE_Error(implode('||', $error_msg)); |
|
| 1477 | - // } |
|
| 1478 | - // $tour_obj = new $tour($this->_is_caf); |
|
| 1479 | - // $tours[] = $tour_obj; |
|
| 1480 | - // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1481 | - // } |
|
| 1482 | - // // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1483 | - // $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1484 | - // $tours[] = $end_stop_tour; |
|
| 1485 | - // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1486 | - // } |
|
| 1487 | - // } |
|
| 1488 | - // |
|
| 1489 | - // if (! empty($tours)) { |
|
| 1490 | - // $this->_help_tour['tours'] = $tours; |
|
| 1491 | - // } |
|
| 1492 | - // // that's it! Now that the $_help_tours property is set (or not) |
|
| 1493 | - // // the scripts and html should be taken care of automatically. |
|
| 1494 | - // |
|
| 1495 | - // /** |
|
| 1496 | - // * Allow extending the help tours variable. |
|
| 1497 | - // * |
|
| 1498 | - // * @param Array $_help_tour The array containing all help tour information to be displayed. |
|
| 1499 | - // */ |
|
| 1500 | - // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour); |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - |
|
| 1504 | - /** |
|
| 1505 | - * This simply sets up any qtips that have been defined in the page config |
|
| 1506 | - * |
|
| 1507 | - * @return void |
|
| 1508 | - * @throws ReflectionException |
|
| 1509 | - * @throws EE_Error |
|
| 1510 | - */ |
|
| 1511 | - protected function _add_qtips() |
|
| 1512 | - { |
|
| 1513 | - if (isset($this->_route_config['qtips'])) { |
|
| 1514 | - $qtips = (array) $this->_route_config['qtips']; |
|
| 1515 | - // load qtip loader |
|
| 1516 | - $path = array( |
|
| 1517 | - $this->_get_dir() . '/qtips/', |
|
| 1518 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1519 | - ); |
|
| 1520 | - $qtip_loader = EEH_Qtip_Loader::instance(); |
|
| 1521 | - if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
| 1522 | - $qtip_loader->register($qtips, $path); |
|
| 1523 | - } |
|
| 1524 | - } |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - |
|
| 1528 | - /** |
|
| 1529 | - * _set_nav_tabs |
|
| 1530 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1531 | - * wish to add additional tabs or modify accordingly. |
|
| 1532 | - * |
|
| 1533 | - * @return void |
|
| 1534 | - * @throws InvalidArgumentException |
|
| 1535 | - * @throws InvalidInterfaceException |
|
| 1536 | - * @throws InvalidDataTypeException |
|
| 1537 | - */ |
|
| 1538 | - protected function _set_nav_tabs() |
|
| 1539 | - { |
|
| 1540 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1541 | - $i = 0; |
|
| 1542 | - foreach ($this->_page_config as $slug => $config) { |
|
| 1543 | - if ( |
|
| 1544 | - ! is_array($config) |
|
| 1545 | - || ( |
|
| 1546 | - is_array($config) |
|
| 1547 | - && ( |
|
| 1548 | - (isset($config['nav']) && ! $config['nav']) |
|
| 1549 | - || ! isset($config['nav']) |
|
| 1550 | - ) |
|
| 1551 | - ) |
|
| 1552 | - ) { |
|
| 1553 | - continue; |
|
| 1554 | - } |
|
| 1555 | - // no nav tab for this config |
|
| 1556 | - // check for persistent flag |
|
| 1557 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1558 | - // nav tab is only to appear when route requested. |
|
| 1559 | - continue; |
|
| 1560 | - } |
|
| 1561 | - if (! $this->check_user_access($slug, true)) { |
|
| 1562 | - // no nav tab because current user does not have access. |
|
| 1563 | - continue; |
|
| 1564 | - } |
|
| 1565 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1566 | - $this->_nav_tabs[ $slug ] = array( |
|
| 1567 | - 'url' => isset($config['nav']['url']) |
|
| 1568 | - ? $config['nav']['url'] |
|
| 1569 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1570 | - array('action' => $slug), |
|
| 1571 | - $this->_admin_base_url |
|
| 1572 | - ), |
|
| 1573 | - 'link_text' => isset($config['nav']['label']) |
|
| 1574 | - ? $config['nav']['label'] |
|
| 1575 | - : ucwords( |
|
| 1576 | - str_replace('_', ' ', $slug) |
|
| 1577 | - ), |
|
| 1578 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1579 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1580 | - ); |
|
| 1581 | - $i++; |
|
| 1582 | - } |
|
| 1583 | - // if $this->_nav_tabs is empty then lets set the default |
|
| 1584 | - if (empty($this->_nav_tabs)) { |
|
| 1585 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1586 | - 'url' => $this->_admin_base_url, |
|
| 1587 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1588 | - 'css_class' => 'nav-tab-active', |
|
| 1589 | - 'order' => 10, |
|
| 1590 | - ); |
|
| 1591 | - } |
|
| 1592 | - // now let's sort the tabs according to order |
|
| 1593 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - |
|
| 1597 | - /** |
|
| 1598 | - * _set_current_labels |
|
| 1599 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1600 | - * property array |
|
| 1601 | - * |
|
| 1602 | - * @return void |
|
| 1603 | - */ |
|
| 1604 | - private function _set_current_labels() |
|
| 1605 | - { |
|
| 1606 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1607 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1608 | - if (is_array($text)) { |
|
| 1609 | - foreach ($text as $sublabel => $subtext) { |
|
| 1610 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1611 | - } |
|
| 1612 | - } else { |
|
| 1613 | - $this->_labels[ $label ] = $text; |
|
| 1614 | - } |
|
| 1615 | - } |
|
| 1616 | - } |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - |
|
| 1620 | - /** |
|
| 1621 | - * verifies user access for this admin page |
|
| 1622 | - * |
|
| 1623 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1624 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1625 | - * return false if verify fail. |
|
| 1626 | - * @return bool |
|
| 1627 | - * @throws InvalidArgumentException |
|
| 1628 | - * @throws InvalidDataTypeException |
|
| 1629 | - * @throws InvalidInterfaceException |
|
| 1630 | - */ |
|
| 1631 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1632 | - { |
|
| 1633 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1634 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1635 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1636 | - && is_array( |
|
| 1637 | - $this->_page_routes[ $route_to_check ] |
|
| 1638 | - ) |
|
| 1639 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1640 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1641 | - if (empty($capability) && empty($route_to_check)) { |
|
| 1642 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1643 | - : $this->_route['capability']; |
|
| 1644 | - } else { |
|
| 1645 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1646 | - } |
|
| 1647 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1648 | - if ( |
|
| 1649 | - ! defined('DOING_AJAX') |
|
| 1650 | - && ( |
|
| 1651 | - ! function_exists('is_admin') |
|
| 1652 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1653 | - $capability, |
|
| 1654 | - $this->page_slug |
|
| 1655 | - . '_' |
|
| 1656 | - . $route_to_check, |
|
| 1657 | - $id |
|
| 1658 | - ) |
|
| 1659 | - ) |
|
| 1660 | - ) { |
|
| 1661 | - if ($verify_only) { |
|
| 1662 | - return false; |
|
| 1663 | - } |
|
| 1664 | - if (is_user_logged_in()) { |
|
| 1665 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1666 | - } else { |
|
| 1667 | - return false; |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - return true; |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - |
|
| 1674 | - /** |
|
| 1675 | - * admin_init_global |
|
| 1676 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1677 | - * This method executes for ALL EE Admin pages. |
|
| 1678 | - * |
|
| 1679 | - * @return void |
|
| 1680 | - */ |
|
| 1681 | - public function admin_init_global() |
|
| 1682 | - { |
|
| 1683 | - } |
|
| 1684 | - |
|
| 1685 | - |
|
| 1686 | - /** |
|
| 1687 | - * wp_loaded_global |
|
| 1688 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1689 | - * EE_Admin page and will execute on every EE Admin Page load |
|
| 1690 | - * |
|
| 1691 | - * @return void |
|
| 1692 | - */ |
|
| 1693 | - public function wp_loaded() |
|
| 1694 | - { |
|
| 1695 | - } |
|
| 1696 | - |
|
| 1697 | - |
|
| 1698 | - /** |
|
| 1699 | - * admin_notices |
|
| 1700 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1701 | - * ALL EE_Admin pages. |
|
| 1702 | - * |
|
| 1703 | - * @return void |
|
| 1704 | - */ |
|
| 1705 | - public function admin_notices_global() |
|
| 1706 | - { |
|
| 1707 | - $this->_display_no_javascript_warning(); |
|
| 1708 | - $this->_display_espresso_notices(); |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - public function network_admin_notices_global() |
|
| 1713 | - { |
|
| 1714 | - $this->_display_no_javascript_warning(); |
|
| 1715 | - $this->_display_espresso_notices(); |
|
| 1716 | - } |
|
| 1717 | - |
|
| 1718 | - |
|
| 1719 | - /** |
|
| 1720 | - * admin_footer_scripts_global |
|
| 1721 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1722 | - * will apply on ALL EE_Admin pages. |
|
| 1723 | - * |
|
| 1724 | - * @return void |
|
| 1725 | - */ |
|
| 1726 | - public function admin_footer_scripts_global() |
|
| 1727 | - { |
|
| 1728 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 1729 | - $this->_add_admin_page_overlay(); |
|
| 1730 | - // if metaboxes are present we need to add the nonce field |
|
| 1731 | - if ( |
|
| 1732 | - isset($this->_route_config['metaboxes']) |
|
| 1733 | - || isset($this->_route_config['list_table']) |
|
| 1734 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1735 | - ) { |
|
| 1736 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1737 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1738 | - } |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - |
|
| 1742 | - /** |
|
| 1743 | - * admin_footer_global |
|
| 1744 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. |
|
| 1745 | - * This particular method will apply on ALL EE_Admin Pages. |
|
| 1746 | - * |
|
| 1747 | - * @return void |
|
| 1748 | - * @throws InvalidArgumentException |
|
| 1749 | - * @throws InvalidDataTypeException |
|
| 1750 | - * @throws InvalidInterfaceException |
|
| 1751 | - */ |
|
| 1752 | - public function admin_footer_global() |
|
| 1753 | - { |
|
| 1754 | - // dialog container for dialog helper |
|
| 1755 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1756 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1757 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1758 | - $d_cont .= '</div>'; |
|
| 1759 | - echo $d_cont; |
|
| 1760 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1761 | - // help tour stuff? |
|
| 1762 | - // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1763 | - // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1764 | - // } |
|
| 1765 | - // current set timezone for timezone js |
|
| 1766 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - |
|
| 1770 | - /** |
|
| 1771 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1772 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1773 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1774 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1775 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1776 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1777 | - * for the |
|
| 1778 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1779 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1780 | - * 'help_trigger_id' => array( |
|
| 1781 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1782 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1783 | - * ) |
|
| 1784 | - * ); |
|
| 1785 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1786 | - * |
|
| 1787 | - * @param array $help_array |
|
| 1788 | - * @param bool $display |
|
| 1789 | - * @return string content |
|
| 1790 | - * @throws DomainException |
|
| 1791 | - * @throws EE_Error |
|
| 1792 | - */ |
|
| 1793 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1794 | - { |
|
| 1795 | - $content = ''; |
|
| 1796 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1797 | - // loop through the array and setup content |
|
| 1798 | - foreach ($help_array as $trigger => $help) { |
|
| 1799 | - // make sure the array is setup properly |
|
| 1800 | - if (! isset($help['title'], $help['content'])) { |
|
| 1801 | - throw new EE_Error( |
|
| 1802 | - esc_html__( |
|
| 1803 | - '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', |
|
| 1804 | - 'event_espresso' |
|
| 1805 | - ) |
|
| 1806 | - ); |
|
| 1807 | - } |
|
| 1808 | - // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1809 | - $template_args = array( |
|
| 1810 | - 'help_popup_id' => $trigger, |
|
| 1811 | - 'help_popup_title' => $help['title'], |
|
| 1812 | - 'help_popup_content' => $help['content'], |
|
| 1813 | - ); |
|
| 1814 | - $content .= EEH_Template::display_template( |
|
| 1815 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1816 | - $template_args, |
|
| 1817 | - true |
|
| 1818 | - ); |
|
| 1819 | - } |
|
| 1820 | - if ($display) { |
|
| 1821 | - echo $content; |
|
| 1822 | - return ''; |
|
| 1823 | - } |
|
| 1824 | - return $content; |
|
| 1825 | - } |
|
| 1826 | - |
|
| 1827 | - |
|
| 1828 | - /** |
|
| 1829 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1830 | - * |
|
| 1831 | - * @return array properly formatted array for help popup content |
|
| 1832 | - * @throws EE_Error |
|
| 1833 | - */ |
|
| 1834 | - private function _get_help_content() |
|
| 1835 | - { |
|
| 1836 | - // what is the method we're looking for? |
|
| 1837 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1838 | - // if method doesn't exist let's get out. |
|
| 1839 | - if (! method_exists($this, $method_name)) { |
|
| 1840 | - return array(); |
|
| 1841 | - } |
|
| 1842 | - // k we're good to go let's retrieve the help array |
|
| 1843 | - $help_array = $this->{$method_name}(); |
|
| 1844 | - // make sure we've got an array! |
|
| 1845 | - if (! is_array($help_array)) { |
|
| 1846 | - throw new EE_Error( |
|
| 1847 | - esc_html__( |
|
| 1848 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1849 | - 'event_espresso' |
|
| 1850 | - ) |
|
| 1851 | - ); |
|
| 1852 | - } |
|
| 1853 | - return $help_array; |
|
| 1854 | - } |
|
| 1855 | - |
|
| 1856 | - |
|
| 1857 | - /** |
|
| 1858 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1859 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1860 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1861 | - * |
|
| 1862 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1863 | - * @param boolean $display if false then we return the trigger string |
|
| 1864 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1865 | - * @return string |
|
| 1866 | - * @throws DomainException |
|
| 1867 | - * @throws EE_Error |
|
| 1868 | - */ |
|
| 1869 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1870 | - { |
|
| 1871 | - if (defined('DOING_AJAX')) { |
|
| 1872 | - return ''; |
|
| 1873 | - } |
|
| 1874 | - // 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 |
|
| 1875 | - $help_array = $this->_get_help_content(); |
|
| 1876 | - $help_content = ''; |
|
| 1877 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1878 | - $help_array[ $trigger_id ] = array( |
|
| 1879 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1880 | - 'content' => esc_html__( |
|
| 1881 | - '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.)', |
|
| 1882 | - 'event_espresso' |
|
| 1883 | - ), |
|
| 1884 | - ); |
|
| 1885 | - $help_content = $this->_set_help_popup_content($help_array); |
|
| 1886 | - } |
|
| 1887 | - // let's setup the trigger |
|
| 1888 | - $content = '<a class="ee-dialog" href="?height=' |
|
| 1889 | - . $dimensions[0] |
|
| 1890 | - . '&width=' |
|
| 1891 | - . $dimensions[1] |
|
| 1892 | - . '&inlineId=' |
|
| 1893 | - . $trigger_id |
|
| 1894 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1895 | - $content .= $help_content; |
|
| 1896 | - if ($display) { |
|
| 1897 | - echo $content; |
|
| 1898 | - return ''; |
|
| 1899 | - } |
|
| 1900 | - return $content; |
|
| 1901 | - } |
|
| 1902 | - |
|
| 1903 | - |
|
| 1904 | - /** |
|
| 1905 | - * _add_global_screen_options |
|
| 1906 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1907 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1908 | - * |
|
| 1909 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1910 | - * see also WP_Screen object documents... |
|
| 1911 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1912 | - * @abstract |
|
| 1913 | - * @return void |
|
| 1914 | - */ |
|
| 1915 | - private function _add_global_screen_options() |
|
| 1916 | - { |
|
| 1917 | - } |
|
| 1918 | - |
|
| 1919 | - |
|
| 1920 | - /** |
|
| 1921 | - * _add_global_feature_pointers |
|
| 1922 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1923 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1924 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1925 | - * |
|
| 1926 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1927 | - * extended) also see: |
|
| 1928 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1929 | - * @abstract |
|
| 1930 | - * @return void |
|
| 1931 | - */ |
|
| 1932 | - private function _add_global_feature_pointers() |
|
| 1933 | - { |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - |
|
| 1937 | - /** |
|
| 1938 | - * load_global_scripts_styles |
|
| 1939 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1940 | - * |
|
| 1941 | - * @return void |
|
| 1942 | - * @throws EE_Error |
|
| 1943 | - */ |
|
| 1944 | - public function load_global_scripts_styles() |
|
| 1945 | - { |
|
| 1946 | - // add debugging styles |
|
| 1947 | - if (WP_DEBUG) { |
|
| 1948 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1949 | - } |
|
| 1950 | - // taking care of metaboxes |
|
| 1951 | - if ( |
|
| 1952 | - empty($this->_cpt_route) |
|
| 1953 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1954 | - ) { |
|
| 1955 | - wp_enqueue_script('dashboard'); |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - // LOCALIZED DATA |
|
| 1959 | - // localize script for ajax lazy loading |
|
| 1960 | - wp_localize_script( |
|
| 1961 | - EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 1962 | - 'eeLazyLoadingContainers', |
|
| 1963 | - apply_filters( |
|
| 1964 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1965 | - ['espresso_news_post_box_content'] |
|
| 1966 | - ) |
|
| 1967 | - ); |
|
| 1968 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1969 | - // /** |
|
| 1970 | - // * help tour stuff |
|
| 1971 | - // */ |
|
| 1972 | - // if (! empty($this->_help_tour)) { |
|
| 1973 | - // // register the js for kicking things off |
|
| 1974 | - // wp_enqueue_script( |
|
| 1975 | - // 'ee-help-tour', |
|
| 1976 | - // EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 1977 | - // array('jquery-joyride'), |
|
| 1978 | - // EVENT_ESPRESSO_VERSION, |
|
| 1979 | - // true |
|
| 1980 | - // ); |
|
| 1981 | - // $tours = array(); |
|
| 1982 | - // // setup tours for the js tour object |
|
| 1983 | - // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1984 | - // if ($tour instanceof EE_Help_Tour) { |
|
| 1985 | - // $tours[] = array( |
|
| 1986 | - // 'id' => $tour->get_slug(), |
|
| 1987 | - // 'options' => $tour->get_options(), |
|
| 1988 | - // ); |
|
| 1989 | - // } |
|
| 1990 | - // } |
|
| 1991 | - // wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1992 | - // // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1993 | - // } |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - |
|
| 1997 | - /** |
|
| 1998 | - * admin_footer_scripts_eei18n_js_strings |
|
| 1999 | - * |
|
| 2000 | - * @return void |
|
| 2001 | - */ |
|
| 2002 | - public function admin_footer_scripts_eei18n_js_strings() |
|
| 2003 | - { |
|
| 2004 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2005 | - EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2006 | - '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!!!', |
|
| 2007 | - 'event_espresso' |
|
| 2008 | - ); |
|
| 2009 | - EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2010 | - EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2011 | - EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2012 | - EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2013 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2014 | - EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2015 | - EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2016 | - EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2017 | - EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2018 | - EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2019 | - EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2020 | - EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2021 | - EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2022 | - EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2023 | - EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2024 | - EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2025 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2026 | - EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2027 | - EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2028 | - EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2029 | - EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2030 | - EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2031 | - EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2032 | - EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2033 | - EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2034 | - EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2035 | - EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2036 | - EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2037 | - EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2038 | - EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2039 | - EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2040 | - EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2041 | - EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2042 | - EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2043 | - EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2044 | - EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2045 | - EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2046 | - EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2047 | - } |
|
| 2048 | - |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2052 | - * |
|
| 2053 | - * @return void |
|
| 2054 | - */ |
|
| 2055 | - public function add_xdebug_style() |
|
| 2056 | - { |
|
| 2057 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2058 | - } |
|
| 2059 | - |
|
| 2060 | - |
|
| 2061 | - /************************/ |
|
| 2062 | - /** LIST TABLE METHODS **/ |
|
| 2063 | - /************************/ |
|
| 2064 | - /** |
|
| 2065 | - * this sets up the list table if the current view requires it. |
|
| 2066 | - * |
|
| 2067 | - * @return void |
|
| 2068 | - * @throws EE_Error |
|
| 2069 | - * @throws InvalidArgumentException |
|
| 2070 | - * @throws InvalidDataTypeException |
|
| 2071 | - * @throws InvalidInterfaceException |
|
| 2072 | - */ |
|
| 2073 | - protected function _set_list_table() |
|
| 2074 | - { |
|
| 2075 | - // first is this a list_table view? |
|
| 2076 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2077 | - return; |
|
| 2078 | - } //not a list_table view so get out. |
|
| 2079 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2080 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2081 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2082 | - // user error msg |
|
| 2083 | - $error_msg = esc_html__( |
|
| 2084 | - 'An error occurred. The requested list table views could not be found.', |
|
| 2085 | - 'event_espresso' |
|
| 2086 | - ); |
|
| 2087 | - // developer error msg |
|
| 2088 | - $error_msg .= '||' |
|
| 2089 | - . sprintf( |
|
| 2090 | - esc_html__( |
|
| 2091 | - '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.', |
|
| 2092 | - 'event_espresso' |
|
| 2093 | - ), |
|
| 2094 | - $this->_req_action, |
|
| 2095 | - $list_table_view |
|
| 2096 | - ); |
|
| 2097 | - throw new EE_Error($error_msg); |
|
| 2098 | - } |
|
| 2099 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2100 | - $this->_views = apply_filters( |
|
| 2101 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2102 | - $this->_views |
|
| 2103 | - ); |
|
| 2104 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2105 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2106 | - $this->_set_list_table_view(); |
|
| 2107 | - $this->_set_list_table_object(); |
|
| 2108 | - } |
|
| 2109 | - |
|
| 2110 | - |
|
| 2111 | - /** |
|
| 2112 | - * set current view for List Table |
|
| 2113 | - * |
|
| 2114 | - * @return void |
|
| 2115 | - */ |
|
| 2116 | - protected function _set_list_table_view() |
|
| 2117 | - { |
|
| 2118 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2119 | - // looking at active items or dumpster diving ? |
|
| 2120 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2121 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2122 | - } else { |
|
| 2123 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2124 | - } |
|
| 2125 | - } |
|
| 2126 | - |
|
| 2127 | - |
|
| 2128 | - /** |
|
| 2129 | - * _set_list_table_object |
|
| 2130 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2131 | - * |
|
| 2132 | - * @throws InvalidInterfaceException |
|
| 2133 | - * @throws InvalidArgumentException |
|
| 2134 | - * @throws InvalidDataTypeException |
|
| 2135 | - * @throws EE_Error |
|
| 2136 | - * @throws InvalidInterfaceException |
|
| 2137 | - */ |
|
| 2138 | - protected function _set_list_table_object() |
|
| 2139 | - { |
|
| 2140 | - if (isset($this->_route_config['list_table'])) { |
|
| 2141 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2142 | - throw new EE_Error( |
|
| 2143 | - sprintf( |
|
| 2144 | - esc_html__( |
|
| 2145 | - '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.', |
|
| 2146 | - 'event_espresso' |
|
| 2147 | - ), |
|
| 2148 | - $this->_route_config['list_table'], |
|
| 2149 | - get_class($this) |
|
| 2150 | - ) |
|
| 2151 | - ); |
|
| 2152 | - } |
|
| 2153 | - $this->_list_table_object = $this->loader->getShared( |
|
| 2154 | - $this->_route_config['list_table'], |
|
| 2155 | - array($this) |
|
| 2156 | - ); |
|
| 2157 | - } |
|
| 2158 | - } |
|
| 2159 | - |
|
| 2160 | - |
|
| 2161 | - /** |
|
| 2162 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2163 | - * |
|
| 2164 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2165 | - * urls. The array should be indexed by the view it is being |
|
| 2166 | - * added to. |
|
| 2167 | - * @return array |
|
| 2168 | - */ |
|
| 2169 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2170 | - { |
|
| 2171 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2172 | - if (empty($this->_views)) { |
|
| 2173 | - $this->_views = array(); |
|
| 2174 | - } |
|
| 2175 | - // cycle thru views |
|
| 2176 | - foreach ($this->_views as $key => $view) { |
|
| 2177 | - $query_args = array(); |
|
| 2178 | - // check for current view |
|
| 2179 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2180 | - $query_args['action'] = $this->_req_action; |
|
| 2181 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2182 | - $query_args['status'] = $view['slug']; |
|
| 2183 | - // merge any other arguments sent in. |
|
| 2184 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2185 | - foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2186 | - $query_args[] = $extra_query_arg; |
|
| 2187 | - } |
|
| 2188 | - } |
|
| 2189 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2190 | - } |
|
| 2191 | - return $this->_views; |
|
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - |
|
| 2195 | - /** |
|
| 2196 | - * _entries_per_page_dropdown |
|
| 2197 | - * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2198 | - * |
|
| 2199 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2200 | - * WP does it. |
|
| 2201 | - * @param int $max_entries total number of rows in the table |
|
| 2202 | - * @return string |
|
| 2203 | - */ |
|
| 2204 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2205 | - { |
|
| 2206 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2207 | - $values = array(10, 25, 50, 100); |
|
| 2208 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2209 | - if ($max_entries) { |
|
| 2210 | - $values[] = $max_entries; |
|
| 2211 | - sort($values); |
|
| 2212 | - } |
|
| 2213 | - $entries_per_page_dropdown = ' |
|
| 131 | + // sanitized request action (and nonce) |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @var string $_req_action |
|
| 135 | + */ |
|
| 136 | + protected $_req_action; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @var string $_req_nonce |
|
| 140 | + */ |
|
| 141 | + protected $_req_nonce; |
|
| 142 | + |
|
| 143 | + // search related |
|
| 144 | + protected $_search_btn_label; |
|
| 145 | + |
|
| 146 | + protected $_search_box_callback; |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * WP Current Screen object |
|
| 150 | + * |
|
| 151 | + * @var WP_Screen |
|
| 152 | + */ |
|
| 153 | + protected $_current_screen; |
|
| 154 | + |
|
| 155 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
| 156 | + protected $_hook_obj; |
|
| 157 | + |
|
| 158 | + // for holding incoming request data |
|
| 159 | + protected $_req_data = []; |
|
| 160 | + |
|
| 161 | + // yes / no array for admin form fields |
|
| 162 | + protected $_yes_no_values = array(); |
|
| 163 | + |
|
| 164 | + // some default things shared by all child classes |
|
| 165 | + protected $_default_espresso_metaboxes; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * EE_Registry Object |
|
| 169 | + * |
|
| 170 | + * @var EE_Registry |
|
| 171 | + */ |
|
| 172 | + protected $EE; |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
| 177 | + * |
|
| 178 | + * @var boolean |
|
| 179 | + */ |
|
| 180 | + protected $_is_caf = false; |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * whether or not initializePage() has run |
|
| 184 | + * |
|
| 185 | + * @var boolean |
|
| 186 | + */ |
|
| 187 | + protected $initialized = false; |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @var FeatureFlags |
|
| 191 | + */ |
|
| 192 | + protected $feature; |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @Constructor |
|
| 197 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
| 198 | + * @throws InvalidArgumentException |
|
| 199 | + * @throws InvalidDataTypeException |
|
| 200 | + * @throws InvalidInterfaceException |
|
| 201 | + * @throws ReflectionException |
|
| 202 | + */ |
|
| 203 | + public function __construct($routing = true) |
|
| 204 | + { |
|
| 205 | + $this->loader = LoaderFactory::getLoader(); |
|
| 206 | + $this->feature = $this->loader->getShared(FeatureFlags::class); |
|
| 207 | + $this->admin_config = $this->loader->getShared('EE_Admin_Config'); |
|
| 208 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
| 209 | + $this->_is_caf = true; |
|
| 210 | + } |
|
| 211 | + $this->_yes_no_values = array( |
|
| 212 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 213 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 214 | + ); |
|
| 215 | + // set the _req_data property. |
|
| 216 | + $this->_req_data = array_merge($_GET, $_POST); |
|
| 217 | + // routing enabled? |
|
| 218 | + $this->_routing = $routing; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * This logic used to be in the constructor, but that caused a chicken <--> egg scenario |
|
| 224 | + * for child classes that needed to set properties prior to these methods getting called, |
|
| 225 | + * but also needed the parent class to have its construction completed as well. |
|
| 226 | + * Bottom line is that constructors should ONLY be used for setting initial properties |
|
| 227 | + * and any complex initialization logic should only run after instantiation is complete. |
|
| 228 | + * |
|
| 229 | + * This method gets called immediately after construction from within |
|
| 230 | + * EE_Admin_Page_Init::_initialize_admin_page() |
|
| 231 | + * |
|
| 232 | + * @throws EE_Error |
|
| 233 | + * @throws InvalidArgumentException |
|
| 234 | + * @throws InvalidDataTypeException |
|
| 235 | + * @throws InvalidInterfaceException |
|
| 236 | + * @throws ReflectionException |
|
| 237 | + * @since $VID:$ |
|
| 238 | + */ |
|
| 239 | + public function initializePage() |
|
| 240 | + { |
|
| 241 | + if ($this->initialized) { |
|
| 242 | + return; |
|
| 243 | + } |
|
| 244 | + // set initial page props (child method) |
|
| 245 | + $this->_init_page_props(); |
|
| 246 | + // set global defaults |
|
| 247 | + $this->_set_defaults(); |
|
| 248 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
| 249 | + $this->_global_ajax_hooks(); |
|
| 250 | + $this->_ajax_hooks(); |
|
| 251 | + // other_page_hooks have to be early too. |
|
| 252 | + $this->_do_other_page_hooks(); |
|
| 253 | + // This just allows us to have extending classes do something specific |
|
| 254 | + // before the parent constructor runs _page_setup(). |
|
| 255 | + if (method_exists($this, '_before_page_setup')) { |
|
| 256 | + $this->_before_page_setup(); |
|
| 257 | + } |
|
| 258 | + // set up page dependencies |
|
| 259 | + $this->_page_setup(); |
|
| 260 | + $this->initialized = true; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * _init_page_props |
|
| 266 | + * Child classes use to set at least the following properties: |
|
| 267 | + * $page_slug. |
|
| 268 | + * $page_label. |
|
| 269 | + * |
|
| 270 | + * @abstract |
|
| 271 | + * @return void |
|
| 272 | + */ |
|
| 273 | + abstract protected function _init_page_props(); |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * _ajax_hooks |
|
| 278 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 279 | + * Note: within the ajax callback methods. |
|
| 280 | + * |
|
| 281 | + * @abstract |
|
| 282 | + * @return void |
|
| 283 | + */ |
|
| 284 | + abstract protected function _ajax_hooks(); |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * _define_page_props |
|
| 289 | + * child classes define page properties in here. Must include at least: |
|
| 290 | + * $_admin_base_url = base_url for all admin pages |
|
| 291 | + * $_admin_page_title = default admin_page_title for admin pages |
|
| 292 | + * $_labels = array of default labels for various automatically generated elements: |
|
| 293 | + * array( |
|
| 294 | + * 'buttons' => array( |
|
| 295 | + * 'add' => esc_html__('label for add new button'), |
|
| 296 | + * 'edit' => esc_html__('label for edit button'), |
|
| 297 | + * 'delete' => esc_html__('label for delete button') |
|
| 298 | + * ) |
|
| 299 | + * ) |
|
| 300 | + * |
|
| 301 | + * @abstract |
|
| 302 | + * @return void |
|
| 303 | + */ |
|
| 304 | + abstract protected function _define_page_props(); |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * _set_page_routes |
|
| 309 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
| 310 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
| 311 | + * have a 'default' route. Here's the format |
|
| 312 | + * $this->_page_routes = array( |
|
| 313 | + * 'default' => array( |
|
| 314 | + * 'func' => '_default_method_handling_route', |
|
| 315 | + * 'args' => array('array','of','args'), |
|
| 316 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
| 317 | + * ajax request, backend processing) |
|
| 318 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
| 319 | + * headers route after. The string you enter here should match the defined route reference for a |
|
| 320 | + * headers sent route. |
|
| 321 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
| 322 | + * this route. |
|
| 323 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
| 324 | + * checks). |
|
| 325 | + * ), |
|
| 326 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
| 327 | + * handling method. |
|
| 328 | + * ) |
|
| 329 | + * ) |
|
| 330 | + * |
|
| 331 | + * @abstract |
|
| 332 | + * @return void |
|
| 333 | + */ |
|
| 334 | + abstract protected function _set_page_routes(); |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * _set_page_config |
|
| 339 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
| 340 | + * array corresponds to the page_route for the loaded page. Format: |
|
| 341 | + * $this->_page_config = array( |
|
| 342 | + * 'default' => array( |
|
| 343 | + * 'labels' => array( |
|
| 344 | + * 'buttons' => array( |
|
| 345 | + * 'add' => esc_html__('label for adding item'), |
|
| 346 | + * 'edit' => esc_html__('label for editing item'), |
|
| 347 | + * 'delete' => esc_html__('label for deleting item') |
|
| 348 | + * ), |
|
| 349 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
| 350 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
| 351 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
| 352 | + * _define_page_props() method |
|
| 353 | + * 'nav' => array( |
|
| 354 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
| 355 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
| 356 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
| 357 | + * 'order' => 10, //required to indicate tab position. |
|
| 358 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
| 359 | + * displayed then add this parameter. |
|
| 360 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
| 361 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
| 362 | + * metaboxes set for eventespresso admin pages. |
|
| 363 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
| 364 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
| 365 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
| 366 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
| 367 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
| 368 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
| 369 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
| 370 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
| 371 | + * want to display. |
|
| 372 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
| 373 | + * 'tab_id' => array( |
|
| 374 | + * 'title' => 'tab_title', |
|
| 375 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
| 376 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
| 377 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
| 378 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
| 379 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
| 380 | + * attempt to use the callback which should match the name of a method in the class |
|
| 381 | + * ), |
|
| 382 | + * 'tab2_id' => array( |
|
| 383 | + * 'title' => 'tab2 title', |
|
| 384 | + * 'filename' => 'file_name_2' |
|
| 385 | + * 'callback' => 'callback_method_for_content', |
|
| 386 | + * ), |
|
| 387 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
| 388 | + * help tab area on an admin page. @link |
|
| 389 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
| 390 | + * 'help_tour' => array( |
|
| 391 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
| 392 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
| 393 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
| 394 | + * ), |
|
| 395 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
| 396 | + * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
| 397 | + * just set |
|
| 398 | + * 'require_nonce' to FALSE |
|
| 399 | + * ) |
|
| 400 | + * ) |
|
| 401 | + * |
|
| 402 | + * @abstract |
|
| 403 | + * @return void |
|
| 404 | + */ |
|
| 405 | + abstract protected function _set_page_config(); |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + /** end sample help_tour methods **/ |
|
| 412 | + /** |
|
| 413 | + * _add_screen_options |
|
| 414 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
| 415 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
| 416 | + * to a particular view. |
|
| 417 | + * |
|
| 418 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 419 | + * see also WP_Screen object documents... |
|
| 420 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 421 | + * @abstract |
|
| 422 | + * @return void |
|
| 423 | + */ |
|
| 424 | + abstract protected function _add_screen_options(); |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * _add_feature_pointers |
|
| 429 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
| 430 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
| 431 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
| 432 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 433 | + * extended) also see: |
|
| 434 | + * |
|
| 435 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 436 | + * @abstract |
|
| 437 | + * @return void |
|
| 438 | + */ |
|
| 439 | + abstract protected function _add_feature_pointers(); |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * load_scripts_styles |
|
| 444 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
| 445 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
| 446 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
| 447 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
| 448 | + * |
|
| 449 | + * @abstract |
|
| 450 | + * @return void |
|
| 451 | + */ |
|
| 452 | + abstract public function load_scripts_styles(); |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * admin_init |
|
| 457 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
| 458 | + * all pages/views loaded by child class. |
|
| 459 | + * |
|
| 460 | + * @abstract |
|
| 461 | + * @return void |
|
| 462 | + */ |
|
| 463 | + abstract public function admin_init(); |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * admin_notices |
|
| 468 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
| 469 | + * all pages/views loaded by child class. |
|
| 470 | + * |
|
| 471 | + * @abstract |
|
| 472 | + * @return void |
|
| 473 | + */ |
|
| 474 | + abstract public function admin_notices(); |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * admin_footer_scripts |
|
| 479 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 480 | + * will apply to all pages/views loaded by child class. |
|
| 481 | + * |
|
| 482 | + * @return void |
|
| 483 | + */ |
|
| 484 | + abstract public function admin_footer_scripts(); |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * admin_footer |
|
| 489 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
| 490 | + * apply to all pages/views loaded by child class. |
|
| 491 | + * |
|
| 492 | + * @return void |
|
| 493 | + */ |
|
| 494 | + public function admin_footer() |
|
| 495 | + { |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * _global_ajax_hooks |
|
| 501 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
| 502 | + * Note: within the ajax callback methods. |
|
| 503 | + * |
|
| 504 | + * @abstract |
|
| 505 | + * @return void |
|
| 506 | + */ |
|
| 507 | + protected function _global_ajax_hooks() |
|
| 508 | + { |
|
| 509 | + // for lazy loading of metabox content |
|
| 510 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
| 511 | + |
|
| 512 | + add_action( |
|
| 513 | + 'wp_ajax_espresso_hide_status_change_notice', |
|
| 514 | + [$this, 'hideStatusChangeNotice'] |
|
| 515 | + ); |
|
| 516 | + add_action( |
|
| 517 | + 'wp_ajax_nopriv_espresso_hide_status_change_notice', |
|
| 518 | + [$this, 'hideStatusChangeNotice'] |
|
| 519 | + ); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + public function ajax_metabox_content() |
|
| 524 | + { |
|
| 525 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
| 526 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
| 527 | + EE_Admin_Page::cached_rss_display($contentid, $url); |
|
| 528 | + wp_die(); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + public function hideStatusChangeNotice() |
|
| 533 | + { |
|
| 534 | + $response = []; |
|
| 535 | + try { |
|
| 536 | + /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
|
| 537 | + $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
|
| 538 | + $response['success'] = $status_change_notice->dismiss() > -1; |
|
| 539 | + } catch (Exception $exception) { |
|
| 540 | + $response['errors'] = $exception->getMessage(); |
|
| 541 | + } |
|
| 542 | + echo wp_json_encode($response); |
|
| 543 | + exit(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * _page_setup |
|
| 549 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
| 550 | + * doesn't match the object. |
|
| 551 | + * |
|
| 552 | + * @final |
|
| 553 | + * @return void |
|
| 554 | + * @throws EE_Error |
|
| 555 | + * @throws InvalidArgumentException |
|
| 556 | + * @throws ReflectionException |
|
| 557 | + * @throws InvalidDataTypeException |
|
| 558 | + * @throws InvalidInterfaceException |
|
| 559 | + */ |
|
| 560 | + final protected function _page_setup() |
|
| 561 | + { |
|
| 562 | + // requires? |
|
| 563 | + // admin_init stuff - global - we're setting this REALLY early |
|
| 564 | + // so if EE_Admin pages have to hook into other WP pages they can. |
|
| 565 | + // But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
| 566 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
| 567 | + // next verify if we need to load anything... |
|
| 568 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
| 569 | + $this->page_folder = strtolower( |
|
| 570 | + str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
| 571 | + ); |
|
| 572 | + global $ee_menu_slugs; |
|
| 573 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
| 574 | + if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 575 | + return; |
|
| 576 | + } |
|
| 577 | + // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
| 578 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
| 579 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
| 580 | + ? $this->_req_data['action2'] |
|
| 581 | + : $this->_req_data['action']; |
|
| 582 | + } |
|
| 583 | + // then set blank or -1 action values to 'default' |
|
| 584 | + $this->_req_action = isset($this->_req_data['action']) |
|
| 585 | + && ! empty($this->_req_data['action']) |
|
| 586 | + && $this->_req_data['action'] !== '-1' |
|
| 587 | + ? sanitize_key($this->_req_data['action']) |
|
| 588 | + : 'default'; |
|
| 589 | + // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
| 590 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
| 591 | + $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
| 592 | + ? $this->_req_data['route'] : $this->_req_action; |
|
| 593 | + // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
| 594 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
| 595 | + ? $this->_req_data['route'] |
|
| 596 | + : $this->_req_action; |
|
| 597 | + $this->_current_view = $this->_req_action; |
|
| 598 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 599 | + $this->_define_page_props(); |
|
| 600 | + $this->_current_page_view_url = add_query_arg( |
|
| 601 | + array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
| 602 | + $this->_admin_base_url |
|
| 603 | + ); |
|
| 604 | + // default things |
|
| 605 | + $this->_default_espresso_metaboxes = array( |
|
| 606 | + '_espresso_news_post_box', |
|
| 607 | + '_espresso_links_post_box', |
|
| 608 | + '_espresso_ratings_request', |
|
| 609 | + '_espresso_sponsors_post_box', |
|
| 610 | + ); |
|
| 611 | + // set page configs |
|
| 612 | + $this->_set_page_routes(); |
|
| 613 | + $this->_set_page_config(); |
|
| 614 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
| 615 | + if (isset($this->_req_data['wp_referer'])) { |
|
| 616 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
| 617 | + } |
|
| 618 | + // for caffeinated and other extended functionality. |
|
| 619 | + // If there is a _extend_page_config method |
|
| 620 | + // then let's run that to modify the all the various page configuration arrays |
|
| 621 | + if (method_exists($this, '_extend_page_config')) { |
|
| 622 | + $this->_extend_page_config(); |
|
| 623 | + } |
|
| 624 | + // for CPT and other extended functionality. |
|
| 625 | + // If there is an _extend_page_config_for_cpt |
|
| 626 | + // then let's run that to modify all the various page configuration arrays. |
|
| 627 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
| 628 | + $this->_extend_page_config_for_cpt(); |
|
| 629 | + } |
|
| 630 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
| 631 | + $this->_page_routes = apply_filters( |
|
| 632 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 633 | + $this->_page_routes, |
|
| 634 | + $this |
|
| 635 | + ); |
|
| 636 | + $this->_page_config = apply_filters( |
|
| 637 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 638 | + $this->_page_config, |
|
| 639 | + $this |
|
| 640 | + ); |
|
| 641 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
| 642 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
| 643 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 644 | + add_action( |
|
| 645 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
| 646 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 647 | + 10, |
|
| 648 | + 2 |
|
| 649 | + ); |
|
| 650 | + } |
|
| 651 | + // next route only if routing enabled |
|
| 652 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
| 653 | + $this->_verify_routes(); |
|
| 654 | + // next let's just check user_access and kill if no access |
|
| 655 | + $this->check_user_access(); |
|
| 656 | + if ($this->_is_UI_request) { |
|
| 657 | + // admin_init stuff - global, all views for this page class, specific view |
|
| 658 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
| 659 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 660 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 661 | + } |
|
| 662 | + } else { |
|
| 663 | + // hijack regular WP loading and route admin request immediately |
|
| 664 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
| 665 | + $this->route_admin_request(); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
| 673 | + * |
|
| 674 | + * @return void |
|
| 675 | + * @throws EE_Error |
|
| 676 | + */ |
|
| 677 | + private function _do_other_page_hooks() |
|
| 678 | + { |
|
| 679 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 680 | + foreach ($registered_pages as $page) { |
|
| 681 | + // now let's setup the file name and class that should be present |
|
| 682 | + $classname = str_replace('.class.php', '', $page); |
|
| 683 | + // autoloaders should take care of loading file |
|
| 684 | + if (! class_exists($classname)) { |
|
| 685 | + $error_msg[] = sprintf( |
|
| 686 | + esc_html__( |
|
| 687 | + 'Something went wrong with loading the %s admin hooks page.', |
|
| 688 | + 'event_espresso' |
|
| 689 | + ), |
|
| 690 | + $page |
|
| 691 | + ); |
|
| 692 | + $error_msg[] = $error_msg[0] |
|
| 693 | + . "\r\n" |
|
| 694 | + . sprintf( |
|
| 695 | + esc_html__( |
|
| 696 | + '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', |
|
| 697 | + 'event_espresso' |
|
| 698 | + ), |
|
| 699 | + $page, |
|
| 700 | + '<br />', |
|
| 701 | + '<strong>' . $classname . '</strong>' |
|
| 702 | + ); |
|
| 703 | + throw new EE_Error(implode('||', $error_msg)); |
|
| 704 | + } |
|
| 705 | + // // notice we are passing the instance of this class to the hook object. |
|
| 706 | + $this->loader->getShared($classname, [$this]); |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * @throws DomainException |
|
| 713 | + * @throws EE_Error |
|
| 714 | + * @throws InvalidArgumentException |
|
| 715 | + * @throws InvalidDataTypeException |
|
| 716 | + * @throws InvalidInterfaceException |
|
| 717 | + * @throws ReflectionException |
|
| 718 | + * @since $VID:$ |
|
| 719 | + */ |
|
| 720 | + public function load_page_dependencies() |
|
| 721 | + { |
|
| 722 | + try { |
|
| 723 | + $this->_load_page_dependencies(); |
|
| 724 | + } catch (EE_Error $e) { |
|
| 725 | + $e->get_error(); |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * load_page_dependencies |
|
| 732 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
| 733 | + * |
|
| 734 | + * @return void |
|
| 735 | + * @throws DomainException |
|
| 736 | + * @throws EE_Error |
|
| 737 | + * @throws InvalidArgumentException |
|
| 738 | + * @throws InvalidDataTypeException |
|
| 739 | + * @throws InvalidInterfaceException |
|
| 740 | + * @throws ReflectionException |
|
| 741 | + */ |
|
| 742 | + protected function _load_page_dependencies() |
|
| 743 | + { |
|
| 744 | + // let's set the current_screen and screen options to override what WP set |
|
| 745 | + $this->_current_screen = get_current_screen(); |
|
| 746 | + // load admin_notices - global, page class, and view specific |
|
| 747 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
| 748 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
| 749 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 750 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 751 | + } |
|
| 752 | + // load network admin_notices - global, page class, and view specific |
|
| 753 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
| 754 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 755 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 756 | + } |
|
| 757 | + // this will save any per_page screen options if they are present |
|
| 758 | + $this->_set_per_page_screen_options(); |
|
| 759 | + // setup list table properties |
|
| 760 | + $this->_set_list_table(); |
|
| 761 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
| 762 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
| 763 | + $this->_add_registered_meta_boxes(); |
|
| 764 | + $this->_add_screen_columns(); |
|
| 765 | + // add screen options - global, page child class, and view specific |
|
| 766 | + $this->_add_global_screen_options(); |
|
| 767 | + $this->_add_screen_options(); |
|
| 768 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
| 769 | + if (method_exists($this, $add_screen_options)) { |
|
| 770 | + $this->{$add_screen_options}(); |
|
| 771 | + } |
|
| 772 | + // add help tab(s) and tours- set via page_config and qtips. |
|
| 773 | + // $this->_add_help_tour(); |
|
| 774 | + $this->_add_help_tabs(); |
|
| 775 | + $this->_add_qtips(); |
|
| 776 | + // add feature_pointers - global, page child class, and view specific |
|
| 777 | + $this->_add_feature_pointers(); |
|
| 778 | + $this->_add_global_feature_pointers(); |
|
| 779 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
| 780 | + if (method_exists($this, $add_feature_pointer)) { |
|
| 781 | + $this->{$add_feature_pointer}(); |
|
| 782 | + } |
|
| 783 | + // enqueue scripts/styles - global, page class, and view specific |
|
| 784 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
| 785 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
| 786 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
| 787 | + add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
| 788 | + } |
|
| 789 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
| 790 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
| 791 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
| 792 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
| 793 | + // is a good use case. Notice the late priority we're giving these |
|
| 794 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
| 795 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
| 796 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
| 797 | + add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
| 798 | + } |
|
| 799 | + // admin footer scripts |
|
| 800 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
| 801 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
| 802 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
| 803 | + add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
| 804 | + } |
|
| 805 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
| 806 | + // targeted hook |
|
| 807 | + do_action( |
|
| 808 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
| 809 | + ); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + |
|
| 813 | + /** |
|
| 814 | + * _set_defaults |
|
| 815 | + * This sets some global defaults for class properties. |
|
| 816 | + */ |
|
| 817 | + private function _set_defaults() |
|
| 818 | + { |
|
| 819 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
| 820 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
| 821 | + $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
| 822 | + $this->_page_config = $this->_default_route_query_args = array(); |
|
| 823 | + $this->_default_nav_tab_name = 'overview'; |
|
| 824 | + // init template args |
|
| 825 | + $this->_template_args = array( |
|
| 826 | + 'admin_page_header' => '', |
|
| 827 | + 'admin_page_content' => '', |
|
| 828 | + 'post_body_content' => '', |
|
| 829 | + 'before_list_table' => '', |
|
| 830 | + 'after_list_table' => '', |
|
| 831 | + ); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * route_admin_request |
|
| 837 | + * |
|
| 838 | + * @see _route_admin_request() |
|
| 839 | + * @return exception|void error |
|
| 840 | + * @throws InvalidArgumentException |
|
| 841 | + * @throws InvalidInterfaceException |
|
| 842 | + * @throws InvalidDataTypeException |
|
| 843 | + * @throws EE_Error |
|
| 844 | + * @throws ReflectionException |
|
| 845 | + */ |
|
| 846 | + public function route_admin_request() |
|
| 847 | + { |
|
| 848 | + try { |
|
| 849 | + $this->_route_admin_request(); |
|
| 850 | + } catch (EE_Error $e) { |
|
| 851 | + $e->get_error(); |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + public function set_wp_page_slug($wp_page_slug) |
|
| 857 | + { |
|
| 858 | + $this->_wp_page_slug = $wp_page_slug; |
|
| 859 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
| 860 | + if (is_network_admin()) { |
|
| 861 | + $this->_wp_page_slug .= '-network'; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * _verify_routes |
|
| 868 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
| 869 | + * we know if we need to drop out. |
|
| 870 | + * |
|
| 871 | + * @return bool |
|
| 872 | + * @throws EE_Error |
|
| 873 | + */ |
|
| 874 | + protected function _verify_routes() |
|
| 875 | + { |
|
| 876 | + if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 879 | + $this->_route = false; |
|
| 880 | + // check that the page_routes array is not empty |
|
| 881 | + if (empty($this->_page_routes)) { |
|
| 882 | + // user error msg |
|
| 883 | + $error_msg = sprintf( |
|
| 884 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
| 885 | + $this->_admin_page_title |
|
| 886 | + ); |
|
| 887 | + // developer error msg |
|
| 888 | + $error_msg .= '||' . $error_msg |
|
| 889 | + . esc_html__( |
|
| 890 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
| 891 | + 'event_espresso' |
|
| 892 | + ); |
|
| 893 | + throw new EE_Error($error_msg); |
|
| 894 | + } |
|
| 895 | + // and that the requested page route exists |
|
| 896 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 897 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 898 | + $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 899 | + ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 900 | + } else { |
|
| 901 | + // user error msg |
|
| 902 | + $error_msg = sprintf( |
|
| 903 | + esc_html__( |
|
| 904 | + 'The requested page route does not exist for the %s admin page.', |
|
| 905 | + 'event_espresso' |
|
| 906 | + ), |
|
| 907 | + $this->_admin_page_title |
|
| 908 | + ); |
|
| 909 | + // developer error msg |
|
| 910 | + $error_msg .= '||' . $error_msg |
|
| 911 | + . sprintf( |
|
| 912 | + esc_html__( |
|
| 913 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
| 914 | + 'event_espresso' |
|
| 915 | + ), |
|
| 916 | + $this->_req_action |
|
| 917 | + ); |
|
| 918 | + throw new EE_Error($error_msg); |
|
| 919 | + } |
|
| 920 | + // and that a default route exists |
|
| 921 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
| 922 | + // user error msg |
|
| 923 | + $error_msg = sprintf( |
|
| 924 | + esc_html__( |
|
| 925 | + 'A default page route has not been set for the % admin page.', |
|
| 926 | + 'event_espresso' |
|
| 927 | + ), |
|
| 928 | + $this->_admin_page_title |
|
| 929 | + ); |
|
| 930 | + // developer error msg |
|
| 931 | + $error_msg .= '||' . $error_msg |
|
| 932 | + . esc_html__( |
|
| 933 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
| 934 | + 'event_espresso' |
|
| 935 | + ); |
|
| 936 | + throw new EE_Error($error_msg); |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + // first lets' catch if the UI request has EVER been set. |
|
| 940 | + if ($this->_is_UI_request === null) { |
|
| 941 | + // lets set if this is a UI request or not. |
|
| 942 | + $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
| 943 | + // wait a minute... we might have a noheader in the route array |
|
| 944 | + $this->_is_UI_request = is_array($this->_route) |
|
| 945 | + && isset($this->_route['noheader']) |
|
| 946 | + && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
| 947 | + } |
|
| 948 | + $this->_set_current_labels(); |
|
| 949 | + return true; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
| 955 | + * |
|
| 956 | + * @param string $route the route name we're verifying |
|
| 957 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
| 958 | + * @throws EE_Error |
|
| 959 | + */ |
|
| 960 | + protected function _verify_route($route) |
|
| 961 | + { |
|
| 962 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
| 963 | + return true; |
|
| 964 | + } |
|
| 965 | + // user error msg |
|
| 966 | + $error_msg = sprintf( |
|
| 967 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
| 968 | + $this->_admin_page_title |
|
| 969 | + ); |
|
| 970 | + // developer error msg |
|
| 971 | + $error_msg .= '||' . $error_msg |
|
| 972 | + . sprintf( |
|
| 973 | + esc_html__( |
|
| 974 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
| 975 | + 'event_espresso' |
|
| 976 | + ), |
|
| 977 | + $route |
|
| 978 | + ); |
|
| 979 | + throw new EE_Error($error_msg); |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + |
|
| 983 | + /** |
|
| 984 | + * perform nonce verification |
|
| 985 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
| 986 | + * using this method (and save retyping!) |
|
| 987 | + * |
|
| 988 | + * @param string $nonce The nonce sent |
|
| 989 | + * @param string $nonce_ref The nonce reference string (name0) |
|
| 990 | + * @return void |
|
| 991 | + * @throws EE_Error |
|
| 992 | + * @throws InvalidArgumentException |
|
| 993 | + * @throws InvalidDataTypeException |
|
| 994 | + * @throws InvalidInterfaceException |
|
| 995 | + */ |
|
| 996 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
| 997 | + { |
|
| 998 | + // verify nonce against expected value |
|
| 999 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1000 | + // these are not the droids you are looking for !!! |
|
| 1001 | + $msg = sprintf( |
|
| 1002 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
| 1003 | + '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
| 1004 | + '</a>' |
|
| 1005 | + ); |
|
| 1006 | + if (WP_DEBUG) { |
|
| 1007 | + $msg .= "\n " |
|
| 1008 | + . sprintf( |
|
| 1009 | + esc_html__( |
|
| 1010 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
| 1011 | + 'event_espresso' |
|
| 1012 | + ), |
|
| 1013 | + EE_Admin_Page::class |
|
| 1014 | + ); |
|
| 1015 | + } |
|
| 1016 | + if (! defined('DOING_AJAX')) { |
|
| 1017 | + wp_die($msg); |
|
| 1018 | + } else { |
|
| 1019 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1020 | + $this->_return_json(); |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * _route_admin_request() |
|
| 1028 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if there are |
|
| 1029 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
| 1030 | + * in the page routes and then will try to load the corresponding method. |
|
| 1031 | + * |
|
| 1032 | + * @return void |
|
| 1033 | + * @throws EE_Error |
|
| 1034 | + * @throws InvalidArgumentException |
|
| 1035 | + * @throws InvalidDataTypeException |
|
| 1036 | + * @throws InvalidInterfaceException |
|
| 1037 | + * @throws ReflectionException |
|
| 1038 | + */ |
|
| 1039 | + protected function _route_admin_request() |
|
| 1040 | + { |
|
| 1041 | + if (! $this->_is_UI_request) { |
|
| 1042 | + $this->_verify_routes(); |
|
| 1043 | + } |
|
| 1044 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
| 1045 | + ? $this->_route_config['require_nonce'] |
|
| 1046 | + : true; |
|
| 1047 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
| 1048 | + // set nonce from post data |
|
| 1049 | + $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 1050 | + ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 1051 | + : ''; |
|
| 1052 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 1053 | + } |
|
| 1054 | + // set the nav_tabs array but ONLY if this is UI_request |
|
| 1055 | + if ($this->_is_UI_request) { |
|
| 1056 | + $this->_set_nav_tabs(); |
|
| 1057 | + } |
|
| 1058 | + // grab callback function |
|
| 1059 | + $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route; |
|
| 1060 | + // check if callback has args |
|
| 1061 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
| 1062 | + $error_msg = ''; |
|
| 1063 | + // action right before calling route |
|
| 1064 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
| 1065 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1066 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
| 1067 | + } |
|
| 1068 | + // right before calling the route, let's remove _wp_http_referer from the |
|
| 1069 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
| 1070 | + $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
| 1071 | + '_wp_http_referer', |
|
| 1072 | + wp_unslash($_SERVER['REQUEST_URI']) |
|
| 1073 | + ); |
|
| 1074 | + if (! empty($func)) { |
|
| 1075 | + if (is_array($func)) { |
|
| 1076 | + [$class, $method] = $func; |
|
| 1077 | + } elseif (strpos($func, '::') !== false) { |
|
| 1078 | + [$class, $method] = explode('::', $func); |
|
| 1079 | + } else { |
|
| 1080 | + $class = $this; |
|
| 1081 | + $method = $func; |
|
| 1082 | + } |
|
| 1083 | + if (! (is_object($class) && $class === $this)) { |
|
| 1084 | + // send along this admin page object for access by addons. |
|
| 1085 | + $args['admin_page_object'] = $this; |
|
| 1086 | + } |
|
| 1087 | + // is it a method on a class that doesn't work? |
|
| 1088 | + if ( |
|
| 1089 | + ((method_exists($class, $method) |
|
| 1090 | + && call_user_func_array(array($class, $method), $args) === false) |
|
| 1091 | + && (// is it a standalone function that doesn't work? |
|
| 1092 | + function_exists($method) |
|
| 1093 | + && call_user_func_array( |
|
| 1094 | + $func, |
|
| 1095 | + array_merge(array('admin_page_object' => $this), $args) |
|
| 1096 | + ) === false |
|
| 1097 | + )) || (// is it neither a class method NOR a standalone function? |
|
| 1098 | + ! function_exists($method) |
|
| 1099 | + && ! method_exists($class, $method) |
|
| 1100 | + ) |
|
| 1101 | + ) { |
|
| 1102 | + // user error msg |
|
| 1103 | + $error_msg = esc_html__( |
|
| 1104 | + 'An error occurred. The requested page route could not be found.', |
|
| 1105 | + 'event_espresso' |
|
| 1106 | + ); |
|
| 1107 | + // developer error msg |
|
| 1108 | + $error_msg .= '||'; |
|
| 1109 | + $error_msg .= sprintf( |
|
| 1110 | + esc_html__( |
|
| 1111 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
| 1112 | + 'event_espresso' |
|
| 1113 | + ), |
|
| 1114 | + $method |
|
| 1115 | + ); |
|
| 1116 | + } |
|
| 1117 | + if (! empty($error_msg)) { |
|
| 1118 | + throw new EE_Error($error_msg); |
|
| 1119 | + } |
|
| 1120 | + } |
|
| 1121 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
| 1122 | + // then we need to reset the routing properties to the new route. |
|
| 1123 | + // 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. |
|
| 1124 | + if ( |
|
| 1125 | + $this->_is_UI_request === false |
|
| 1126 | + && is_array($this->_route) |
|
| 1127 | + && ! empty($this->_route['headers_sent_route']) |
|
| 1128 | + ) { |
|
| 1129 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * This method just allows the resetting of page properties in the case where a no headers |
|
| 1136 | + * route redirects to a headers route in its route config. |
|
| 1137 | + * |
|
| 1138 | + * @since 4.3.0 |
|
| 1139 | + * @param string $new_route New (non header) route to redirect to. |
|
| 1140 | + * @return void |
|
| 1141 | + * @throws ReflectionException |
|
| 1142 | + * @throws InvalidArgumentException |
|
| 1143 | + * @throws InvalidInterfaceException |
|
| 1144 | + * @throws InvalidDataTypeException |
|
| 1145 | + * @throws EE_Error |
|
| 1146 | + */ |
|
| 1147 | + protected function _reset_routing_properties($new_route) |
|
| 1148 | + { |
|
| 1149 | + $this->_is_UI_request = true; |
|
| 1150 | + // now we set the current route to whatever the headers_sent_route is set at |
|
| 1151 | + $this->_req_data['action'] = $new_route; |
|
| 1152 | + // rerun page setup |
|
| 1153 | + $this->_page_setup(); |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * _add_query_arg |
|
| 1159 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 1160 | + *(internally just uses EEH_URL's function with the same name) |
|
| 1161 | + * |
|
| 1162 | + * @param array $args |
|
| 1163 | + * @param string $url |
|
| 1164 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
| 1165 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
| 1166 | + * Example usage: If the current page is: |
|
| 1167 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
| 1168 | + * &action=default&event_id=20&month_range=March%202015 |
|
| 1169 | + * &_wpnonce=5467821 |
|
| 1170 | + * and you call: |
|
| 1171 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
| 1172 | + * array( |
|
| 1173 | + * 'action' => 'resend_something', |
|
| 1174 | + * 'page=>espresso_registrations' |
|
| 1175 | + * ), |
|
| 1176 | + * $some_url, |
|
| 1177 | + * true |
|
| 1178 | + * ); |
|
| 1179 | + * It will produce a url in this structure: |
|
| 1180 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
| 1181 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
| 1182 | + * month_range]=March%202015 |
|
| 1183 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
| 1184 | + * @return string |
|
| 1185 | + */ |
|
| 1186 | + public static function add_query_args_and_nonce( |
|
| 1187 | + $args = array(), |
|
| 1188 | + $url = '', |
|
| 1189 | + $sticky = false, |
|
| 1190 | + $exclude_nonce = false |
|
| 1191 | + ) { |
|
| 1192 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
| 1193 | + if ($sticky) { |
|
| 1194 | + $request = $_REQUEST; |
|
| 1195 | + unset($request['_wp_http_referer'], $request['wp_referer']); |
|
| 1196 | + foreach ($request as $key => $value) { |
|
| 1197 | + // do not add nonces |
|
| 1198 | + if (strpos($key, 'nonce') !== false) { |
|
| 1199 | + continue; |
|
| 1200 | + } |
|
| 1201 | + $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1202 | + } |
|
| 1203 | + } |
|
| 1204 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * This returns a generated link that will load the related help tab. |
|
| 1210 | + * |
|
| 1211 | + * @param string $help_tab_id the id for the connected help tab |
|
| 1212 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
| 1213 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
| 1214 | + * @uses EEH_Template::get_help_tab_link() |
|
| 1215 | + * @return string generated link |
|
| 1216 | + */ |
|
| 1217 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
| 1218 | + { |
|
| 1219 | + return EEH_Template::get_help_tab_link( |
|
| 1220 | + $help_tab_id, |
|
| 1221 | + $this->page_slug, |
|
| 1222 | + $this->_req_action, |
|
| 1223 | + $icon_style, |
|
| 1224 | + $help_text |
|
| 1225 | + ); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * _add_help_tabs |
|
| 1231 | + * Note child classes define their help tabs within the page_config array. |
|
| 1232 | + * |
|
| 1233 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
| 1234 | + * @return void |
|
| 1235 | + * @throws DomainException |
|
| 1236 | + * @throws EE_Error |
|
| 1237 | + * @throws ReflectionException |
|
| 1238 | + */ |
|
| 1239 | + protected function _add_help_tabs() |
|
| 1240 | + { |
|
| 1241 | + $tour_buttons = ''; |
|
| 1242 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1243 | + $config = $this->_page_config[ $this->_req_action ]; |
|
| 1244 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1245 | + // is there a help tour for the current route? if there is let's setup the tour buttons |
|
| 1246 | + // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1247 | + // $tb = array(); |
|
| 1248 | + // $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
| 1249 | + // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1250 | + // // if this is the end tour then we don't need to setup a button |
|
| 1251 | + // if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
| 1252 | + // continue; |
|
| 1253 | + // } |
|
| 1254 | + // $tb[] = '<button id="trigger-tour-' |
|
| 1255 | + // . $tour->get_slug() |
|
| 1256 | + // . '" class="button-primary trigger-ee-help-tour">' |
|
| 1257 | + // . $tour->get_label() |
|
| 1258 | + // . '</button>'; |
|
| 1259 | + // } |
|
| 1260 | + // $tour_buttons .= implode('<br />', $tb); |
|
| 1261 | + // $tour_buttons .= '</div></div>'; |
|
| 1262 | + // } |
|
| 1263 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
| 1264 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
| 1265 | + // check that the callback given is valid |
|
| 1266 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1267 | + throw new EE_Error( |
|
| 1268 | + sprintf( |
|
| 1269 | + esc_html__( |
|
| 1270 | + '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', |
|
| 1271 | + 'event_espresso' |
|
| 1272 | + ), |
|
| 1273 | + $config['help_sidebar'], |
|
| 1274 | + get_class($this) |
|
| 1275 | + ) |
|
| 1276 | + ); |
|
| 1277 | + } |
|
| 1278 | + $content = apply_filters( |
|
| 1279 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1280 | + $this->{$config['help_sidebar']}() |
|
| 1281 | + ); |
|
| 1282 | + $content .= $tour_buttons; // add help tour buttons. |
|
| 1283 | + // do we have any help tours setup? Cause if we do we want to add the buttons |
|
| 1284 | + $this->_current_screen->set_help_sidebar($content); |
|
| 1285 | + } |
|
| 1286 | + // if there ARE tour buttons... |
|
| 1287 | + if (! empty($tour_buttons)) { |
|
| 1288 | + // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar. |
|
| 1289 | + if (! isset($config['help_sidebar'])) { |
|
| 1290 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
| 1291 | + } |
|
| 1292 | + // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
| 1293 | + if (! isset($config['help_tabs'])) { |
|
| 1294 | + $_ht['id'] = $this->page_slug; |
|
| 1295 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
| 1296 | + $_ht['content'] = '<p>' |
|
| 1297 | + . esc_html__( |
|
| 1298 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
| 1299 | + 'event_espresso' |
|
| 1300 | + ) . '</p>'; |
|
| 1301 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | + if (! isset($config['help_tabs'])) { |
|
| 1305 | + return; |
|
| 1306 | + } //no help tabs for this route |
|
| 1307 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
| 1308 | + // we're here so there ARE help tabs! |
|
| 1309 | + // make sure we've got what we need |
|
| 1310 | + if (! isset($cfg['title'])) { |
|
| 1311 | + throw new EE_Error( |
|
| 1312 | + esc_html__( |
|
| 1313 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
| 1314 | + 'event_espresso' |
|
| 1315 | + ) |
|
| 1316 | + ); |
|
| 1317 | + } |
|
| 1318 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1319 | + throw new EE_Error( |
|
| 1320 | + esc_html__( |
|
| 1321 | + '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', |
|
| 1322 | + 'event_espresso' |
|
| 1323 | + ) |
|
| 1324 | + ); |
|
| 1325 | + } |
|
| 1326 | + // first priority goes to content. |
|
| 1327 | + if (! empty($cfg['content'])) { |
|
| 1328 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
| 1329 | + // second priority goes to filename |
|
| 1330 | + } elseif (! empty($cfg['filename'])) { |
|
| 1331 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1332 | + // 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) |
|
| 1333 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1334 | + . basename($this->_get_dir()) |
|
| 1335 | + . '/help_tabs/' |
|
| 1336 | + . $cfg['filename'] |
|
| 1337 | + . '.help_tab.php' : $file_path; |
|
| 1338 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1339 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1340 | + EE_Error::add_error( |
|
| 1341 | + sprintf( |
|
| 1342 | + esc_html__( |
|
| 1343 | + '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', |
|
| 1344 | + 'event_espresso' |
|
| 1345 | + ), |
|
| 1346 | + $tab_id, |
|
| 1347 | + key($config), |
|
| 1348 | + $file_path |
|
| 1349 | + ), |
|
| 1350 | + __FILE__, |
|
| 1351 | + __FUNCTION__, |
|
| 1352 | + __LINE__ |
|
| 1353 | + ); |
|
| 1354 | + return; |
|
| 1355 | + } |
|
| 1356 | + $template_args['admin_page_obj'] = $this; |
|
| 1357 | + $content = EEH_Template::display_template( |
|
| 1358 | + $file_path, |
|
| 1359 | + $template_args, |
|
| 1360 | + true |
|
| 1361 | + ); |
|
| 1362 | + } else { |
|
| 1363 | + $content = ''; |
|
| 1364 | + } |
|
| 1365 | + // check if callback is valid |
|
| 1366 | + if ( |
|
| 1367 | + empty($content) && ( |
|
| 1368 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
| 1369 | + ) |
|
| 1370 | + ) { |
|
| 1371 | + EE_Error::add_error( |
|
| 1372 | + sprintf( |
|
| 1373 | + esc_html__( |
|
| 1374 | + '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.', |
|
| 1375 | + 'event_espresso' |
|
| 1376 | + ), |
|
| 1377 | + $cfg['title'] |
|
| 1378 | + ), |
|
| 1379 | + __FILE__, |
|
| 1380 | + __FUNCTION__, |
|
| 1381 | + __LINE__ |
|
| 1382 | + ); |
|
| 1383 | + return; |
|
| 1384 | + } |
|
| 1385 | + // setup config array for help tab method |
|
| 1386 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1387 | + $_ht = array( |
|
| 1388 | + 'id' => $id, |
|
| 1389 | + 'title' => $cfg['title'], |
|
| 1390 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
| 1391 | + 'content' => $content, |
|
| 1392 | + ); |
|
| 1393 | + $this->_current_screen->add_help_tab($_ht); |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + |
|
| 1399 | + /** |
|
| 1400 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
| 1401 | + * an array with properties for setting up usage of the joyride plugin |
|
| 1402 | + * |
|
| 1403 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
| 1404 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
| 1405 | + * _set_page_config() comments |
|
| 1406 | + * @return void |
|
| 1407 | + * @throws EE_Error |
|
| 1408 | + * @throws InvalidArgumentException |
|
| 1409 | + * @throws InvalidDataTypeException |
|
| 1410 | + * @throws InvalidInterfaceException |
|
| 1411 | + * @throws ReflectionException |
|
| 1412 | + */ |
|
| 1413 | + protected function _add_help_tour() |
|
| 1414 | + { |
|
| 1415 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1416 | + // $tours = array(); |
|
| 1417 | + // $this->_help_tour = array(); |
|
| 1418 | + // // exit early if help tours are turned off globally |
|
| 1419 | + // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
| 1420 | + // || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
| 1421 | + // ) { |
|
| 1422 | + // return; |
|
| 1423 | + // } |
|
| 1424 | + // // loop through _page_config to find any help_tour defined |
|
| 1425 | + // foreach ($this->_page_config as $route => $config) { |
|
| 1426 | + // // we're only going to set things up for this route |
|
| 1427 | + // if ($route !== $this->_req_action) { |
|
| 1428 | + // continue; |
|
| 1429 | + // } |
|
| 1430 | + // if (isset($config['help_tour'])) { |
|
| 1431 | + // foreach ($config['help_tour'] as $tour) { |
|
| 1432 | + // $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
| 1433 | + // // let's see if we can get that file... |
|
| 1434 | + // // if not its possible this is a decaf route not set in caffeinated |
|
| 1435 | + // // so lets try and get the caffeinated equivalent |
|
| 1436 | + // $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
| 1437 | + // . basename($this->_get_dir()) |
|
| 1438 | + // . '/help_tours/' |
|
| 1439 | + // . $tour |
|
| 1440 | + // . '.class.php' : $file_path; |
|
| 1441 | + // // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
| 1442 | + // if (! is_readable($file_path)) { |
|
| 1443 | + // EE_Error::add_error( |
|
| 1444 | + // sprintf( |
|
| 1445 | + // esc_html__( |
|
| 1446 | + // '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', |
|
| 1447 | + // 'event_espresso' |
|
| 1448 | + // ), |
|
| 1449 | + // $file_path, |
|
| 1450 | + // $tour |
|
| 1451 | + // ), |
|
| 1452 | + // __FILE__, |
|
| 1453 | + // __FUNCTION__, |
|
| 1454 | + // __LINE__ |
|
| 1455 | + // ); |
|
| 1456 | + // return; |
|
| 1457 | + // } |
|
| 1458 | + // require_once $file_path; |
|
| 1459 | + // if (! class_exists($tour)) { |
|
| 1460 | + // $error_msg[] = sprintf( |
|
| 1461 | + // esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
| 1462 | + // $tour |
|
| 1463 | + // ); |
|
| 1464 | + // $error_msg[] = $error_msg[0] . "\r\n" |
|
| 1465 | + // . sprintf( |
|
| 1466 | + // esc_html__( |
|
| 1467 | + // '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.', |
|
| 1468 | + // 'event_espresso' |
|
| 1469 | + // ), |
|
| 1470 | + // $tour, |
|
| 1471 | + // '<br />', |
|
| 1472 | + // $tour, |
|
| 1473 | + // $this->_req_action, |
|
| 1474 | + // get_class($this) |
|
| 1475 | + // ); |
|
| 1476 | + // throw new EE_Error(implode('||', $error_msg)); |
|
| 1477 | + // } |
|
| 1478 | + // $tour_obj = new $tour($this->_is_caf); |
|
| 1479 | + // $tours[] = $tour_obj; |
|
| 1480 | + // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
| 1481 | + // } |
|
| 1482 | + // // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
| 1483 | + // $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
| 1484 | + // $tours[] = $end_stop_tour; |
|
| 1485 | + // $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
| 1486 | + // } |
|
| 1487 | + // } |
|
| 1488 | + // |
|
| 1489 | + // if (! empty($tours)) { |
|
| 1490 | + // $this->_help_tour['tours'] = $tours; |
|
| 1491 | + // } |
|
| 1492 | + // // that's it! Now that the $_help_tours property is set (or not) |
|
| 1493 | + // // the scripts and html should be taken care of automatically. |
|
| 1494 | + // |
|
| 1495 | + // /** |
|
| 1496 | + // * Allow extending the help tours variable. |
|
| 1497 | + // * |
|
| 1498 | + // * @param Array $_help_tour The array containing all help tour information to be displayed. |
|
| 1499 | + // */ |
|
| 1500 | + // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour); |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + |
|
| 1504 | + /** |
|
| 1505 | + * This simply sets up any qtips that have been defined in the page config |
|
| 1506 | + * |
|
| 1507 | + * @return void |
|
| 1508 | + * @throws ReflectionException |
|
| 1509 | + * @throws EE_Error |
|
| 1510 | + */ |
|
| 1511 | + protected function _add_qtips() |
|
| 1512 | + { |
|
| 1513 | + if (isset($this->_route_config['qtips'])) { |
|
| 1514 | + $qtips = (array) $this->_route_config['qtips']; |
|
| 1515 | + // load qtip loader |
|
| 1516 | + $path = array( |
|
| 1517 | + $this->_get_dir() . '/qtips/', |
|
| 1518 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1519 | + ); |
|
| 1520 | + $qtip_loader = EEH_Qtip_Loader::instance(); |
|
| 1521 | + if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
| 1522 | + $qtip_loader->register($qtips, $path); |
|
| 1523 | + } |
|
| 1524 | + } |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + |
|
| 1528 | + /** |
|
| 1529 | + * _set_nav_tabs |
|
| 1530 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
| 1531 | + * wish to add additional tabs or modify accordingly. |
|
| 1532 | + * |
|
| 1533 | + * @return void |
|
| 1534 | + * @throws InvalidArgumentException |
|
| 1535 | + * @throws InvalidInterfaceException |
|
| 1536 | + * @throws InvalidDataTypeException |
|
| 1537 | + */ |
|
| 1538 | + protected function _set_nav_tabs() |
|
| 1539 | + { |
|
| 1540 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1541 | + $i = 0; |
|
| 1542 | + foreach ($this->_page_config as $slug => $config) { |
|
| 1543 | + if ( |
|
| 1544 | + ! is_array($config) |
|
| 1545 | + || ( |
|
| 1546 | + is_array($config) |
|
| 1547 | + && ( |
|
| 1548 | + (isset($config['nav']) && ! $config['nav']) |
|
| 1549 | + || ! isset($config['nav']) |
|
| 1550 | + ) |
|
| 1551 | + ) |
|
| 1552 | + ) { |
|
| 1553 | + continue; |
|
| 1554 | + } |
|
| 1555 | + // no nav tab for this config |
|
| 1556 | + // check for persistent flag |
|
| 1557 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
| 1558 | + // nav tab is only to appear when route requested. |
|
| 1559 | + continue; |
|
| 1560 | + } |
|
| 1561 | + if (! $this->check_user_access($slug, true)) { |
|
| 1562 | + // no nav tab because current user does not have access. |
|
| 1563 | + continue; |
|
| 1564 | + } |
|
| 1565 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1566 | + $this->_nav_tabs[ $slug ] = array( |
|
| 1567 | + 'url' => isset($config['nav']['url']) |
|
| 1568 | + ? $config['nav']['url'] |
|
| 1569 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1570 | + array('action' => $slug), |
|
| 1571 | + $this->_admin_base_url |
|
| 1572 | + ), |
|
| 1573 | + 'link_text' => isset($config['nav']['label']) |
|
| 1574 | + ? $config['nav']['label'] |
|
| 1575 | + : ucwords( |
|
| 1576 | + str_replace('_', ' ', $slug) |
|
| 1577 | + ), |
|
| 1578 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1579 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
| 1580 | + ); |
|
| 1581 | + $i++; |
|
| 1582 | + } |
|
| 1583 | + // if $this->_nav_tabs is empty then lets set the default |
|
| 1584 | + if (empty($this->_nav_tabs)) { |
|
| 1585 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1586 | + 'url' => $this->_admin_base_url, |
|
| 1587 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
| 1588 | + 'css_class' => 'nav-tab-active', |
|
| 1589 | + 'order' => 10, |
|
| 1590 | + ); |
|
| 1591 | + } |
|
| 1592 | + // now let's sort the tabs according to order |
|
| 1593 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + |
|
| 1597 | + /** |
|
| 1598 | + * _set_current_labels |
|
| 1599 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
| 1600 | + * property array |
|
| 1601 | + * |
|
| 1602 | + * @return void |
|
| 1603 | + */ |
|
| 1604 | + private function _set_current_labels() |
|
| 1605 | + { |
|
| 1606 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
| 1607 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
| 1608 | + if (is_array($text)) { |
|
| 1609 | + foreach ($text as $sublabel => $subtext) { |
|
| 1610 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1611 | + } |
|
| 1612 | + } else { |
|
| 1613 | + $this->_labels[ $label ] = $text; |
|
| 1614 | + } |
|
| 1615 | + } |
|
| 1616 | + } |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + |
|
| 1620 | + /** |
|
| 1621 | + * verifies user access for this admin page |
|
| 1622 | + * |
|
| 1623 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
| 1624 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
| 1625 | + * return false if verify fail. |
|
| 1626 | + * @return bool |
|
| 1627 | + * @throws InvalidArgumentException |
|
| 1628 | + * @throws InvalidDataTypeException |
|
| 1629 | + * @throws InvalidInterfaceException |
|
| 1630 | + */ |
|
| 1631 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
| 1632 | + { |
|
| 1633 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1634 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
| 1635 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1636 | + && is_array( |
|
| 1637 | + $this->_page_routes[ $route_to_check ] |
|
| 1638 | + ) |
|
| 1639 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1640 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1641 | + if (empty($capability) && empty($route_to_check)) { |
|
| 1642 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
| 1643 | + : $this->_route['capability']; |
|
| 1644 | + } else { |
|
| 1645 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
| 1646 | + } |
|
| 1647 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
| 1648 | + if ( |
|
| 1649 | + ! defined('DOING_AJAX') |
|
| 1650 | + && ( |
|
| 1651 | + ! function_exists('is_admin') |
|
| 1652 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
| 1653 | + $capability, |
|
| 1654 | + $this->page_slug |
|
| 1655 | + . '_' |
|
| 1656 | + . $route_to_check, |
|
| 1657 | + $id |
|
| 1658 | + ) |
|
| 1659 | + ) |
|
| 1660 | + ) { |
|
| 1661 | + if ($verify_only) { |
|
| 1662 | + return false; |
|
| 1663 | + } |
|
| 1664 | + if (is_user_logged_in()) { |
|
| 1665 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
| 1666 | + } else { |
|
| 1667 | + return false; |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + return true; |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + |
|
| 1674 | + /** |
|
| 1675 | + * admin_init_global |
|
| 1676 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 1677 | + * This method executes for ALL EE Admin pages. |
|
| 1678 | + * |
|
| 1679 | + * @return void |
|
| 1680 | + */ |
|
| 1681 | + public function admin_init_global() |
|
| 1682 | + { |
|
| 1683 | + } |
|
| 1684 | + |
|
| 1685 | + |
|
| 1686 | + /** |
|
| 1687 | + * wp_loaded_global |
|
| 1688 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
| 1689 | + * EE_Admin page and will execute on every EE Admin Page load |
|
| 1690 | + * |
|
| 1691 | + * @return void |
|
| 1692 | + */ |
|
| 1693 | + public function wp_loaded() |
|
| 1694 | + { |
|
| 1695 | + } |
|
| 1696 | + |
|
| 1697 | + |
|
| 1698 | + /** |
|
| 1699 | + * admin_notices |
|
| 1700 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
| 1701 | + * ALL EE_Admin pages. |
|
| 1702 | + * |
|
| 1703 | + * @return void |
|
| 1704 | + */ |
|
| 1705 | + public function admin_notices_global() |
|
| 1706 | + { |
|
| 1707 | + $this->_display_no_javascript_warning(); |
|
| 1708 | + $this->_display_espresso_notices(); |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + public function network_admin_notices_global() |
|
| 1713 | + { |
|
| 1714 | + $this->_display_no_javascript_warning(); |
|
| 1715 | + $this->_display_espresso_notices(); |
|
| 1716 | + } |
|
| 1717 | + |
|
| 1718 | + |
|
| 1719 | + /** |
|
| 1720 | + * admin_footer_scripts_global |
|
| 1721 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 1722 | + * will apply on ALL EE_Admin pages. |
|
| 1723 | + * |
|
| 1724 | + * @return void |
|
| 1725 | + */ |
|
| 1726 | + public function admin_footer_scripts_global() |
|
| 1727 | + { |
|
| 1728 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 1729 | + $this->_add_admin_page_overlay(); |
|
| 1730 | + // if metaboxes are present we need to add the nonce field |
|
| 1731 | + if ( |
|
| 1732 | + isset($this->_route_config['metaboxes']) |
|
| 1733 | + || isset($this->_route_config['list_table']) |
|
| 1734 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
| 1735 | + ) { |
|
| 1736 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
| 1737 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
| 1738 | + } |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + |
|
| 1742 | + /** |
|
| 1743 | + * admin_footer_global |
|
| 1744 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. |
|
| 1745 | + * This particular method will apply on ALL EE_Admin Pages. |
|
| 1746 | + * |
|
| 1747 | + * @return void |
|
| 1748 | + * @throws InvalidArgumentException |
|
| 1749 | + * @throws InvalidDataTypeException |
|
| 1750 | + * @throws InvalidInterfaceException |
|
| 1751 | + */ |
|
| 1752 | + public function admin_footer_global() |
|
| 1753 | + { |
|
| 1754 | + // dialog container for dialog helper |
|
| 1755 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1756 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
| 1757 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
| 1758 | + $d_cont .= '</div>'; |
|
| 1759 | + echo $d_cont; |
|
| 1760 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1761 | + // help tour stuff? |
|
| 1762 | + // if (isset($this->_help_tour[ $this->_req_action ])) { |
|
| 1763 | + // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
| 1764 | + // } |
|
| 1765 | + // current set timezone for timezone js |
|
| 1766 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + |
|
| 1770 | + /** |
|
| 1771 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
| 1772 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
| 1773 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
| 1774 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
| 1775 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
| 1776 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
| 1777 | + * for the |
|
| 1778 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
| 1779 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
| 1780 | + * 'help_trigger_id' => array( |
|
| 1781 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
| 1782 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
| 1783 | + * ) |
|
| 1784 | + * ); |
|
| 1785 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
| 1786 | + * |
|
| 1787 | + * @param array $help_array |
|
| 1788 | + * @param bool $display |
|
| 1789 | + * @return string content |
|
| 1790 | + * @throws DomainException |
|
| 1791 | + * @throws EE_Error |
|
| 1792 | + */ |
|
| 1793 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
| 1794 | + { |
|
| 1795 | + $content = ''; |
|
| 1796 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
| 1797 | + // loop through the array and setup content |
|
| 1798 | + foreach ($help_array as $trigger => $help) { |
|
| 1799 | + // make sure the array is setup properly |
|
| 1800 | + if (! isset($help['title'], $help['content'])) { |
|
| 1801 | + throw new EE_Error( |
|
| 1802 | + esc_html__( |
|
| 1803 | + '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', |
|
| 1804 | + 'event_espresso' |
|
| 1805 | + ) |
|
| 1806 | + ); |
|
| 1807 | + } |
|
| 1808 | + // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
| 1809 | + $template_args = array( |
|
| 1810 | + 'help_popup_id' => $trigger, |
|
| 1811 | + 'help_popup_title' => $help['title'], |
|
| 1812 | + 'help_popup_content' => $help['content'], |
|
| 1813 | + ); |
|
| 1814 | + $content .= EEH_Template::display_template( |
|
| 1815 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1816 | + $template_args, |
|
| 1817 | + true |
|
| 1818 | + ); |
|
| 1819 | + } |
|
| 1820 | + if ($display) { |
|
| 1821 | + echo $content; |
|
| 1822 | + return ''; |
|
| 1823 | + } |
|
| 1824 | + return $content; |
|
| 1825 | + } |
|
| 1826 | + |
|
| 1827 | + |
|
| 1828 | + /** |
|
| 1829 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
| 1830 | + * |
|
| 1831 | + * @return array properly formatted array for help popup content |
|
| 1832 | + * @throws EE_Error |
|
| 1833 | + */ |
|
| 1834 | + private function _get_help_content() |
|
| 1835 | + { |
|
| 1836 | + // what is the method we're looking for? |
|
| 1837 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1838 | + // if method doesn't exist let's get out. |
|
| 1839 | + if (! method_exists($this, $method_name)) { |
|
| 1840 | + return array(); |
|
| 1841 | + } |
|
| 1842 | + // k we're good to go let's retrieve the help array |
|
| 1843 | + $help_array = $this->{$method_name}(); |
|
| 1844 | + // make sure we've got an array! |
|
| 1845 | + if (! is_array($help_array)) { |
|
| 1846 | + throw new EE_Error( |
|
| 1847 | + esc_html__( |
|
| 1848 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
| 1849 | + 'event_espresso' |
|
| 1850 | + ) |
|
| 1851 | + ); |
|
| 1852 | + } |
|
| 1853 | + return $help_array; |
|
| 1854 | + } |
|
| 1855 | + |
|
| 1856 | + |
|
| 1857 | + /** |
|
| 1858 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
| 1859 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
| 1860 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
| 1861 | + * |
|
| 1862 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
| 1863 | + * @param boolean $display if false then we return the trigger string |
|
| 1864 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
| 1865 | + * @return string |
|
| 1866 | + * @throws DomainException |
|
| 1867 | + * @throws EE_Error |
|
| 1868 | + */ |
|
| 1869 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
| 1870 | + { |
|
| 1871 | + if (defined('DOING_AJAX')) { |
|
| 1872 | + return ''; |
|
| 1873 | + } |
|
| 1874 | + // 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 |
|
| 1875 | + $help_array = $this->_get_help_content(); |
|
| 1876 | + $help_content = ''; |
|
| 1877 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1878 | + $help_array[ $trigger_id ] = array( |
|
| 1879 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
| 1880 | + 'content' => esc_html__( |
|
| 1881 | + '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.)', |
|
| 1882 | + 'event_espresso' |
|
| 1883 | + ), |
|
| 1884 | + ); |
|
| 1885 | + $help_content = $this->_set_help_popup_content($help_array); |
|
| 1886 | + } |
|
| 1887 | + // let's setup the trigger |
|
| 1888 | + $content = '<a class="ee-dialog" href="?height=' |
|
| 1889 | + . $dimensions[0] |
|
| 1890 | + . '&width=' |
|
| 1891 | + . $dimensions[1] |
|
| 1892 | + . '&inlineId=' |
|
| 1893 | + . $trigger_id |
|
| 1894 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
| 1895 | + $content .= $help_content; |
|
| 1896 | + if ($display) { |
|
| 1897 | + echo $content; |
|
| 1898 | + return ''; |
|
| 1899 | + } |
|
| 1900 | + return $content; |
|
| 1901 | + } |
|
| 1902 | + |
|
| 1903 | + |
|
| 1904 | + /** |
|
| 1905 | + * _add_global_screen_options |
|
| 1906 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
| 1907 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
| 1908 | + * |
|
| 1909 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
| 1910 | + * see also WP_Screen object documents... |
|
| 1911 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
| 1912 | + * @abstract |
|
| 1913 | + * @return void |
|
| 1914 | + */ |
|
| 1915 | + private function _add_global_screen_options() |
|
| 1916 | + { |
|
| 1917 | + } |
|
| 1918 | + |
|
| 1919 | + |
|
| 1920 | + /** |
|
| 1921 | + * _add_global_feature_pointers |
|
| 1922 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
| 1923 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
| 1924 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
| 1925 | + * |
|
| 1926 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
| 1927 | + * extended) also see: |
|
| 1928 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
| 1929 | + * @abstract |
|
| 1930 | + * @return void |
|
| 1931 | + */ |
|
| 1932 | + private function _add_global_feature_pointers() |
|
| 1933 | + { |
|
| 1934 | + } |
|
| 1935 | + |
|
| 1936 | + |
|
| 1937 | + /** |
|
| 1938 | + * load_global_scripts_styles |
|
| 1939 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
| 1940 | + * |
|
| 1941 | + * @return void |
|
| 1942 | + * @throws EE_Error |
|
| 1943 | + */ |
|
| 1944 | + public function load_global_scripts_styles() |
|
| 1945 | + { |
|
| 1946 | + // add debugging styles |
|
| 1947 | + if (WP_DEBUG) { |
|
| 1948 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
| 1949 | + } |
|
| 1950 | + // taking care of metaboxes |
|
| 1951 | + if ( |
|
| 1952 | + empty($this->_cpt_route) |
|
| 1953 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
| 1954 | + ) { |
|
| 1955 | + wp_enqueue_script('dashboard'); |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + // LOCALIZED DATA |
|
| 1959 | + // localize script for ajax lazy loading |
|
| 1960 | + wp_localize_script( |
|
| 1961 | + EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN, |
|
| 1962 | + 'eeLazyLoadingContainers', |
|
| 1963 | + apply_filters( |
|
| 1964 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
| 1965 | + ['espresso_news_post_box_content'] |
|
| 1966 | + ) |
|
| 1967 | + ); |
|
| 1968 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 1969 | + // /** |
|
| 1970 | + // * help tour stuff |
|
| 1971 | + // */ |
|
| 1972 | + // if (! empty($this->_help_tour)) { |
|
| 1973 | + // // register the js for kicking things off |
|
| 1974 | + // wp_enqueue_script( |
|
| 1975 | + // 'ee-help-tour', |
|
| 1976 | + // EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
| 1977 | + // array('jquery-joyride'), |
|
| 1978 | + // EVENT_ESPRESSO_VERSION, |
|
| 1979 | + // true |
|
| 1980 | + // ); |
|
| 1981 | + // $tours = array(); |
|
| 1982 | + // // setup tours for the js tour object |
|
| 1983 | + // foreach ($this->_help_tour['tours'] as $tour) { |
|
| 1984 | + // if ($tour instanceof EE_Help_Tour) { |
|
| 1985 | + // $tours[] = array( |
|
| 1986 | + // 'id' => $tour->get_slug(), |
|
| 1987 | + // 'options' => $tour->get_options(), |
|
| 1988 | + // ); |
|
| 1989 | + // } |
|
| 1990 | + // } |
|
| 1991 | + // wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
| 1992 | + // // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
| 1993 | + // } |
|
| 1994 | + } |
|
| 1995 | + |
|
| 1996 | + |
|
| 1997 | + /** |
|
| 1998 | + * admin_footer_scripts_eei18n_js_strings |
|
| 1999 | + * |
|
| 2000 | + * @return void |
|
| 2001 | + */ |
|
| 2002 | + public function admin_footer_scripts_eei18n_js_strings() |
|
| 2003 | + { |
|
| 2004 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
| 2005 | + EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
| 2006 | + '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!!!', |
|
| 2007 | + 'event_espresso' |
|
| 2008 | + ); |
|
| 2009 | + EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
| 2010 | + EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
| 2011 | + EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
| 2012 | + EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
| 2013 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2014 | + EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
| 2015 | + EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
| 2016 | + EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
| 2017 | + EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
| 2018 | + EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
| 2019 | + EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
| 2020 | + EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
| 2021 | + EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
| 2022 | + EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
| 2023 | + EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
| 2024 | + EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
| 2025 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
| 2026 | + EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
| 2027 | + EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
| 2028 | + EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
| 2029 | + EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
| 2030 | + EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
| 2031 | + EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
| 2032 | + EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
| 2033 | + EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
| 2034 | + EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
| 2035 | + EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
| 2036 | + EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
| 2037 | + EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
| 2038 | + EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
| 2039 | + EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
| 2040 | + EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
| 2041 | + EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
| 2042 | + EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
| 2043 | + EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
| 2044 | + EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
| 2045 | + EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
| 2046 | + EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
| 2047 | + } |
|
| 2048 | + |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
| 2052 | + * |
|
| 2053 | + * @return void |
|
| 2054 | + */ |
|
| 2055 | + public function add_xdebug_style() |
|
| 2056 | + { |
|
| 2057 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
| 2058 | + } |
|
| 2059 | + |
|
| 2060 | + |
|
| 2061 | + /************************/ |
|
| 2062 | + /** LIST TABLE METHODS **/ |
|
| 2063 | + /************************/ |
|
| 2064 | + /** |
|
| 2065 | + * this sets up the list table if the current view requires it. |
|
| 2066 | + * |
|
| 2067 | + * @return void |
|
| 2068 | + * @throws EE_Error |
|
| 2069 | + * @throws InvalidArgumentException |
|
| 2070 | + * @throws InvalidDataTypeException |
|
| 2071 | + * @throws InvalidInterfaceException |
|
| 2072 | + */ |
|
| 2073 | + protected function _set_list_table() |
|
| 2074 | + { |
|
| 2075 | + // first is this a list_table view? |
|
| 2076 | + if (! isset($this->_route_config['list_table'])) { |
|
| 2077 | + return; |
|
| 2078 | + } //not a list_table view so get out. |
|
| 2079 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
| 2080 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2081 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2082 | + // user error msg |
|
| 2083 | + $error_msg = esc_html__( |
|
| 2084 | + 'An error occurred. The requested list table views could not be found.', |
|
| 2085 | + 'event_espresso' |
|
| 2086 | + ); |
|
| 2087 | + // developer error msg |
|
| 2088 | + $error_msg .= '||' |
|
| 2089 | + . sprintf( |
|
| 2090 | + esc_html__( |
|
| 2091 | + '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.', |
|
| 2092 | + 'event_espresso' |
|
| 2093 | + ), |
|
| 2094 | + $this->_req_action, |
|
| 2095 | + $list_table_view |
|
| 2096 | + ); |
|
| 2097 | + throw new EE_Error($error_msg); |
|
| 2098 | + } |
|
| 2099 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
| 2100 | + $this->_views = apply_filters( |
|
| 2101 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2102 | + $this->_views |
|
| 2103 | + ); |
|
| 2104 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2105 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
| 2106 | + $this->_set_list_table_view(); |
|
| 2107 | + $this->_set_list_table_object(); |
|
| 2108 | + } |
|
| 2109 | + |
|
| 2110 | + |
|
| 2111 | + /** |
|
| 2112 | + * set current view for List Table |
|
| 2113 | + * |
|
| 2114 | + * @return void |
|
| 2115 | + */ |
|
| 2116 | + protected function _set_list_table_view() |
|
| 2117 | + { |
|
| 2118 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2119 | + // looking at active items or dumpster diving ? |
|
| 2120 | + if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2121 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
| 2122 | + } else { |
|
| 2123 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
| 2124 | + } |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + |
|
| 2128 | + /** |
|
| 2129 | + * _set_list_table_object |
|
| 2130 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
| 2131 | + * |
|
| 2132 | + * @throws InvalidInterfaceException |
|
| 2133 | + * @throws InvalidArgumentException |
|
| 2134 | + * @throws InvalidDataTypeException |
|
| 2135 | + * @throws EE_Error |
|
| 2136 | + * @throws InvalidInterfaceException |
|
| 2137 | + */ |
|
| 2138 | + protected function _set_list_table_object() |
|
| 2139 | + { |
|
| 2140 | + if (isset($this->_route_config['list_table'])) { |
|
| 2141 | + if (! class_exists($this->_route_config['list_table'])) { |
|
| 2142 | + throw new EE_Error( |
|
| 2143 | + sprintf( |
|
| 2144 | + esc_html__( |
|
| 2145 | + '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.', |
|
| 2146 | + 'event_espresso' |
|
| 2147 | + ), |
|
| 2148 | + $this->_route_config['list_table'], |
|
| 2149 | + get_class($this) |
|
| 2150 | + ) |
|
| 2151 | + ); |
|
| 2152 | + } |
|
| 2153 | + $this->_list_table_object = $this->loader->getShared( |
|
| 2154 | + $this->_route_config['list_table'], |
|
| 2155 | + array($this) |
|
| 2156 | + ); |
|
| 2157 | + } |
|
| 2158 | + } |
|
| 2159 | + |
|
| 2160 | + |
|
| 2161 | + /** |
|
| 2162 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
| 2163 | + * |
|
| 2164 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
| 2165 | + * urls. The array should be indexed by the view it is being |
|
| 2166 | + * added to. |
|
| 2167 | + * @return array |
|
| 2168 | + */ |
|
| 2169 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
| 2170 | + { |
|
| 2171 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2172 | + if (empty($this->_views)) { |
|
| 2173 | + $this->_views = array(); |
|
| 2174 | + } |
|
| 2175 | + // cycle thru views |
|
| 2176 | + foreach ($this->_views as $key => $view) { |
|
| 2177 | + $query_args = array(); |
|
| 2178 | + // check for current view |
|
| 2179 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2180 | + $query_args['action'] = $this->_req_action; |
|
| 2181 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2182 | + $query_args['status'] = $view['slug']; |
|
| 2183 | + // merge any other arguments sent in. |
|
| 2184 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2185 | + foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2186 | + $query_args[] = $extra_query_arg; |
|
| 2187 | + } |
|
| 2188 | + } |
|
| 2189 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2190 | + } |
|
| 2191 | + return $this->_views; |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + |
|
| 2195 | + /** |
|
| 2196 | + * _entries_per_page_dropdown |
|
| 2197 | + * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
| 2198 | + * |
|
| 2199 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
| 2200 | + * WP does it. |
|
| 2201 | + * @param int $max_entries total number of rows in the table |
|
| 2202 | + * @return string |
|
| 2203 | + */ |
|
| 2204 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
| 2205 | + { |
|
| 2206 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2207 | + $values = array(10, 25, 50, 100); |
|
| 2208 | + $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2209 | + if ($max_entries) { |
|
| 2210 | + $values[] = $max_entries; |
|
| 2211 | + sort($values); |
|
| 2212 | + } |
|
| 2213 | + $entries_per_page_dropdown = ' |
|
| 2214 | 2214 | <div id="entries-per-page-dv" class="alignleft actions"> |
| 2215 | 2215 | <label class="hide-if-no-js"> |
| 2216 | 2216 | Show |
| 2217 | 2217 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2218 | - foreach ($values as $value) { |
|
| 2219 | - if ($value < $max_entries) { |
|
| 2220 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2221 | - $entries_per_page_dropdown .= ' |
|
| 2218 | + foreach ($values as $value) { |
|
| 2219 | + if ($value < $max_entries) { |
|
| 2220 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2221 | + $entries_per_page_dropdown .= ' |
|
| 2222 | 2222 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
| 2223 | - } |
|
| 2224 | - } |
|
| 2225 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2226 | - $entries_per_page_dropdown .= ' |
|
| 2223 | + } |
|
| 2224 | + } |
|
| 2225 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2226 | + $entries_per_page_dropdown .= ' |
|
| 2227 | 2227 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
| 2228 | - $entries_per_page_dropdown .= ' |
|
| 2228 | + $entries_per_page_dropdown .= ' |
|
| 2229 | 2229 | </select> |
| 2230 | 2230 | entries |
| 2231 | 2231 | </label> |
| 2232 | 2232 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
| 2233 | 2233 | </div> |
| 2234 | 2234 | '; |
| 2235 | - return $entries_per_page_dropdown; |
|
| 2236 | - } |
|
| 2237 | - |
|
| 2238 | - |
|
| 2239 | - /** |
|
| 2240 | - * _set_search_attributes |
|
| 2241 | - * |
|
| 2242 | - * @return void |
|
| 2243 | - */ |
|
| 2244 | - public function _set_search_attributes() |
|
| 2245 | - { |
|
| 2246 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2247 | - esc_html__('Search %s', 'event_espresso'), |
|
| 2248 | - empty($this->_search_btn_label) ? $this->page_label |
|
| 2249 | - : $this->_search_btn_label |
|
| 2250 | - ); |
|
| 2251 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2252 | - } |
|
| 2253 | - |
|
| 2254 | - |
|
| 2255 | - |
|
| 2256 | - /*** END LIST TABLE METHODS **/ |
|
| 2257 | - |
|
| 2258 | - |
|
| 2259 | - /** |
|
| 2260 | - * _add_registered_metaboxes |
|
| 2261 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2262 | - * |
|
| 2263 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2264 | - * @return void |
|
| 2265 | - * @throws EE_Error |
|
| 2266 | - */ |
|
| 2267 | - private function _add_registered_meta_boxes() |
|
| 2268 | - { |
|
| 2269 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2270 | - // we only add meta boxes if the page_route calls for it |
|
| 2271 | - if ( |
|
| 2272 | - is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2273 | - && is_array( |
|
| 2274 | - $this->_route_config['metaboxes'] |
|
| 2275 | - ) |
|
| 2276 | - ) { |
|
| 2277 | - // this simply loops through the callbacks provided |
|
| 2278 | - // and checks if there is a corresponding callback registered by the child |
|
| 2279 | - // if there is then we go ahead and process the metabox loader. |
|
| 2280 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2281 | - // first check for Closures |
|
| 2282 | - if ($metabox_callback instanceof Closure) { |
|
| 2283 | - $result = $metabox_callback(); |
|
| 2284 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2285 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2286 | - } else { |
|
| 2287 | - $result = $this->{$metabox_callback}(); |
|
| 2288 | - } |
|
| 2289 | - if ($result === false) { |
|
| 2290 | - // user error msg |
|
| 2291 | - $error_msg = esc_html__( |
|
| 2292 | - 'An error occurred. The requested metabox could not be found.', |
|
| 2293 | - 'event_espresso' |
|
| 2294 | - ); |
|
| 2295 | - // developer error msg |
|
| 2296 | - $error_msg .= '||' |
|
| 2297 | - . sprintf( |
|
| 2298 | - esc_html__( |
|
| 2299 | - '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.', |
|
| 2300 | - 'event_espresso' |
|
| 2301 | - ), |
|
| 2302 | - $metabox_callback |
|
| 2303 | - ); |
|
| 2304 | - throw new EE_Error($error_msg); |
|
| 2305 | - } |
|
| 2306 | - } |
|
| 2307 | - } |
|
| 2308 | - } |
|
| 2309 | - |
|
| 2310 | - |
|
| 2311 | - /** |
|
| 2312 | - * _add_screen_columns |
|
| 2313 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2314 | - * the dynamic column template and we'll setup the column options for the page. |
|
| 2315 | - * |
|
| 2316 | - * @return void |
|
| 2317 | - */ |
|
| 2318 | - private function _add_screen_columns() |
|
| 2319 | - { |
|
| 2320 | - if ( |
|
| 2321 | - is_array($this->_route_config) |
|
| 2322 | - && isset($this->_route_config['columns']) |
|
| 2323 | - && is_array($this->_route_config['columns']) |
|
| 2324 | - && count($this->_route_config['columns']) === 2 |
|
| 2325 | - ) { |
|
| 2326 | - add_screen_option( |
|
| 2327 | - 'layout_columns', |
|
| 2328 | - array( |
|
| 2329 | - 'max' => (int) $this->_route_config['columns'][0], |
|
| 2330 | - 'default' => (int) $this->_route_config['columns'][1], |
|
| 2331 | - ) |
|
| 2332 | - ); |
|
| 2333 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2334 | - $screen_id = $this->_current_screen->id; |
|
| 2335 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2336 | - $total_columns = ! empty($screen_columns) |
|
| 2337 | - ? $screen_columns |
|
| 2338 | - : $this->_route_config['columns'][1]; |
|
| 2339 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2340 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2341 | - $this->_template_args['screen'] = $this->_current_screen; |
|
| 2342 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2343 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2344 | - // finally if we don't have has_metaboxes set in the route config |
|
| 2345 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2346 | - $this->_route_config['has_metaboxes'] = true; |
|
| 2347 | - } |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - |
|
| 2351 | - |
|
| 2352 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2353 | - |
|
| 2354 | - |
|
| 2355 | - /** |
|
| 2356 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2357 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2358 | - * these get loaded on. |
|
| 2359 | - */ |
|
| 2360 | - private function _espresso_news_post_box() |
|
| 2361 | - { |
|
| 2362 | - $news_box_title = apply_filters( |
|
| 2363 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2364 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2365 | - ); |
|
| 2366 | - add_meta_box( |
|
| 2367 | - 'espresso_news_post_box', |
|
| 2368 | - $news_box_title, |
|
| 2369 | - array( |
|
| 2370 | - $this, |
|
| 2371 | - 'espresso_news_post_box', |
|
| 2372 | - ), |
|
| 2373 | - $this->_wp_page_slug, |
|
| 2374 | - 'side' |
|
| 2375 | - ); |
|
| 2376 | - } |
|
| 2377 | - |
|
| 2378 | - |
|
| 2379 | - /** |
|
| 2380 | - * Code for setting up espresso ratings request metabox. |
|
| 2381 | - */ |
|
| 2382 | - protected function _espresso_ratings_request() |
|
| 2383 | - { |
|
| 2384 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2385 | - return; |
|
| 2386 | - } |
|
| 2387 | - $ratings_box_title = apply_filters( |
|
| 2388 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2389 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2390 | - ); |
|
| 2391 | - add_meta_box( |
|
| 2392 | - 'espresso_ratings_request', |
|
| 2393 | - $ratings_box_title, |
|
| 2394 | - array( |
|
| 2395 | - $this, |
|
| 2396 | - 'espresso_ratings_request', |
|
| 2397 | - ), |
|
| 2398 | - $this->_wp_page_slug, |
|
| 2399 | - 'side' |
|
| 2400 | - ); |
|
| 2401 | - } |
|
| 2402 | - |
|
| 2403 | - |
|
| 2404 | - /** |
|
| 2405 | - * Code for setting up espresso ratings request metabox content. |
|
| 2406 | - * |
|
| 2407 | - * @throws DomainException |
|
| 2408 | - */ |
|
| 2409 | - public function espresso_ratings_request() |
|
| 2410 | - { |
|
| 2411 | - EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2412 | - } |
|
| 2413 | - |
|
| 2414 | - |
|
| 2415 | - public static function cached_rss_display($rss_id, $url) |
|
| 2416 | - { |
|
| 2417 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2418 | - . __('Loading…', 'event_espresso') |
|
| 2419 | - . '</p><p class="hide-if-js">' |
|
| 2420 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2421 | - . '</p>'; |
|
| 2422 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2423 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2424 | - $post = '</div>' . "\n"; |
|
| 2425 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2426 | - $output = get_transient($cache_key); |
|
| 2427 | - if ($output !== false) { |
|
| 2428 | - echo $pre . $output . $post; |
|
| 2429 | - return true; |
|
| 2430 | - } |
|
| 2431 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2432 | - echo $pre . $loading . $post; |
|
| 2433 | - return false; |
|
| 2434 | - } |
|
| 2435 | - ob_start(); |
|
| 2436 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2437 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2438 | - return true; |
|
| 2439 | - } |
|
| 2440 | - |
|
| 2441 | - |
|
| 2442 | - public function espresso_news_post_box() |
|
| 2443 | - { |
|
| 2444 | - ?> |
|
| 2235 | + return $entries_per_page_dropdown; |
|
| 2236 | + } |
|
| 2237 | + |
|
| 2238 | + |
|
| 2239 | + /** |
|
| 2240 | + * _set_search_attributes |
|
| 2241 | + * |
|
| 2242 | + * @return void |
|
| 2243 | + */ |
|
| 2244 | + public function _set_search_attributes() |
|
| 2245 | + { |
|
| 2246 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
| 2247 | + esc_html__('Search %s', 'event_espresso'), |
|
| 2248 | + empty($this->_search_btn_label) ? $this->page_label |
|
| 2249 | + : $this->_search_btn_label |
|
| 2250 | + ); |
|
| 2251 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + |
|
| 2255 | + |
|
| 2256 | + /*** END LIST TABLE METHODS **/ |
|
| 2257 | + |
|
| 2258 | + |
|
| 2259 | + /** |
|
| 2260 | + * _add_registered_metaboxes |
|
| 2261 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
| 2262 | + * |
|
| 2263 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
| 2264 | + * @return void |
|
| 2265 | + * @throws EE_Error |
|
| 2266 | + */ |
|
| 2267 | + private function _add_registered_meta_boxes() |
|
| 2268 | + { |
|
| 2269 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2270 | + // we only add meta boxes if the page_route calls for it |
|
| 2271 | + if ( |
|
| 2272 | + is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
| 2273 | + && is_array( |
|
| 2274 | + $this->_route_config['metaboxes'] |
|
| 2275 | + ) |
|
| 2276 | + ) { |
|
| 2277 | + // this simply loops through the callbacks provided |
|
| 2278 | + // and checks if there is a corresponding callback registered by the child |
|
| 2279 | + // if there is then we go ahead and process the metabox loader. |
|
| 2280 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
| 2281 | + // first check for Closures |
|
| 2282 | + if ($metabox_callback instanceof Closure) { |
|
| 2283 | + $result = $metabox_callback(); |
|
| 2284 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
| 2285 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
| 2286 | + } else { |
|
| 2287 | + $result = $this->{$metabox_callback}(); |
|
| 2288 | + } |
|
| 2289 | + if ($result === false) { |
|
| 2290 | + // user error msg |
|
| 2291 | + $error_msg = esc_html__( |
|
| 2292 | + 'An error occurred. The requested metabox could not be found.', |
|
| 2293 | + 'event_espresso' |
|
| 2294 | + ); |
|
| 2295 | + // developer error msg |
|
| 2296 | + $error_msg .= '||' |
|
| 2297 | + . sprintf( |
|
| 2298 | + esc_html__( |
|
| 2299 | + '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.', |
|
| 2300 | + 'event_espresso' |
|
| 2301 | + ), |
|
| 2302 | + $metabox_callback |
|
| 2303 | + ); |
|
| 2304 | + throw new EE_Error($error_msg); |
|
| 2305 | + } |
|
| 2306 | + } |
|
| 2307 | + } |
|
| 2308 | + } |
|
| 2309 | + |
|
| 2310 | + |
|
| 2311 | + /** |
|
| 2312 | + * _add_screen_columns |
|
| 2313 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
| 2314 | + * the dynamic column template and we'll setup the column options for the page. |
|
| 2315 | + * |
|
| 2316 | + * @return void |
|
| 2317 | + */ |
|
| 2318 | + private function _add_screen_columns() |
|
| 2319 | + { |
|
| 2320 | + if ( |
|
| 2321 | + is_array($this->_route_config) |
|
| 2322 | + && isset($this->_route_config['columns']) |
|
| 2323 | + && is_array($this->_route_config['columns']) |
|
| 2324 | + && count($this->_route_config['columns']) === 2 |
|
| 2325 | + ) { |
|
| 2326 | + add_screen_option( |
|
| 2327 | + 'layout_columns', |
|
| 2328 | + array( |
|
| 2329 | + 'max' => (int) $this->_route_config['columns'][0], |
|
| 2330 | + 'default' => (int) $this->_route_config['columns'][1], |
|
| 2331 | + ) |
|
| 2332 | + ); |
|
| 2333 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
| 2334 | + $screen_id = $this->_current_screen->id; |
|
| 2335 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
| 2336 | + $total_columns = ! empty($screen_columns) |
|
| 2337 | + ? $screen_columns |
|
| 2338 | + : $this->_route_config['columns'][1]; |
|
| 2339 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2340 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2341 | + $this->_template_args['screen'] = $this->_current_screen; |
|
| 2342 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
| 2343 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
| 2344 | + // finally if we don't have has_metaboxes set in the route config |
|
| 2345 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
| 2346 | + $this->_route_config['has_metaboxes'] = true; |
|
| 2347 | + } |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + |
|
| 2351 | + |
|
| 2352 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
| 2353 | + |
|
| 2354 | + |
|
| 2355 | + /** |
|
| 2356 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
| 2357 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
| 2358 | + * these get loaded on. |
|
| 2359 | + */ |
|
| 2360 | + private function _espresso_news_post_box() |
|
| 2361 | + { |
|
| 2362 | + $news_box_title = apply_filters( |
|
| 2363 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2364 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
| 2365 | + ); |
|
| 2366 | + add_meta_box( |
|
| 2367 | + 'espresso_news_post_box', |
|
| 2368 | + $news_box_title, |
|
| 2369 | + array( |
|
| 2370 | + $this, |
|
| 2371 | + 'espresso_news_post_box', |
|
| 2372 | + ), |
|
| 2373 | + $this->_wp_page_slug, |
|
| 2374 | + 'side' |
|
| 2375 | + ); |
|
| 2376 | + } |
|
| 2377 | + |
|
| 2378 | + |
|
| 2379 | + /** |
|
| 2380 | + * Code for setting up espresso ratings request metabox. |
|
| 2381 | + */ |
|
| 2382 | + protected function _espresso_ratings_request() |
|
| 2383 | + { |
|
| 2384 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2385 | + return; |
|
| 2386 | + } |
|
| 2387 | + $ratings_box_title = apply_filters( |
|
| 2388 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
| 2389 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
| 2390 | + ); |
|
| 2391 | + add_meta_box( |
|
| 2392 | + 'espresso_ratings_request', |
|
| 2393 | + $ratings_box_title, |
|
| 2394 | + array( |
|
| 2395 | + $this, |
|
| 2396 | + 'espresso_ratings_request', |
|
| 2397 | + ), |
|
| 2398 | + $this->_wp_page_slug, |
|
| 2399 | + 'side' |
|
| 2400 | + ); |
|
| 2401 | + } |
|
| 2402 | + |
|
| 2403 | + |
|
| 2404 | + /** |
|
| 2405 | + * Code for setting up espresso ratings request metabox content. |
|
| 2406 | + * |
|
| 2407 | + * @throws DomainException |
|
| 2408 | + */ |
|
| 2409 | + public function espresso_ratings_request() |
|
| 2410 | + { |
|
| 2411 | + EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2412 | + } |
|
| 2413 | + |
|
| 2414 | + |
|
| 2415 | + public static function cached_rss_display($rss_id, $url) |
|
| 2416 | + { |
|
| 2417 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
| 2418 | + . __('Loading…', 'event_espresso') |
|
| 2419 | + . '</p><p class="hide-if-js">' |
|
| 2420 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
| 2421 | + . '</p>'; |
|
| 2422 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2423 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2424 | + $post = '</div>' . "\n"; |
|
| 2425 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2426 | + $output = get_transient($cache_key); |
|
| 2427 | + if ($output !== false) { |
|
| 2428 | + echo $pre . $output . $post; |
|
| 2429 | + return true; |
|
| 2430 | + } |
|
| 2431 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2432 | + echo $pre . $loading . $post; |
|
| 2433 | + return false; |
|
| 2434 | + } |
|
| 2435 | + ob_start(); |
|
| 2436 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
| 2437 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
| 2438 | + return true; |
|
| 2439 | + } |
|
| 2440 | + |
|
| 2441 | + |
|
| 2442 | + public function espresso_news_post_box() |
|
| 2443 | + { |
|
| 2444 | + ?> |
|
| 2445 | 2445 | <div class="padding"> |
| 2446 | 2446 | <div id="espresso_news_post_box_content" class="infolinks"> |
| 2447 | 2447 | <?php |
| 2448 | - // Get RSS Feed(s) |
|
| 2449 | - EE_Admin_Page::cached_rss_display( |
|
| 2450 | - 'espresso_news_post_box_content', |
|
| 2451 | - urlencode( |
|
| 2452 | - apply_filters( |
|
| 2453 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2454 | - 'http://eventespresso.com/feed/' |
|
| 2455 | - ) |
|
| 2456 | - ) |
|
| 2457 | - ); |
|
| 2458 | - ?> |
|
| 2448 | + // Get RSS Feed(s) |
|
| 2449 | + EE_Admin_Page::cached_rss_display( |
|
| 2450 | + 'espresso_news_post_box_content', |
|
| 2451 | + urlencode( |
|
| 2452 | + apply_filters( |
|
| 2453 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
| 2454 | + 'http://eventespresso.com/feed/' |
|
| 2455 | + ) |
|
| 2456 | + ) |
|
| 2457 | + ); |
|
| 2458 | + ?> |
|
| 2459 | 2459 | </div> |
| 2460 | 2460 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
| 2461 | 2461 | </div> |
| 2462 | 2462 | <?php |
| 2463 | - } |
|
| 2464 | - |
|
| 2465 | - |
|
| 2466 | - private function _espresso_links_post_box() |
|
| 2467 | - { |
|
| 2468 | - // Hiding until we actually have content to put in here... |
|
| 2469 | - // 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'); |
|
| 2470 | - } |
|
| 2471 | - |
|
| 2472 | - |
|
| 2473 | - public function espresso_links_post_box() |
|
| 2474 | - { |
|
| 2475 | - // Hiding until we actually have content to put in here... |
|
| 2476 | - // EEH_Template::display_template( |
|
| 2477 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2478 | - // ); |
|
| 2479 | - } |
|
| 2480 | - |
|
| 2481 | - |
|
| 2482 | - protected function _espresso_sponsors_post_box() |
|
| 2483 | - { |
|
| 2484 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2485 | - add_meta_box( |
|
| 2486 | - 'espresso_sponsors_post_box', |
|
| 2487 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2488 | - array($this, 'espresso_sponsors_post_box'), |
|
| 2489 | - $this->_wp_page_slug, |
|
| 2490 | - 'side' |
|
| 2491 | - ); |
|
| 2492 | - } |
|
| 2493 | - } |
|
| 2494 | - |
|
| 2495 | - |
|
| 2496 | - public function espresso_sponsors_post_box() |
|
| 2497 | - { |
|
| 2498 | - EEH_Template::display_template( |
|
| 2499 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2500 | - ); |
|
| 2501 | - } |
|
| 2502 | - |
|
| 2503 | - |
|
| 2504 | - private function _publish_post_box() |
|
| 2505 | - { |
|
| 2506 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2507 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2508 | - // then we'll use that for the metabox label. |
|
| 2509 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2510 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2511 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2512 | - : $this->_labels['publishbox']; |
|
| 2513 | - } else { |
|
| 2514 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2515 | - } |
|
| 2516 | - $box_label = apply_filters( |
|
| 2517 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2518 | - $box_label, |
|
| 2519 | - $this->_req_action, |
|
| 2520 | - $this |
|
| 2521 | - ); |
|
| 2522 | - add_meta_box( |
|
| 2523 | - $meta_box_ref, |
|
| 2524 | - $box_label, |
|
| 2525 | - array($this, 'editor_overview'), |
|
| 2526 | - $this->_current_screen->id, |
|
| 2527 | - 'side', |
|
| 2528 | - 'high' |
|
| 2529 | - ); |
|
| 2530 | - } |
|
| 2531 | - |
|
| 2532 | - |
|
| 2533 | - public function editor_overview() |
|
| 2534 | - { |
|
| 2535 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2536 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2537 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2538 | - : ''; |
|
| 2539 | - echo EEH_Template::display_template( |
|
| 2540 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2541 | - $this->_template_args, |
|
| 2542 | - true |
|
| 2543 | - ); |
|
| 2544 | - } |
|
| 2545 | - |
|
| 2546 | - |
|
| 2547 | - /** end of globally available metaboxes section **/ |
|
| 2548 | - |
|
| 2549 | - |
|
| 2550 | - /** |
|
| 2551 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2552 | - * protected method. |
|
| 2553 | - * |
|
| 2554 | - * @see $this->_set_publish_post_box_vars for param details |
|
| 2555 | - * @since 4.6.0 |
|
| 2556 | - * @param string $name |
|
| 2557 | - * @param int $id |
|
| 2558 | - * @param bool $delete |
|
| 2559 | - * @param string $save_close_redirect_URL |
|
| 2560 | - * @param bool $both_btns |
|
| 2561 | - * @throws EE_Error |
|
| 2562 | - * @throws InvalidArgumentException |
|
| 2563 | - * @throws InvalidDataTypeException |
|
| 2564 | - * @throws InvalidInterfaceException |
|
| 2565 | - */ |
|
| 2566 | - public function set_publish_post_box_vars( |
|
| 2567 | - $name = '', |
|
| 2568 | - $id = 0, |
|
| 2569 | - $delete = false, |
|
| 2570 | - $save_close_redirect_URL = '', |
|
| 2571 | - $both_btns = true |
|
| 2572 | - ) { |
|
| 2573 | - $this->_set_publish_post_box_vars( |
|
| 2574 | - $name, |
|
| 2575 | - $id, |
|
| 2576 | - $delete, |
|
| 2577 | - $save_close_redirect_URL, |
|
| 2578 | - $both_btns |
|
| 2579 | - ); |
|
| 2580 | - } |
|
| 2581 | - |
|
| 2582 | - |
|
| 2583 | - /** |
|
| 2584 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2585 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2586 | - * save, and save and close buttons to work properly, then you will want to include a |
|
| 2587 | - * values for the name and id arguments. |
|
| 2588 | - * |
|
| 2589 | - * @todo Add in validation for name/id arguments. |
|
| 2590 | - * @param string $name key used for the action ID (i.e. event_id) |
|
| 2591 | - * @param int $id id attached to the item published |
|
| 2592 | - * @param string $delete page route callback for the delete action |
|
| 2593 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2594 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2595 | - * the Save button |
|
| 2596 | - * @throws EE_Error |
|
| 2597 | - * @throws InvalidArgumentException |
|
| 2598 | - * @throws InvalidDataTypeException |
|
| 2599 | - * @throws InvalidInterfaceException |
|
| 2600 | - */ |
|
| 2601 | - protected function _set_publish_post_box_vars( |
|
| 2602 | - $name = '', |
|
| 2603 | - $id = 0, |
|
| 2604 | - $delete = '', |
|
| 2605 | - $save_close_redirect_URL = '', |
|
| 2606 | - $both_btns = true |
|
| 2607 | - ) { |
|
| 2608 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2609 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2610 | - ? $save_close_redirect_URL |
|
| 2611 | - : $this->_admin_base_url; |
|
| 2612 | - // create the Save & Close and Save buttons |
|
| 2613 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2614 | - // if we have extra content set let's add it in if not make sure its empty |
|
| 2615 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2616 | - ? $this->_template_args['publish_box_extra_content'] |
|
| 2617 | - : ''; |
|
| 2618 | - if ($delete && ! empty($id)) { |
|
| 2619 | - // make sure we have a default if just true is sent. |
|
| 2620 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2621 | - $delete_link_args = array($name => $id); |
|
| 2622 | - $delete = $this->get_action_link_or_button( |
|
| 2623 | - $delete, |
|
| 2624 | - $delete, |
|
| 2625 | - $delete_link_args, |
|
| 2626 | - 'submitdelete deletion' |
|
| 2627 | - ); |
|
| 2628 | - } |
|
| 2629 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2630 | - if (! empty($name) && ! empty($id)) { |
|
| 2631 | - $hidden_field_arr[ $name ] = array( |
|
| 2632 | - 'type' => 'hidden', |
|
| 2633 | - 'value' => $id, |
|
| 2634 | - ); |
|
| 2635 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2636 | - } else { |
|
| 2637 | - $hf = ''; |
|
| 2638 | - } |
|
| 2639 | - // add hidden field |
|
| 2640 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2641 | - ? $hf[ $name ]['field'] |
|
| 2642 | - : $hf; |
|
| 2643 | - } |
|
| 2644 | - |
|
| 2645 | - |
|
| 2646 | - /** |
|
| 2647 | - * displays an error message to ppl who have javascript disabled |
|
| 2648 | - * |
|
| 2649 | - * @return void |
|
| 2650 | - */ |
|
| 2651 | - private function _display_no_javascript_warning() |
|
| 2652 | - { |
|
| 2653 | - ?> |
|
| 2463 | + } |
|
| 2464 | + |
|
| 2465 | + |
|
| 2466 | + private function _espresso_links_post_box() |
|
| 2467 | + { |
|
| 2468 | + // Hiding until we actually have content to put in here... |
|
| 2469 | + // 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'); |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + |
|
| 2473 | + public function espresso_links_post_box() |
|
| 2474 | + { |
|
| 2475 | + // Hiding until we actually have content to put in here... |
|
| 2476 | + // EEH_Template::display_template( |
|
| 2477 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
| 2478 | + // ); |
|
| 2479 | + } |
|
| 2480 | + |
|
| 2481 | + |
|
| 2482 | + protected function _espresso_sponsors_post_box() |
|
| 2483 | + { |
|
| 2484 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
| 2485 | + add_meta_box( |
|
| 2486 | + 'espresso_sponsors_post_box', |
|
| 2487 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
| 2488 | + array($this, 'espresso_sponsors_post_box'), |
|
| 2489 | + $this->_wp_page_slug, |
|
| 2490 | + 'side' |
|
| 2491 | + ); |
|
| 2492 | + } |
|
| 2493 | + } |
|
| 2494 | + |
|
| 2495 | + |
|
| 2496 | + public function espresso_sponsors_post_box() |
|
| 2497 | + { |
|
| 2498 | + EEH_Template::display_template( |
|
| 2499 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2500 | + ); |
|
| 2501 | + } |
|
| 2502 | + |
|
| 2503 | + |
|
| 2504 | + private function _publish_post_box() |
|
| 2505 | + { |
|
| 2506 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2507 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
| 2508 | + // then we'll use that for the metabox label. |
|
| 2509 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
| 2510 | + if (! empty($this->_labels['publishbox'])) { |
|
| 2511 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2512 | + : $this->_labels['publishbox']; |
|
| 2513 | + } else { |
|
| 2514 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
| 2515 | + } |
|
| 2516 | + $box_label = apply_filters( |
|
| 2517 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
| 2518 | + $box_label, |
|
| 2519 | + $this->_req_action, |
|
| 2520 | + $this |
|
| 2521 | + ); |
|
| 2522 | + add_meta_box( |
|
| 2523 | + $meta_box_ref, |
|
| 2524 | + $box_label, |
|
| 2525 | + array($this, 'editor_overview'), |
|
| 2526 | + $this->_current_screen->id, |
|
| 2527 | + 'side', |
|
| 2528 | + 'high' |
|
| 2529 | + ); |
|
| 2530 | + } |
|
| 2531 | + |
|
| 2532 | + |
|
| 2533 | + public function editor_overview() |
|
| 2534 | + { |
|
| 2535 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2536 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2537 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2538 | + : ''; |
|
| 2539 | + echo EEH_Template::display_template( |
|
| 2540 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2541 | + $this->_template_args, |
|
| 2542 | + true |
|
| 2543 | + ); |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + |
|
| 2547 | + /** end of globally available metaboxes section **/ |
|
| 2548 | + |
|
| 2549 | + |
|
| 2550 | + /** |
|
| 2551 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
| 2552 | + * protected method. |
|
| 2553 | + * |
|
| 2554 | + * @see $this->_set_publish_post_box_vars for param details |
|
| 2555 | + * @since 4.6.0 |
|
| 2556 | + * @param string $name |
|
| 2557 | + * @param int $id |
|
| 2558 | + * @param bool $delete |
|
| 2559 | + * @param string $save_close_redirect_URL |
|
| 2560 | + * @param bool $both_btns |
|
| 2561 | + * @throws EE_Error |
|
| 2562 | + * @throws InvalidArgumentException |
|
| 2563 | + * @throws InvalidDataTypeException |
|
| 2564 | + * @throws InvalidInterfaceException |
|
| 2565 | + */ |
|
| 2566 | + public function set_publish_post_box_vars( |
|
| 2567 | + $name = '', |
|
| 2568 | + $id = 0, |
|
| 2569 | + $delete = false, |
|
| 2570 | + $save_close_redirect_URL = '', |
|
| 2571 | + $both_btns = true |
|
| 2572 | + ) { |
|
| 2573 | + $this->_set_publish_post_box_vars( |
|
| 2574 | + $name, |
|
| 2575 | + $id, |
|
| 2576 | + $delete, |
|
| 2577 | + $save_close_redirect_URL, |
|
| 2578 | + $both_btns |
|
| 2579 | + ); |
|
| 2580 | + } |
|
| 2581 | + |
|
| 2582 | + |
|
| 2583 | + /** |
|
| 2584 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
| 2585 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
| 2586 | + * save, and save and close buttons to work properly, then you will want to include a |
|
| 2587 | + * values for the name and id arguments. |
|
| 2588 | + * |
|
| 2589 | + * @todo Add in validation for name/id arguments. |
|
| 2590 | + * @param string $name key used for the action ID (i.e. event_id) |
|
| 2591 | + * @param int $id id attached to the item published |
|
| 2592 | + * @param string $delete page route callback for the delete action |
|
| 2593 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
| 2594 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
| 2595 | + * the Save button |
|
| 2596 | + * @throws EE_Error |
|
| 2597 | + * @throws InvalidArgumentException |
|
| 2598 | + * @throws InvalidDataTypeException |
|
| 2599 | + * @throws InvalidInterfaceException |
|
| 2600 | + */ |
|
| 2601 | + protected function _set_publish_post_box_vars( |
|
| 2602 | + $name = '', |
|
| 2603 | + $id = 0, |
|
| 2604 | + $delete = '', |
|
| 2605 | + $save_close_redirect_URL = '', |
|
| 2606 | + $both_btns = true |
|
| 2607 | + ) { |
|
| 2608 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
| 2609 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
| 2610 | + ? $save_close_redirect_URL |
|
| 2611 | + : $this->_admin_base_url; |
|
| 2612 | + // create the Save & Close and Save buttons |
|
| 2613 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
| 2614 | + // if we have extra content set let's add it in if not make sure its empty |
|
| 2615 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
| 2616 | + ? $this->_template_args['publish_box_extra_content'] |
|
| 2617 | + : ''; |
|
| 2618 | + if ($delete && ! empty($id)) { |
|
| 2619 | + // make sure we have a default if just true is sent. |
|
| 2620 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
| 2621 | + $delete_link_args = array($name => $id); |
|
| 2622 | + $delete = $this->get_action_link_or_button( |
|
| 2623 | + $delete, |
|
| 2624 | + $delete, |
|
| 2625 | + $delete_link_args, |
|
| 2626 | + 'submitdelete deletion' |
|
| 2627 | + ); |
|
| 2628 | + } |
|
| 2629 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
| 2630 | + if (! empty($name) && ! empty($id)) { |
|
| 2631 | + $hidden_field_arr[ $name ] = array( |
|
| 2632 | + 'type' => 'hidden', |
|
| 2633 | + 'value' => $id, |
|
| 2634 | + ); |
|
| 2635 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
| 2636 | + } else { |
|
| 2637 | + $hf = ''; |
|
| 2638 | + } |
|
| 2639 | + // add hidden field |
|
| 2640 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
| 2641 | + ? $hf[ $name ]['field'] |
|
| 2642 | + : $hf; |
|
| 2643 | + } |
|
| 2644 | + |
|
| 2645 | + |
|
| 2646 | + /** |
|
| 2647 | + * displays an error message to ppl who have javascript disabled |
|
| 2648 | + * |
|
| 2649 | + * @return void |
|
| 2650 | + */ |
|
| 2651 | + private function _display_no_javascript_warning() |
|
| 2652 | + { |
|
| 2653 | + ?> |
|
| 2654 | 2654 | <noscript> |
| 2655 | 2655 | <div id="no-js-message" class="error"> |
| 2656 | 2656 | <p style="font-size:1.3em;"> |
| 2657 | 2657 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
| 2658 | 2658 | <?php esc_html_e( |
| 2659 | - '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.', |
|
| 2660 | - 'event_espresso' |
|
| 2661 | - ); ?> |
|
| 2659 | + '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.', |
|
| 2660 | + 'event_espresso' |
|
| 2661 | + ); ?> |
|
| 2662 | 2662 | </p> |
| 2663 | 2663 | </div> |
| 2664 | 2664 | </noscript> |
| 2665 | 2665 | <?php |
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - |
|
| 2669 | - /** |
|
| 2670 | - * displays espresso success and/or error notices |
|
| 2671 | - * |
|
| 2672 | - * @return void |
|
| 2673 | - */ |
|
| 2674 | - private function _display_espresso_notices() |
|
| 2675 | - { |
|
| 2676 | - $notices = $this->_get_transient(true); |
|
| 2677 | - echo stripslashes($notices); |
|
| 2678 | - } |
|
| 2679 | - |
|
| 2680 | - |
|
| 2681 | - /** |
|
| 2682 | - * spinny things pacify the masses |
|
| 2683 | - * |
|
| 2684 | - * @return void |
|
| 2685 | - */ |
|
| 2686 | - protected function _add_admin_page_ajax_loading_img() |
|
| 2687 | - { |
|
| 2688 | - ?> |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + |
|
| 2669 | + /** |
|
| 2670 | + * displays espresso success and/or error notices |
|
| 2671 | + * |
|
| 2672 | + * @return void |
|
| 2673 | + */ |
|
| 2674 | + private function _display_espresso_notices() |
|
| 2675 | + { |
|
| 2676 | + $notices = $this->_get_transient(true); |
|
| 2677 | + echo stripslashes($notices); |
|
| 2678 | + } |
|
| 2679 | + |
|
| 2680 | + |
|
| 2681 | + /** |
|
| 2682 | + * spinny things pacify the masses |
|
| 2683 | + * |
|
| 2684 | + * @return void |
|
| 2685 | + */ |
|
| 2686 | + protected function _add_admin_page_ajax_loading_img() |
|
| 2687 | + { |
|
| 2688 | + ?> |
|
| 2689 | 2689 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
| 2690 | 2690 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
| 2691 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2691 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
| 2692 | 2692 | </div> |
| 2693 | 2693 | <?php |
| 2694 | - } |
|
| 2694 | + } |
|
| 2695 | 2695 | |
| 2696 | 2696 | |
| 2697 | - /** |
|
| 2698 | - * add admin page overlay for modal boxes |
|
| 2699 | - * |
|
| 2700 | - * @return void |
|
| 2701 | - */ |
|
| 2702 | - protected function _add_admin_page_overlay() |
|
| 2703 | - { |
|
| 2704 | - ?> |
|
| 2697 | + /** |
|
| 2698 | + * add admin page overlay for modal boxes |
|
| 2699 | + * |
|
| 2700 | + * @return void |
|
| 2701 | + */ |
|
| 2702 | + protected function _add_admin_page_overlay() |
|
| 2703 | + { |
|
| 2704 | + ?> |
|
| 2705 | 2705 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
| 2706 | 2706 | <?php |
| 2707 | - } |
|
| 2708 | - |
|
| 2709 | - |
|
| 2710 | - /** |
|
| 2711 | - * facade for add_meta_box |
|
| 2712 | - * |
|
| 2713 | - * @param string $action where the metabox get's displayed |
|
| 2714 | - * @param string $title Title of Metabox (output in metabox header) |
|
| 2715 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2716 | - * instead of the one created in here. |
|
| 2717 | - * @param array $callback_args an array of args supplied for the metabox |
|
| 2718 | - * @param string $column what metabox column |
|
| 2719 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2720 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2721 | - * created but just set our own callback for wp's add_meta_box. |
|
| 2722 | - * @throws DomainException |
|
| 2723 | - */ |
|
| 2724 | - public function _add_admin_page_meta_box( |
|
| 2725 | - $action, |
|
| 2726 | - $title, |
|
| 2727 | - $callback, |
|
| 2728 | - $callback_args, |
|
| 2729 | - $column = 'normal', |
|
| 2730 | - $priority = 'high', |
|
| 2731 | - $create_func = true |
|
| 2732 | - ) { |
|
| 2733 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2734 | - // 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. |
|
| 2735 | - if (empty($callback_args) && $create_func) { |
|
| 2736 | - $callback_args = array( |
|
| 2737 | - 'template_path' => $this->_template_path, |
|
| 2738 | - 'template_args' => $this->_template_args, |
|
| 2739 | - ); |
|
| 2740 | - } |
|
| 2741 | - // 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) |
|
| 2742 | - $call_back_func = $create_func |
|
| 2743 | - ? static function ($post, $metabox) { |
|
| 2744 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2745 | - echo EEH_Template::display_template( |
|
| 2746 | - $metabox['args']['template_path'], |
|
| 2747 | - $metabox['args']['template_args'], |
|
| 2748 | - true |
|
| 2749 | - ); |
|
| 2750 | - } |
|
| 2751 | - : $callback; |
|
| 2752 | - add_meta_box( |
|
| 2753 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2754 | - $title, |
|
| 2755 | - $call_back_func, |
|
| 2756 | - $this->_wp_page_slug, |
|
| 2757 | - $column, |
|
| 2758 | - $priority, |
|
| 2759 | - $callback_args |
|
| 2760 | - ); |
|
| 2761 | - } |
|
| 2762 | - |
|
| 2763 | - |
|
| 2764 | - /** |
|
| 2765 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2766 | - * |
|
| 2767 | - * @throws DomainException |
|
| 2768 | - * @throws EE_Error |
|
| 2769 | - * @throws InvalidArgumentException |
|
| 2770 | - * @throws InvalidDataTypeException |
|
| 2771 | - * @throws InvalidInterfaceException |
|
| 2772 | - */ |
|
| 2773 | - public function display_admin_page_with_metabox_columns() |
|
| 2774 | - { |
|
| 2775 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2776 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2777 | - $this->_column_template_path, |
|
| 2778 | - $this->_template_args, |
|
| 2779 | - true |
|
| 2780 | - ); |
|
| 2781 | - // the final wrapper |
|
| 2782 | - $this->admin_page_wrapper(); |
|
| 2783 | - } |
|
| 2784 | - |
|
| 2785 | - |
|
| 2786 | - /** |
|
| 2787 | - * generates HTML wrapper for an admin details page |
|
| 2788 | - * |
|
| 2789 | - * @return void |
|
| 2790 | - * @throws DomainException |
|
| 2791 | - * @throws EE_Error |
|
| 2792 | - * @throws InvalidArgumentException |
|
| 2793 | - * @throws InvalidDataTypeException |
|
| 2794 | - * @throws InvalidInterfaceException |
|
| 2795 | - */ |
|
| 2796 | - public function display_admin_page_with_sidebar() |
|
| 2797 | - { |
|
| 2798 | - $this->_display_admin_page(true); |
|
| 2799 | - } |
|
| 2800 | - |
|
| 2801 | - |
|
| 2802 | - /** |
|
| 2803 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2804 | - * |
|
| 2805 | - * @return void |
|
| 2806 | - * @throws DomainException |
|
| 2807 | - * @throws EE_Error |
|
| 2808 | - * @throws InvalidArgumentException |
|
| 2809 | - * @throws InvalidDataTypeException |
|
| 2810 | - * @throws InvalidInterfaceException |
|
| 2811 | - */ |
|
| 2812 | - public function display_admin_page_with_no_sidebar() |
|
| 2813 | - { |
|
| 2814 | - $this->_display_admin_page(); |
|
| 2815 | - } |
|
| 2816 | - |
|
| 2817 | - |
|
| 2818 | - /** |
|
| 2819 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2820 | - * |
|
| 2821 | - * @return void |
|
| 2822 | - * @throws DomainException |
|
| 2823 | - * @throws EE_Error |
|
| 2824 | - * @throws InvalidArgumentException |
|
| 2825 | - * @throws InvalidDataTypeException |
|
| 2826 | - * @throws InvalidInterfaceException |
|
| 2827 | - */ |
|
| 2828 | - public function display_about_admin_page() |
|
| 2829 | - { |
|
| 2830 | - $this->_display_admin_page(false, true); |
|
| 2831 | - } |
|
| 2832 | - |
|
| 2833 | - |
|
| 2834 | - /** |
|
| 2835 | - * display_admin_page |
|
| 2836 | - * contains the code for actually displaying an admin page |
|
| 2837 | - * |
|
| 2838 | - * @param boolean $sidebar true with sidebar, false without |
|
| 2839 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2840 | - * @return void |
|
| 2841 | - * @throws DomainException |
|
| 2842 | - * @throws EE_Error |
|
| 2843 | - * @throws InvalidArgumentException |
|
| 2844 | - * @throws InvalidDataTypeException |
|
| 2845 | - * @throws InvalidInterfaceException |
|
| 2846 | - */ |
|
| 2847 | - private function _display_admin_page($sidebar = false, $about = false) |
|
| 2848 | - { |
|
| 2849 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2850 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2851 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2852 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2853 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2854 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2855 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2856 | - ? 'poststuff' |
|
| 2857 | - : 'espresso-default-admin'; |
|
| 2858 | - $template_path = $sidebar |
|
| 2859 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2860 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2861 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2862 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2863 | - } |
|
| 2864 | - $template_path = ! empty($this->_column_template_path) |
|
| 2865 | - ? $this->_column_template_path : $template_path; |
|
| 2866 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2867 | - ? $this->_template_args['admin_page_content'] |
|
| 2868 | - : ''; |
|
| 2869 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2870 | - ? $this->_template_args['before_admin_page_content'] |
|
| 2871 | - : ''; |
|
| 2872 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2873 | - ? $this->_template_args['after_admin_page_content'] |
|
| 2874 | - : ''; |
|
| 2875 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2876 | - $template_path, |
|
| 2877 | - $this->_template_args, |
|
| 2878 | - true |
|
| 2879 | - ); |
|
| 2880 | - // the final template wrapper |
|
| 2881 | - $this->admin_page_wrapper($about); |
|
| 2882 | - } |
|
| 2883 | - |
|
| 2884 | - |
|
| 2885 | - /** |
|
| 2886 | - * This is used to display caf preview pages. |
|
| 2887 | - * |
|
| 2888 | - * @since 4.3.2 |
|
| 2889 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2890 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2891 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2892 | - * @return void |
|
| 2893 | - * @throws DomainException |
|
| 2894 | - * @throws EE_Error |
|
| 2895 | - * @throws InvalidArgumentException |
|
| 2896 | - * @throws InvalidDataTypeException |
|
| 2897 | - * @throws InvalidInterfaceException |
|
| 2898 | - */ |
|
| 2899 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2900 | - { |
|
| 2901 | - // let's generate a default preview action button if there isn't one already present. |
|
| 2902 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2903 | - 'Upgrade to Event Espresso 4 Right Now', |
|
| 2904 | - 'event_espresso' |
|
| 2905 | - ); |
|
| 2906 | - $buy_now_url = add_query_arg( |
|
| 2907 | - array( |
|
| 2908 | - 'ee_ver' => 'ee4', |
|
| 2909 | - 'utm_source' => 'ee4_plugin_admin', |
|
| 2910 | - 'utm_medium' => 'link', |
|
| 2911 | - 'utm_campaign' => $utm_campaign_source, |
|
| 2912 | - 'utm_content' => 'buy_now_button', |
|
| 2913 | - ), |
|
| 2914 | - 'http://eventespresso.com/pricing/' |
|
| 2915 | - ); |
|
| 2916 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2917 | - ? $this->get_action_link_or_button( |
|
| 2918 | - '', |
|
| 2919 | - 'buy_now', |
|
| 2920 | - array(), |
|
| 2921 | - 'button-primary button-large', |
|
| 2922 | - $buy_now_url, |
|
| 2923 | - true |
|
| 2924 | - ) |
|
| 2925 | - : $this->_template_args['preview_action_button']; |
|
| 2926 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2927 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2928 | - $this->_template_args, |
|
| 2929 | - true |
|
| 2930 | - ); |
|
| 2931 | - $this->_display_admin_page($display_sidebar); |
|
| 2932 | - } |
|
| 2933 | - |
|
| 2934 | - |
|
| 2935 | - /** |
|
| 2936 | - * display_admin_list_table_page_with_sidebar |
|
| 2937 | - * generates HTML wrapper for an admin_page with list_table |
|
| 2938 | - * |
|
| 2939 | - * @return void |
|
| 2940 | - * @throws DomainException |
|
| 2941 | - * @throws EE_Error |
|
| 2942 | - * @throws InvalidArgumentException |
|
| 2943 | - * @throws InvalidDataTypeException |
|
| 2944 | - * @throws InvalidInterfaceException |
|
| 2945 | - */ |
|
| 2946 | - public function display_admin_list_table_page_with_sidebar() |
|
| 2947 | - { |
|
| 2948 | - $this->_display_admin_list_table_page(true); |
|
| 2949 | - } |
|
| 2950 | - |
|
| 2951 | - |
|
| 2952 | - /** |
|
| 2953 | - * display_admin_list_table_page_with_no_sidebar |
|
| 2954 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2955 | - * |
|
| 2956 | - * @return void |
|
| 2957 | - * @throws DomainException |
|
| 2958 | - * @throws EE_Error |
|
| 2959 | - * @throws InvalidArgumentException |
|
| 2960 | - * @throws InvalidDataTypeException |
|
| 2961 | - * @throws InvalidInterfaceException |
|
| 2962 | - */ |
|
| 2963 | - public function display_admin_list_table_page_with_no_sidebar() |
|
| 2964 | - { |
|
| 2965 | - $this->_display_admin_list_table_page(); |
|
| 2966 | - } |
|
| 2967 | - |
|
| 2968 | - |
|
| 2969 | - /** |
|
| 2970 | - * generates html wrapper for an admin_list_table page |
|
| 2971 | - * |
|
| 2972 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2973 | - * @return void |
|
| 2974 | - * @throws DomainException |
|
| 2975 | - * @throws EE_Error |
|
| 2976 | - * @throws InvalidArgumentException |
|
| 2977 | - * @throws InvalidDataTypeException |
|
| 2978 | - * @throws InvalidInterfaceException |
|
| 2979 | - */ |
|
| 2980 | - private function _display_admin_list_table_page($sidebar = false) |
|
| 2981 | - { |
|
| 2982 | - // setup search attributes |
|
| 2983 | - $this->_set_search_attributes(); |
|
| 2984 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2985 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2986 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2987 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2988 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2989 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2990 | - $this->_template_args['current_route'] = $this->_req_action; |
|
| 2991 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2992 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2993 | - if (! empty($ajax_sorting_callback)) { |
|
| 2994 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2995 | - $ajax_sorting_callback . '_nonce', |
|
| 2996 | - $ajax_sorting_callback . '_nonce', |
|
| 2997 | - false, |
|
| 2998 | - false |
|
| 2999 | - ); |
|
| 3000 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3001 | - . $this->page_slug |
|
| 3002 | - . '" />'; |
|
| 3003 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3004 | - . $ajax_sorting_callback |
|
| 3005 | - . '" />'; |
|
| 3006 | - } else { |
|
| 3007 | - $sortable_list_table_form_fields = ''; |
|
| 3008 | - } |
|
| 3009 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3010 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 3011 | - ? $this->_template_args['list_table_hidden_fields'] |
|
| 3012 | - : ''; |
|
| 3013 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3014 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3015 | - . $nonce_ref |
|
| 3016 | - . '" value="' |
|
| 3017 | - . wp_create_nonce($nonce_ref) |
|
| 3018 | - . '">'; |
|
| 3019 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3020 | - // display message about search results? |
|
| 3021 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3022 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3023 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3024 | - trim($this->_req_data['s'], '%') |
|
| 3025 | - ) . '</p>' |
|
| 3026 | - : ''; |
|
| 3027 | - // filter before_list_table template arg |
|
| 3028 | - $this->_template_args['before_list_table'] = apply_filters( |
|
| 3029 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3030 | - $this->_template_args['before_list_table'], |
|
| 3031 | - $this->page_slug, |
|
| 3032 | - $this->_req_data, |
|
| 3033 | - $this->_req_action |
|
| 3034 | - ); |
|
| 3035 | - // convert to array and filter again |
|
| 3036 | - // arrays are easier to inject new items in a specific location, |
|
| 3037 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3038 | - $this->_template_args['before_list_table'] = implode( |
|
| 3039 | - " \n", |
|
| 3040 | - (array) apply_filters( |
|
| 3041 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3042 | - (array) $this->_template_args['before_list_table'], |
|
| 3043 | - $this->page_slug, |
|
| 3044 | - $this->_req_data, |
|
| 3045 | - $this->_req_action |
|
| 3046 | - ) |
|
| 3047 | - ); |
|
| 3048 | - // filter after_list_table template arg |
|
| 3049 | - $this->_template_args['after_list_table'] = apply_filters( |
|
| 3050 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3051 | - $this->_template_args['after_list_table'], |
|
| 3052 | - $this->page_slug, |
|
| 3053 | - $this->_req_data, |
|
| 3054 | - $this->_req_action |
|
| 3055 | - ); |
|
| 3056 | - // convert to array and filter again |
|
| 3057 | - // arrays are easier to inject new items in a specific location, |
|
| 3058 | - // but would not be backwards compatible, so we have to add a new filter |
|
| 3059 | - $this->_template_args['after_list_table'] = implode( |
|
| 3060 | - " \n", |
|
| 3061 | - (array) apply_filters( |
|
| 3062 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3063 | - (array) $this->_template_args['after_list_table'], |
|
| 3064 | - $this->page_slug, |
|
| 3065 | - $this->_req_data, |
|
| 3066 | - $this->_req_action |
|
| 3067 | - ) |
|
| 3068 | - ); |
|
| 3069 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3070 | - $template_path, |
|
| 3071 | - $this->_template_args, |
|
| 3072 | - true |
|
| 3073 | - ); |
|
| 3074 | - // the final template wrapper |
|
| 3075 | - if ($sidebar) { |
|
| 3076 | - $this->display_admin_page_with_sidebar(); |
|
| 3077 | - } else { |
|
| 3078 | - $this->display_admin_page_with_no_sidebar(); |
|
| 3079 | - } |
|
| 3080 | - } |
|
| 3081 | - |
|
| 3082 | - |
|
| 3083 | - /** |
|
| 3084 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3085 | - * html string for the legend. |
|
| 3086 | - * $items are expected in an array in the following format: |
|
| 3087 | - * $legend_items = array( |
|
| 3088 | - * 'item_id' => array( |
|
| 3089 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3090 | - * 'desc' => esc_html__('localized description of item'); |
|
| 3091 | - * ) |
|
| 3092 | - * ); |
|
| 3093 | - * |
|
| 3094 | - * @param array $items see above for format of array |
|
| 3095 | - * @return string html string of legend |
|
| 3096 | - * @throws DomainException |
|
| 3097 | - */ |
|
| 3098 | - protected function _display_legend($items) |
|
| 3099 | - { |
|
| 3100 | - $this->_template_args['items'] = apply_filters( |
|
| 3101 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3102 | - (array) $items, |
|
| 3103 | - $this |
|
| 3104 | - ); |
|
| 3105 | - /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
|
| 3106 | - $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
|
| 3107 | - if (! $status_change_notice->isDismissed()) { |
|
| 3108 | - $this->_template_args['status_change_notice'] = EEH_Template::display_template( |
|
| 3109 | - EE_ADMIN_TEMPLATE . 'status_change_notice.template.php', |
|
| 3110 | - [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ], |
|
| 3111 | - true |
|
| 3112 | - ); |
|
| 3113 | - } |
|
| 3114 | - return EEH_Template::display_template( |
|
| 3115 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3116 | - $this->_template_args, |
|
| 3117 | - true |
|
| 3118 | - ); |
|
| 3119 | - } |
|
| 3120 | - |
|
| 3121 | - |
|
| 3122 | - /** |
|
| 3123 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3124 | - * The returned json object is created from an array in the following format: |
|
| 3125 | - * array( |
|
| 3126 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3127 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3128 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3129 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3130 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3131 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3132 | - * that might be included in here) |
|
| 3133 | - * ) |
|
| 3134 | - * The json object is populated by whatever is set in the $_template_args property. |
|
| 3135 | - * |
|
| 3136 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3137 | - * instead of displayed. |
|
| 3138 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3139 | - * @return void |
|
| 3140 | - * @throws EE_Error |
|
| 3141 | - * @throws InvalidArgumentException |
|
| 3142 | - * @throws InvalidDataTypeException |
|
| 3143 | - * @throws InvalidInterfaceException |
|
| 3144 | - */ |
|
| 3145 | - protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3146 | - { |
|
| 3147 | - // make sure any EE_Error notices have been handled. |
|
| 3148 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3149 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3150 | - unset($this->_template_args['data']); |
|
| 3151 | - $json = array( |
|
| 3152 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3153 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3154 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3155 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3156 | - 'notices' => EE_Error::get_notices(), |
|
| 3157 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3158 | - ? $this->_template_args['admin_page_content'] : '', |
|
| 3159 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3160 | - 'isEEajax' => true |
|
| 3161 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3162 | - ); |
|
| 3163 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3164 | - if (null === error_get_last() || ! headers_sent()) { |
|
| 3165 | - header('Content-Type: application/json; charset=UTF-8'); |
|
| 3166 | - } |
|
| 3167 | - echo wp_json_encode($json); |
|
| 3168 | - exit(); |
|
| 3169 | - } |
|
| 3170 | - |
|
| 3171 | - |
|
| 3172 | - /** |
|
| 3173 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3174 | - * |
|
| 3175 | - * @return void |
|
| 3176 | - * @throws EE_Error |
|
| 3177 | - * @throws InvalidArgumentException |
|
| 3178 | - * @throws InvalidDataTypeException |
|
| 3179 | - * @throws InvalidInterfaceException |
|
| 3180 | - */ |
|
| 3181 | - public function return_json() |
|
| 3182 | - { |
|
| 3183 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3184 | - $this->_return_json(); |
|
| 3185 | - } else { |
|
| 3186 | - throw new EE_Error( |
|
| 3187 | - sprintf( |
|
| 3188 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3189 | - __FUNCTION__ |
|
| 3190 | - ) |
|
| 3191 | - ); |
|
| 3192 | - } |
|
| 3193 | - } |
|
| 3194 | - |
|
| 3195 | - |
|
| 3196 | - /** |
|
| 3197 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3198 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3199 | - * |
|
| 3200 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3201 | - */ |
|
| 3202 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3203 | - { |
|
| 3204 | - $this->_hook_obj = $hook_obj; |
|
| 3205 | - } |
|
| 3206 | - |
|
| 3207 | - |
|
| 3208 | - /** |
|
| 3209 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3210 | - * |
|
| 3211 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3212 | - * @return void |
|
| 3213 | - * @throws DomainException |
|
| 3214 | - * @throws EE_Error |
|
| 3215 | - * @throws InvalidArgumentException |
|
| 3216 | - * @throws InvalidDataTypeException |
|
| 3217 | - * @throws InvalidInterfaceException |
|
| 3218 | - */ |
|
| 3219 | - public function admin_page_wrapper($about = false) |
|
| 3220 | - { |
|
| 3221 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3222 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3223 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3224 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3225 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3226 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3227 | - isset($this->_template_args['before_admin_page_content']) |
|
| 3228 | - ? $this->_template_args['before_admin_page_content'] |
|
| 3229 | - : '' |
|
| 3230 | - ); |
|
| 3231 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3232 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3233 | - isset($this->_template_args['after_admin_page_content']) |
|
| 3234 | - ? $this->_template_args['after_admin_page_content'] |
|
| 3235 | - : '' |
|
| 3236 | - ); |
|
| 3237 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3238 | - // load settings page wrapper template |
|
| 3239 | - $template_path = ! defined('DOING_AJAX') |
|
| 3240 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3241 | - : EE_ADMIN_TEMPLATE |
|
| 3242 | - . 'admin_wrapper_ajax.template.php'; |
|
| 3243 | - // about page? |
|
| 3244 | - $template_path = $about |
|
| 3245 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3246 | - : $template_path; |
|
| 3247 | - if (defined('DOING_AJAX')) { |
|
| 3248 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3249 | - $template_path, |
|
| 3250 | - $this->_template_args, |
|
| 3251 | - true |
|
| 3252 | - ); |
|
| 3253 | - $this->_return_json(); |
|
| 3254 | - } else { |
|
| 3255 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3256 | - } |
|
| 3257 | - } |
|
| 3258 | - |
|
| 3259 | - |
|
| 3260 | - /** |
|
| 3261 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3262 | - * |
|
| 3263 | - * @return string html |
|
| 3264 | - * @throws EE_Error |
|
| 3265 | - */ |
|
| 3266 | - protected function _get_main_nav_tabs() |
|
| 3267 | - { |
|
| 3268 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3269 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3270 | - // (rather than setting in the page_routes array) |
|
| 3271 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3272 | - } |
|
| 3273 | - |
|
| 3274 | - |
|
| 3275 | - /** |
|
| 3276 | - * sort nav tabs |
|
| 3277 | - * |
|
| 3278 | - * @param $a |
|
| 3279 | - * @param $b |
|
| 3280 | - * @return int |
|
| 3281 | - */ |
|
| 3282 | - private function _sort_nav_tabs($a, $b) |
|
| 3283 | - { |
|
| 3284 | - if ($a['order'] === $b['order']) { |
|
| 3285 | - return 0; |
|
| 3286 | - } |
|
| 3287 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3288 | - } |
|
| 3289 | - |
|
| 3290 | - |
|
| 3291 | - /** |
|
| 3292 | - * generates HTML for the forms used on admin pages |
|
| 3293 | - * |
|
| 3294 | - * @param array $input_vars - array of input field details |
|
| 3295 | - * @param string $generator indicates which generator to use: options are 'string' or 'array' |
|
| 3296 | - * @param bool $id |
|
| 3297 | - * @return array|string |
|
| 3298 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3299 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3300 | - */ |
|
| 3301 | - protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3302 | - { |
|
| 3303 | - return $generator === 'string' |
|
| 3304 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3305 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3306 | - } |
|
| 3307 | - |
|
| 3308 | - |
|
| 3309 | - /** |
|
| 3310 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3311 | - * |
|
| 3312 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3313 | - * Close" button. |
|
| 3314 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3315 | - * 'Save', [1] => 'save & close') |
|
| 3316 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3317 | - * via the "name" value in the button). We can also use this to just dump |
|
| 3318 | - * default actions by submitting some other value. |
|
| 3319 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3320 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3321 | - * close (normal form handling). |
|
| 3322 | - */ |
|
| 3323 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3324 | - { |
|
| 3325 | - // make sure $text and $actions are in an array |
|
| 3326 | - $text = (array) $text; |
|
| 3327 | - $actions = (array) $actions; |
|
| 3328 | - $referrer_url = empty($referrer) |
|
| 3329 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3330 | - . $_SERVER['REQUEST_URI'] |
|
| 3331 | - . '" />' |
|
| 3332 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3333 | - . $referrer |
|
| 3334 | - . '" />'; |
|
| 3335 | - $button_text = ! empty($text) |
|
| 3336 | - ? $text |
|
| 3337 | - : array( |
|
| 3338 | - esc_html__('Save', 'event_espresso'), |
|
| 3339 | - esc_html__('Save and Close', 'event_espresso'), |
|
| 3340 | - ); |
|
| 3341 | - $default_names = array('save', 'save_and_close'); |
|
| 3342 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3343 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3344 | - foreach ($button_text as $key => $button) { |
|
| 3345 | - $ref = $default_names[ $key ]; |
|
| 3346 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3347 | - . $ref |
|
| 3348 | - . '" value="' |
|
| 3349 | - . $button |
|
| 3350 | - . '" name="' |
|
| 3351 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3352 | - . '" id="' |
|
| 3353 | - . $this->_current_view . '_' . $ref |
|
| 3354 | - . '" />'; |
|
| 3355 | - if (! $both) { |
|
| 3356 | - break; |
|
| 3357 | - } |
|
| 3358 | - } |
|
| 3359 | - } |
|
| 3360 | - |
|
| 3361 | - |
|
| 3362 | - /** |
|
| 3363 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3364 | - * |
|
| 3365 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3366 | - * @since 4.6.0 |
|
| 3367 | - * @param string $route |
|
| 3368 | - * @param array $additional_hidden_fields |
|
| 3369 | - */ |
|
| 3370 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3371 | - { |
|
| 3372 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3373 | - } |
|
| 3374 | - |
|
| 3375 | - |
|
| 3376 | - /** |
|
| 3377 | - * set form open and close tags on add/edit pages. |
|
| 3378 | - * |
|
| 3379 | - * @param string $route the route you want the form to direct to |
|
| 3380 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3381 | - * @return void |
|
| 3382 | - */ |
|
| 3383 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3384 | - { |
|
| 3385 | - if (empty($route)) { |
|
| 3386 | - $user_msg = esc_html__( |
|
| 3387 | - 'An error occurred. No action was set for this page\'s form.', |
|
| 3388 | - 'event_espresso' |
|
| 3389 | - ); |
|
| 3390 | - $dev_msg = $user_msg . "\n" |
|
| 3391 | - . sprintf( |
|
| 3392 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3393 | - __FUNCTION__, |
|
| 3394 | - EE_Admin_Page::class |
|
| 3395 | - ); |
|
| 3396 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3397 | - } |
|
| 3398 | - // open form |
|
| 3399 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3400 | - . $this->_admin_base_url |
|
| 3401 | - . '" id="' |
|
| 3402 | - . $route |
|
| 3403 | - . '_event_form" >'; |
|
| 3404 | - // add nonce |
|
| 3405 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3406 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3407 | - // add REQUIRED form action |
|
| 3408 | - $hidden_fields = array( |
|
| 3409 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3410 | - ); |
|
| 3411 | - // merge arrays |
|
| 3412 | - $hidden_fields = is_array($additional_hidden_fields) |
|
| 3413 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3414 | - : $hidden_fields; |
|
| 3415 | - // generate form fields |
|
| 3416 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3417 | - // add fields to form |
|
| 3418 | - foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3419 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3420 | - } |
|
| 3421 | - // close form |
|
| 3422 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3423 | - } |
|
| 3424 | - |
|
| 3425 | - |
|
| 3426 | - /** |
|
| 3427 | - * Public Wrapper for _redirect_after_action() method since its |
|
| 3428 | - * discovered it would be useful for external code to have access. |
|
| 3429 | - * |
|
| 3430 | - * @param bool $success |
|
| 3431 | - * @param string $what |
|
| 3432 | - * @param string $action_desc |
|
| 3433 | - * @param array $query_args |
|
| 3434 | - * @param bool $override_overwrite |
|
| 3435 | - * @throws EE_Error |
|
| 3436 | - * @throws InvalidArgumentException |
|
| 3437 | - * @throws InvalidDataTypeException |
|
| 3438 | - * @throws InvalidInterfaceException |
|
| 3439 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3440 | - * @since 4.5.0 |
|
| 3441 | - */ |
|
| 3442 | - public function redirect_after_action( |
|
| 3443 | - $success = false, |
|
| 3444 | - $what = 'item', |
|
| 3445 | - $action_desc = 'processed', |
|
| 3446 | - $query_args = array(), |
|
| 3447 | - $override_overwrite = false |
|
| 3448 | - ) { |
|
| 3449 | - $this->_redirect_after_action( |
|
| 3450 | - $success, |
|
| 3451 | - $what, |
|
| 3452 | - $action_desc, |
|
| 3453 | - $query_args, |
|
| 3454 | - $override_overwrite |
|
| 3455 | - ); |
|
| 3456 | - } |
|
| 3457 | - |
|
| 3458 | - |
|
| 3459 | - /** |
|
| 3460 | - * Helper method for merging existing request data with the returned redirect url. |
|
| 3461 | - * |
|
| 3462 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3463 | - * filters are still applied. |
|
| 3464 | - * |
|
| 3465 | - * @param array $new_route_data |
|
| 3466 | - * @return array |
|
| 3467 | - */ |
|
| 3468 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3469 | - { |
|
| 3470 | - foreach ($this->_req_data as $ref => $value) { |
|
| 3471 | - // unset nonces |
|
| 3472 | - if (strpos($ref, 'nonce') !== false) { |
|
| 3473 | - unset($this->_req_data[ $ref ]); |
|
| 3474 | - continue; |
|
| 3475 | - } |
|
| 3476 | - // urlencode values. |
|
| 3477 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3478 | - $this->_req_data[ $ref ] = $value; |
|
| 3479 | - } |
|
| 3480 | - return array_merge($this->_req_data, $new_route_data); |
|
| 3481 | - } |
|
| 3482 | - |
|
| 3483 | - |
|
| 3484 | - /** |
|
| 3485 | - * _redirect_after_action |
|
| 3486 | - * |
|
| 3487 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3488 | - * @param string $what - what the action was performed on |
|
| 3489 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3490 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3491 | - * action is completed |
|
| 3492 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3493 | - * override this so that they show. |
|
| 3494 | - * @return void |
|
| 3495 | - * @throws EE_Error |
|
| 3496 | - * @throws InvalidArgumentException |
|
| 3497 | - * @throws InvalidDataTypeException |
|
| 3498 | - * @throws InvalidInterfaceException |
|
| 3499 | - */ |
|
| 3500 | - protected function _redirect_after_action( |
|
| 3501 | - $success = 0, |
|
| 3502 | - $what = 'item', |
|
| 3503 | - $action_desc = 'processed', |
|
| 3504 | - $query_args = array(), |
|
| 3505 | - $override_overwrite = false |
|
| 3506 | - ) { |
|
| 3507 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3508 | - // class name for actions/filters. |
|
| 3509 | - $classname = get_class($this); |
|
| 3510 | - // set redirect url. |
|
| 3511 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3512 | - // otherwise we go with whatever is set as the _admin_base_url |
|
| 3513 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3514 | - $notices = EE_Error::get_notices(false); |
|
| 3515 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3516 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3517 | - EE_Error::overwrite_success(); |
|
| 3518 | - } |
|
| 3519 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3520 | - // how many records affected ? more than one record ? or just one ? |
|
| 3521 | - if ($success > 1) { |
|
| 3522 | - // set plural msg |
|
| 3523 | - EE_Error::add_success( |
|
| 3524 | - sprintf( |
|
| 3525 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3526 | - $what, |
|
| 3527 | - $action_desc |
|
| 3528 | - ), |
|
| 3529 | - __FILE__, |
|
| 3530 | - __FUNCTION__, |
|
| 3531 | - __LINE__ |
|
| 3532 | - ); |
|
| 3533 | - } elseif ($success === 1) { |
|
| 3534 | - // set singular msg |
|
| 3535 | - EE_Error::add_success( |
|
| 3536 | - sprintf( |
|
| 3537 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3538 | - $what, |
|
| 3539 | - $action_desc |
|
| 3540 | - ), |
|
| 3541 | - __FILE__, |
|
| 3542 | - __FUNCTION__, |
|
| 3543 | - __LINE__ |
|
| 3544 | - ); |
|
| 3545 | - } |
|
| 3546 | - } |
|
| 3547 | - // check that $query_args isn't something crazy |
|
| 3548 | - if (! is_array($query_args)) { |
|
| 3549 | - $query_args = array(); |
|
| 3550 | - } |
|
| 3551 | - /** |
|
| 3552 | - * Allow injecting actions before the query_args are modified for possible different |
|
| 3553 | - * redirections on save and close actions |
|
| 3554 | - * |
|
| 3555 | - * @since 4.2.0 |
|
| 3556 | - * @param array $query_args The original query_args array coming into the |
|
| 3557 | - * method. |
|
| 3558 | - */ |
|
| 3559 | - do_action( |
|
| 3560 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3561 | - $query_args |
|
| 3562 | - ); |
|
| 3563 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3564 | - if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3565 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3566 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3567 | - // regenerate query args array from referrer URL |
|
| 3568 | - parse_str($parsed_url['query'], $query_args); |
|
| 3569 | - // correct page and action will be in the query args now |
|
| 3570 | - $redirect_url = admin_url('admin.php'); |
|
| 3571 | - } |
|
| 3572 | - // merge any default query_args set in _default_route_query_args property |
|
| 3573 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3574 | - $args_to_merge = array(); |
|
| 3575 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3576 | - // is there a wp_referer array in our _default_route_query_args property? |
|
| 3577 | - if ($query_param === 'wp_referer') { |
|
| 3578 | - $query_value = (array) $query_value; |
|
| 3579 | - foreach ($query_value as $reference => $value) { |
|
| 3580 | - if (strpos($reference, 'nonce') !== false) { |
|
| 3581 | - continue; |
|
| 3582 | - } |
|
| 3583 | - // finally we will override any arguments in the referer with |
|
| 3584 | - // what might be set on the _default_route_query_args array. |
|
| 3585 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3586 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3587 | - } else { |
|
| 3588 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3589 | - } |
|
| 3590 | - } |
|
| 3591 | - continue; |
|
| 3592 | - } |
|
| 3593 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3594 | - } |
|
| 3595 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3596 | - // redirect. |
|
| 3597 | - $query_args = array_merge($args_to_merge, $query_args); |
|
| 3598 | - } |
|
| 3599 | - $this->_process_notices($query_args); |
|
| 3600 | - // generate redirect url |
|
| 3601 | - // if redirecting to anything other than the main page, add a nonce |
|
| 3602 | - if (isset($query_args['action'])) { |
|
| 3603 | - // manually generate wp_nonce and merge that with the query vars |
|
| 3604 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3605 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3606 | - } |
|
| 3607 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3608 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3609 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3610 | - $redirect_url = apply_filters( |
|
| 3611 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3612 | - EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3613 | - $query_args |
|
| 3614 | - ); |
|
| 3615 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3616 | - if (defined('DOING_AJAX')) { |
|
| 3617 | - $default_data = array( |
|
| 3618 | - 'close' => true, |
|
| 3619 | - 'redirect_url' => $redirect_url, |
|
| 3620 | - 'where' => 'main', |
|
| 3621 | - 'what' => 'append', |
|
| 3622 | - ); |
|
| 3623 | - $this->_template_args['success'] = $success; |
|
| 3624 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3625 | - $default_data, |
|
| 3626 | - $this->_template_args['data'] |
|
| 3627 | - ) : $default_data; |
|
| 3628 | - $this->_return_json(); |
|
| 3629 | - } |
|
| 3630 | - wp_safe_redirect($redirect_url); |
|
| 3631 | - exit(); |
|
| 3632 | - } |
|
| 3633 | - |
|
| 3634 | - |
|
| 3635 | - /** |
|
| 3636 | - * process any notices before redirecting (or returning ajax request) |
|
| 3637 | - * This method sets the $this->_template_args['notices'] attribute; |
|
| 3638 | - * |
|
| 3639 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3640 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3641 | - * page_routes haven't been defined yet. |
|
| 3642 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3643 | - * still save a transient for the notice. |
|
| 3644 | - * @return void |
|
| 3645 | - * @throws EE_Error |
|
| 3646 | - * @throws InvalidArgumentException |
|
| 3647 | - * @throws InvalidDataTypeException |
|
| 3648 | - * @throws InvalidInterfaceException |
|
| 3649 | - */ |
|
| 3650 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3651 | - { |
|
| 3652 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3653 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3654 | - $notices = EE_Error::get_notices(false); |
|
| 3655 | - if (empty($this->_template_args['success'])) { |
|
| 3656 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3657 | - } |
|
| 3658 | - if (empty($this->_template_args['errors'])) { |
|
| 3659 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3660 | - } |
|
| 3661 | - if (empty($this->_template_args['attention'])) { |
|
| 3662 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3663 | - } |
|
| 3664 | - } |
|
| 3665 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3666 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3667 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3668 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3669 | - $this->_add_transient( |
|
| 3670 | - $route, |
|
| 3671 | - $this->_template_args['notices'], |
|
| 3672 | - true, |
|
| 3673 | - $skip_route_verify |
|
| 3674 | - ); |
|
| 3675 | - } |
|
| 3676 | - } |
|
| 3677 | - |
|
| 3678 | - |
|
| 3679 | - /** |
|
| 3680 | - * get_action_link_or_button |
|
| 3681 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3682 | - * |
|
| 3683 | - * @param string $action use this to indicate which action the url is generated with. |
|
| 3684 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3685 | - * property. |
|
| 3686 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3687 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3688 | - * @param string $base_url If this is not provided |
|
| 3689 | - * the _admin_base_url will be used as the default for the button base_url. |
|
| 3690 | - * Otherwise this value will be used. |
|
| 3691 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3692 | - * @return string |
|
| 3693 | - * @throws InvalidArgumentException |
|
| 3694 | - * @throws InvalidInterfaceException |
|
| 3695 | - * @throws InvalidDataTypeException |
|
| 3696 | - * @throws EE_Error |
|
| 3697 | - */ |
|
| 3698 | - public function get_action_link_or_button( |
|
| 3699 | - $action, |
|
| 3700 | - $type = 'add', |
|
| 3701 | - $extra_request = array(), |
|
| 3702 | - $class = 'button-primary', |
|
| 3703 | - $base_url = '', |
|
| 3704 | - $exclude_nonce = false |
|
| 3705 | - ) { |
|
| 3706 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3707 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3708 | - throw new EE_Error( |
|
| 3709 | - sprintf( |
|
| 3710 | - esc_html__( |
|
| 3711 | - 'There is no page route for given action for the button. This action was given: %s', |
|
| 3712 | - 'event_espresso' |
|
| 3713 | - ), |
|
| 3714 | - $action |
|
| 3715 | - ) |
|
| 3716 | - ); |
|
| 3717 | - } |
|
| 3718 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3719 | - throw new EE_Error( |
|
| 3720 | - sprintf( |
|
| 3721 | - __( |
|
| 3722 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3723 | - 'event_espresso' |
|
| 3724 | - ), |
|
| 3725 | - $type |
|
| 3726 | - ) |
|
| 3727 | - ); |
|
| 3728 | - } |
|
| 3729 | - // finally check user access for this button. |
|
| 3730 | - $has_access = $this->check_user_access($action, true); |
|
| 3731 | - if (! $has_access) { |
|
| 3732 | - return ''; |
|
| 3733 | - } |
|
| 3734 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3735 | - $query_args = array( |
|
| 3736 | - 'action' => $action, |
|
| 3737 | - ); |
|
| 3738 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3739 | - if (! empty($extra_request)) { |
|
| 3740 | - $query_args = array_merge($extra_request, $query_args); |
|
| 3741 | - } |
|
| 3742 | - $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3743 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3744 | - } |
|
| 3745 | - |
|
| 3746 | - |
|
| 3747 | - /** |
|
| 3748 | - * _per_page_screen_option |
|
| 3749 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3750 | - * |
|
| 3751 | - * @return void |
|
| 3752 | - * @throws InvalidArgumentException |
|
| 3753 | - * @throws InvalidInterfaceException |
|
| 3754 | - * @throws InvalidDataTypeException |
|
| 3755 | - */ |
|
| 3756 | - protected function _per_page_screen_option() |
|
| 3757 | - { |
|
| 3758 | - $option = 'per_page'; |
|
| 3759 | - $args = array( |
|
| 3760 | - 'label' => apply_filters( |
|
| 3761 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3762 | - $this->_admin_page_title, |
|
| 3763 | - $this |
|
| 3764 | - ), |
|
| 3765 | - 'default' => (int) apply_filters( |
|
| 3766 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3767 | - 20 |
|
| 3768 | - ), |
|
| 3769 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3770 | - ); |
|
| 3771 | - // ONLY add the screen option if the user has access to it. |
|
| 3772 | - if ($this->check_user_access($this->_current_view, true)) { |
|
| 3773 | - add_screen_option($option, $args); |
|
| 3774 | - } |
|
| 3775 | - } |
|
| 3776 | - |
|
| 3777 | - |
|
| 3778 | - /** |
|
| 3779 | - * set_per_page_screen_option |
|
| 3780 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3781 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3782 | - * admin_menu. |
|
| 3783 | - * |
|
| 3784 | - * @return void |
|
| 3785 | - */ |
|
| 3786 | - private function _set_per_page_screen_options() |
|
| 3787 | - { |
|
| 3788 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3789 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3790 | - if (! $user = wp_get_current_user()) { |
|
| 3791 | - return; |
|
| 3792 | - } |
|
| 3793 | - $option = $_POST['wp_screen_options']['option']; |
|
| 3794 | - $value = $_POST['wp_screen_options']['value']; |
|
| 3795 | - if ($option !== sanitize_key($option)) { |
|
| 3796 | - return; |
|
| 3797 | - } |
|
| 3798 | - $map_option = $option; |
|
| 3799 | - $option = str_replace('-', '_', $option); |
|
| 3800 | - switch ($map_option) { |
|
| 3801 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3802 | - $value = (int) $value; |
|
| 3803 | - $max_value = apply_filters( |
|
| 3804 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3805 | - 999, |
|
| 3806 | - $this->_current_page, |
|
| 3807 | - $this->_current_view |
|
| 3808 | - ); |
|
| 3809 | - if ($value < 1) { |
|
| 3810 | - return; |
|
| 3811 | - } |
|
| 3812 | - $value = min($value, $max_value); |
|
| 3813 | - break; |
|
| 3814 | - default: |
|
| 3815 | - $value = apply_filters( |
|
| 3816 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3817 | - false, |
|
| 3818 | - $option, |
|
| 3819 | - $value |
|
| 3820 | - ); |
|
| 3821 | - if (false === $value) { |
|
| 3822 | - return; |
|
| 3823 | - } |
|
| 3824 | - break; |
|
| 3825 | - } |
|
| 3826 | - update_user_meta($user->ID, $option, $value); |
|
| 3827 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3828 | - exit; |
|
| 3829 | - } |
|
| 3830 | - } |
|
| 3831 | - |
|
| 3832 | - |
|
| 3833 | - /** |
|
| 3834 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3835 | - * |
|
| 3836 | - * @param array $data array that will be assigned to template args. |
|
| 3837 | - */ |
|
| 3838 | - public function set_template_args($data) |
|
| 3839 | - { |
|
| 3840 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3841 | - } |
|
| 3842 | - |
|
| 3843 | - |
|
| 3844 | - /** |
|
| 3845 | - * This makes available the WP transient system for temporarily moving data between routes |
|
| 3846 | - * |
|
| 3847 | - * @param string $route the route that should receive the transient |
|
| 3848 | - * @param array $data the data that gets sent |
|
| 3849 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3850 | - * normal route transient. |
|
| 3851 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3852 | - * when we are adding a transient before page_routes have been defined. |
|
| 3853 | - * @return void |
|
| 3854 | - * @throws EE_Error |
|
| 3855 | - */ |
|
| 3856 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3857 | - { |
|
| 3858 | - $user_id = get_current_user_id(); |
|
| 3859 | - if (! $skip_route_verify) { |
|
| 3860 | - $this->_verify_route($route); |
|
| 3861 | - } |
|
| 3862 | - // now let's set the string for what kind of transient we're setting |
|
| 3863 | - $transient = $notices |
|
| 3864 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3865 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3866 | - $data = $notices ? array('notices' => $data) : $data; |
|
| 3867 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3868 | - $existing = is_multisite() && is_network_admin() |
|
| 3869 | - ? get_site_transient($transient) |
|
| 3870 | - : get_transient($transient); |
|
| 3871 | - if ($existing) { |
|
| 3872 | - $data = array_merge((array) $data, (array) $existing); |
|
| 3873 | - } |
|
| 3874 | - if (is_multisite() && is_network_admin()) { |
|
| 3875 | - set_site_transient($transient, $data, 8); |
|
| 3876 | - } else { |
|
| 3877 | - set_transient($transient, $data, 8); |
|
| 3878 | - } |
|
| 3879 | - } |
|
| 3880 | - |
|
| 3881 | - |
|
| 3882 | - /** |
|
| 3883 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3884 | - * |
|
| 3885 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3886 | - * @param string $route |
|
| 3887 | - * @return mixed data |
|
| 3888 | - */ |
|
| 3889 | - protected function _get_transient($notices = false, $route = '') |
|
| 3890 | - { |
|
| 3891 | - $user_id = get_current_user_id(); |
|
| 3892 | - $route = ! $route ? $this->_req_action : $route; |
|
| 3893 | - $transient = $notices |
|
| 3894 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3895 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3896 | - $data = is_multisite() && is_network_admin() |
|
| 3897 | - ? get_site_transient($transient) |
|
| 3898 | - : get_transient($transient); |
|
| 3899 | - // delete transient after retrieval (just in case it hasn't expired); |
|
| 3900 | - if (is_multisite() && is_network_admin()) { |
|
| 3901 | - delete_site_transient($transient); |
|
| 3902 | - } else { |
|
| 3903 | - delete_transient($transient); |
|
| 3904 | - } |
|
| 3905 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3906 | - } |
|
| 3907 | - |
|
| 3908 | - |
|
| 3909 | - /** |
|
| 3910 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3911 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3912 | - * default route callback on the EE_Admin page you want it run.) |
|
| 3913 | - * |
|
| 3914 | - * @return void |
|
| 3915 | - */ |
|
| 3916 | - protected function _transient_garbage_collection() |
|
| 3917 | - { |
|
| 3918 | - global $wpdb; |
|
| 3919 | - // retrieve all existing transients |
|
| 3920 | - $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3921 | - if ($results = $wpdb->get_results($query)) { |
|
| 3922 | - foreach ($results as $result) { |
|
| 3923 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3924 | - get_transient($transient); |
|
| 3925 | - if (is_multisite() && is_network_admin()) { |
|
| 3926 | - get_site_transient($transient); |
|
| 3927 | - } |
|
| 3928 | - } |
|
| 3929 | - } |
|
| 3930 | - } |
|
| 3931 | - |
|
| 3932 | - |
|
| 3933 | - /** |
|
| 3934 | - * get_view |
|
| 3935 | - * |
|
| 3936 | - * @return string content of _view property |
|
| 3937 | - */ |
|
| 3938 | - public function get_view() |
|
| 3939 | - { |
|
| 3940 | - return $this->_view; |
|
| 3941 | - } |
|
| 3942 | - |
|
| 3943 | - |
|
| 3944 | - /** |
|
| 3945 | - * getter for the protected $_views property |
|
| 3946 | - * |
|
| 3947 | - * @return array |
|
| 3948 | - */ |
|
| 3949 | - public function get_views() |
|
| 3950 | - { |
|
| 3951 | - return $this->_views; |
|
| 3952 | - } |
|
| 3953 | - |
|
| 3954 | - |
|
| 3955 | - /** |
|
| 3956 | - * get_current_page |
|
| 3957 | - * |
|
| 3958 | - * @return string _current_page property value |
|
| 3959 | - */ |
|
| 3960 | - public function get_current_page() |
|
| 3961 | - { |
|
| 3962 | - return $this->_current_page; |
|
| 3963 | - } |
|
| 3964 | - |
|
| 3965 | - |
|
| 3966 | - /** |
|
| 3967 | - * get_current_view |
|
| 3968 | - * |
|
| 3969 | - * @return string _current_view property value |
|
| 3970 | - */ |
|
| 3971 | - public function get_current_view() |
|
| 3972 | - { |
|
| 3973 | - return $this->_current_view; |
|
| 3974 | - } |
|
| 3975 | - |
|
| 3976 | - |
|
| 3977 | - /** |
|
| 3978 | - * get_current_screen |
|
| 3979 | - * |
|
| 3980 | - * @return object The current WP_Screen object |
|
| 3981 | - */ |
|
| 3982 | - public function get_current_screen() |
|
| 3983 | - { |
|
| 3984 | - return $this->_current_screen; |
|
| 3985 | - } |
|
| 3986 | - |
|
| 3987 | - |
|
| 3988 | - /** |
|
| 3989 | - * get_current_page_view_url |
|
| 3990 | - * |
|
| 3991 | - * @return string This returns the url for the current_page_view. |
|
| 3992 | - */ |
|
| 3993 | - public function get_current_page_view_url() |
|
| 3994 | - { |
|
| 3995 | - return $this->_current_page_view_url; |
|
| 3996 | - } |
|
| 3997 | - |
|
| 3998 | - |
|
| 3999 | - /** |
|
| 4000 | - * just returns the _req_data property |
|
| 4001 | - * |
|
| 4002 | - * @return array |
|
| 4003 | - */ |
|
| 4004 | - public function get_request_data() |
|
| 4005 | - { |
|
| 4006 | - return $this->_req_data; |
|
| 4007 | - } |
|
| 4008 | - |
|
| 4009 | - |
|
| 4010 | - /** |
|
| 4011 | - * returns the _req_data protected property |
|
| 4012 | - * |
|
| 4013 | - * @return string |
|
| 4014 | - */ |
|
| 4015 | - public function get_req_action() |
|
| 4016 | - { |
|
| 4017 | - return $this->_req_action; |
|
| 4018 | - } |
|
| 4019 | - |
|
| 4020 | - |
|
| 4021 | - /** |
|
| 4022 | - * @return bool value of $_is_caf property |
|
| 4023 | - */ |
|
| 4024 | - public function is_caf() |
|
| 4025 | - { |
|
| 4026 | - return $this->_is_caf; |
|
| 4027 | - } |
|
| 4028 | - |
|
| 4029 | - |
|
| 4030 | - /** |
|
| 4031 | - * @return mixed |
|
| 4032 | - */ |
|
| 4033 | - public function default_espresso_metaboxes() |
|
| 4034 | - { |
|
| 4035 | - return $this->_default_espresso_metaboxes; |
|
| 4036 | - } |
|
| 4037 | - |
|
| 4038 | - |
|
| 4039 | - /** |
|
| 4040 | - * @return mixed |
|
| 4041 | - */ |
|
| 4042 | - public function admin_base_url() |
|
| 4043 | - { |
|
| 4044 | - return $this->_admin_base_url; |
|
| 4045 | - } |
|
| 4046 | - |
|
| 4047 | - |
|
| 4048 | - /** |
|
| 4049 | - * @return mixed |
|
| 4050 | - */ |
|
| 4051 | - public function wp_page_slug() |
|
| 4052 | - { |
|
| 4053 | - return $this->_wp_page_slug; |
|
| 4054 | - } |
|
| 4055 | - |
|
| 4056 | - |
|
| 4057 | - /** |
|
| 4058 | - * updates espresso configuration settings |
|
| 4059 | - * |
|
| 4060 | - * @param string $tab |
|
| 4061 | - * @param EE_Config_Base|EE_Config $config |
|
| 4062 | - * @param string $file file where error occurred |
|
| 4063 | - * @param string $func function where error occurred |
|
| 4064 | - * @param string $line line no where error occurred |
|
| 4065 | - * @return boolean |
|
| 4066 | - */ |
|
| 4067 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4068 | - { |
|
| 4069 | - // remove any options that are NOT going to be saved with the config settings. |
|
| 4070 | - if (isset($config->core->ee_ueip_optin)) { |
|
| 4071 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4072 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4073 | - update_option('ee_ueip_has_notified', true); |
|
| 4074 | - } |
|
| 4075 | - // and save it (note we're also doing the network save here) |
|
| 4076 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4077 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4078 | - if ($config_saved && $net_saved) { |
|
| 4079 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4080 | - return true; |
|
| 4081 | - } |
|
| 4082 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4083 | - return false; |
|
| 4084 | - } |
|
| 4085 | - |
|
| 4086 | - |
|
| 4087 | - /** |
|
| 4088 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4089 | - * |
|
| 4090 | - * @return array |
|
| 4091 | - */ |
|
| 4092 | - public function get_yes_no_values() |
|
| 4093 | - { |
|
| 4094 | - return $this->_yes_no_values; |
|
| 4095 | - } |
|
| 4096 | - |
|
| 4097 | - |
|
| 4098 | - /** |
|
| 4099 | - * @return string |
|
| 4100 | - * @throws ReflectionException |
|
| 4101 | - * @since $VID:$ |
|
| 4102 | - */ |
|
| 4103 | - protected function _get_dir() |
|
| 4104 | - { |
|
| 4105 | - $reflector = new ReflectionClass(get_class($this)); |
|
| 4106 | - return dirname($reflector->getFileName()); |
|
| 4107 | - } |
|
| 4108 | - |
|
| 4109 | - |
|
| 4110 | - /** |
|
| 4111 | - * A helper for getting a "next link". |
|
| 4112 | - * |
|
| 4113 | - * @param string $url The url to link to |
|
| 4114 | - * @param string $class The class to use. |
|
| 4115 | - * @return string |
|
| 4116 | - */ |
|
| 4117 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4118 | - { |
|
| 4119 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4120 | - } |
|
| 4121 | - |
|
| 4122 | - |
|
| 4123 | - /** |
|
| 4124 | - * A helper for getting a "previous link". |
|
| 4125 | - * |
|
| 4126 | - * @param string $url The url to link to |
|
| 4127 | - * @param string $class The class to use. |
|
| 4128 | - * @return string |
|
| 4129 | - */ |
|
| 4130 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4131 | - { |
|
| 4132 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4133 | - } |
|
| 4134 | - |
|
| 4135 | - |
|
| 4136 | - |
|
| 4137 | - |
|
| 4138 | - |
|
| 4139 | - |
|
| 4140 | - |
|
| 4141 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4142 | - |
|
| 4143 | - |
|
| 4144 | - /** |
|
| 4145 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4146 | - * 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 |
|
| 4147 | - * _req_data array. |
|
| 4148 | - * |
|
| 4149 | - * @return bool success/fail |
|
| 4150 | - * @throws EE_Error |
|
| 4151 | - * @throws InvalidArgumentException |
|
| 4152 | - * @throws ReflectionException |
|
| 4153 | - * @throws InvalidDataTypeException |
|
| 4154 | - * @throws InvalidInterfaceException |
|
| 4155 | - */ |
|
| 4156 | - protected function _process_resend_registration() |
|
| 4157 | - { |
|
| 4158 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4159 | - do_action( |
|
| 4160 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4161 | - $this->_template_args['success'], |
|
| 4162 | - $this->_req_data |
|
| 4163 | - ); |
|
| 4164 | - return $this->_template_args['success']; |
|
| 4165 | - } |
|
| 4166 | - |
|
| 4167 | - |
|
| 4168 | - /** |
|
| 4169 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4170 | - * |
|
| 4171 | - * @param EE_Payment $payment |
|
| 4172 | - * @return bool success/fail |
|
| 4173 | - */ |
|
| 4174 | - protected function _process_payment_notification(EE_Payment $payment) |
|
| 4175 | - { |
|
| 4176 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4177 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4178 | - $this->_template_args['success'] = apply_filters( |
|
| 4179 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4180 | - false, |
|
| 4181 | - $payment |
|
| 4182 | - ); |
|
| 4183 | - return $this->_template_args['success']; |
|
| 4184 | - } |
|
| 2707 | + } |
|
| 2708 | + |
|
| 2709 | + |
|
| 2710 | + /** |
|
| 2711 | + * facade for add_meta_box |
|
| 2712 | + * |
|
| 2713 | + * @param string $action where the metabox get's displayed |
|
| 2714 | + * @param string $title Title of Metabox (output in metabox header) |
|
| 2715 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
| 2716 | + * instead of the one created in here. |
|
| 2717 | + * @param array $callback_args an array of args supplied for the metabox |
|
| 2718 | + * @param string $column what metabox column |
|
| 2719 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
| 2720 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
| 2721 | + * created but just set our own callback for wp's add_meta_box. |
|
| 2722 | + * @throws DomainException |
|
| 2723 | + */ |
|
| 2724 | + public function _add_admin_page_meta_box( |
|
| 2725 | + $action, |
|
| 2726 | + $title, |
|
| 2727 | + $callback, |
|
| 2728 | + $callback_args, |
|
| 2729 | + $column = 'normal', |
|
| 2730 | + $priority = 'high', |
|
| 2731 | + $create_func = true |
|
| 2732 | + ) { |
|
| 2733 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
| 2734 | + // 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. |
|
| 2735 | + if (empty($callback_args) && $create_func) { |
|
| 2736 | + $callback_args = array( |
|
| 2737 | + 'template_path' => $this->_template_path, |
|
| 2738 | + 'template_args' => $this->_template_args, |
|
| 2739 | + ); |
|
| 2740 | + } |
|
| 2741 | + // 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) |
|
| 2742 | + $call_back_func = $create_func |
|
| 2743 | + ? static function ($post, $metabox) { |
|
| 2744 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2745 | + echo EEH_Template::display_template( |
|
| 2746 | + $metabox['args']['template_path'], |
|
| 2747 | + $metabox['args']['template_args'], |
|
| 2748 | + true |
|
| 2749 | + ); |
|
| 2750 | + } |
|
| 2751 | + : $callback; |
|
| 2752 | + add_meta_box( |
|
| 2753 | + str_replace('_', '-', $action) . '-mbox', |
|
| 2754 | + $title, |
|
| 2755 | + $call_back_func, |
|
| 2756 | + $this->_wp_page_slug, |
|
| 2757 | + $column, |
|
| 2758 | + $priority, |
|
| 2759 | + $callback_args |
|
| 2760 | + ); |
|
| 2761 | + } |
|
| 2762 | + |
|
| 2763 | + |
|
| 2764 | + /** |
|
| 2765 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
| 2766 | + * |
|
| 2767 | + * @throws DomainException |
|
| 2768 | + * @throws EE_Error |
|
| 2769 | + * @throws InvalidArgumentException |
|
| 2770 | + * @throws InvalidDataTypeException |
|
| 2771 | + * @throws InvalidInterfaceException |
|
| 2772 | + */ |
|
| 2773 | + public function display_admin_page_with_metabox_columns() |
|
| 2774 | + { |
|
| 2775 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
| 2776 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2777 | + $this->_column_template_path, |
|
| 2778 | + $this->_template_args, |
|
| 2779 | + true |
|
| 2780 | + ); |
|
| 2781 | + // the final wrapper |
|
| 2782 | + $this->admin_page_wrapper(); |
|
| 2783 | + } |
|
| 2784 | + |
|
| 2785 | + |
|
| 2786 | + /** |
|
| 2787 | + * generates HTML wrapper for an admin details page |
|
| 2788 | + * |
|
| 2789 | + * @return void |
|
| 2790 | + * @throws DomainException |
|
| 2791 | + * @throws EE_Error |
|
| 2792 | + * @throws InvalidArgumentException |
|
| 2793 | + * @throws InvalidDataTypeException |
|
| 2794 | + * @throws InvalidInterfaceException |
|
| 2795 | + */ |
|
| 2796 | + public function display_admin_page_with_sidebar() |
|
| 2797 | + { |
|
| 2798 | + $this->_display_admin_page(true); |
|
| 2799 | + } |
|
| 2800 | + |
|
| 2801 | + |
|
| 2802 | + /** |
|
| 2803 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
| 2804 | + * |
|
| 2805 | + * @return void |
|
| 2806 | + * @throws DomainException |
|
| 2807 | + * @throws EE_Error |
|
| 2808 | + * @throws InvalidArgumentException |
|
| 2809 | + * @throws InvalidDataTypeException |
|
| 2810 | + * @throws InvalidInterfaceException |
|
| 2811 | + */ |
|
| 2812 | + public function display_admin_page_with_no_sidebar() |
|
| 2813 | + { |
|
| 2814 | + $this->_display_admin_page(); |
|
| 2815 | + } |
|
| 2816 | + |
|
| 2817 | + |
|
| 2818 | + /** |
|
| 2819 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
| 2820 | + * |
|
| 2821 | + * @return void |
|
| 2822 | + * @throws DomainException |
|
| 2823 | + * @throws EE_Error |
|
| 2824 | + * @throws InvalidArgumentException |
|
| 2825 | + * @throws InvalidDataTypeException |
|
| 2826 | + * @throws InvalidInterfaceException |
|
| 2827 | + */ |
|
| 2828 | + public function display_about_admin_page() |
|
| 2829 | + { |
|
| 2830 | + $this->_display_admin_page(false, true); |
|
| 2831 | + } |
|
| 2832 | + |
|
| 2833 | + |
|
| 2834 | + /** |
|
| 2835 | + * display_admin_page |
|
| 2836 | + * contains the code for actually displaying an admin page |
|
| 2837 | + * |
|
| 2838 | + * @param boolean $sidebar true with sidebar, false without |
|
| 2839 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
| 2840 | + * @return void |
|
| 2841 | + * @throws DomainException |
|
| 2842 | + * @throws EE_Error |
|
| 2843 | + * @throws InvalidArgumentException |
|
| 2844 | + * @throws InvalidDataTypeException |
|
| 2845 | + * @throws InvalidInterfaceException |
|
| 2846 | + */ |
|
| 2847 | + private function _display_admin_page($sidebar = false, $about = false) |
|
| 2848 | + { |
|
| 2849 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2850 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
| 2851 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
| 2852 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
| 2853 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
| 2854 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2855 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
| 2856 | + ? 'poststuff' |
|
| 2857 | + : 'espresso-default-admin'; |
|
| 2858 | + $template_path = $sidebar |
|
| 2859 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
| 2860 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2861 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2862 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2863 | + } |
|
| 2864 | + $template_path = ! empty($this->_column_template_path) |
|
| 2865 | + ? $this->_column_template_path : $template_path; |
|
| 2866 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
| 2867 | + ? $this->_template_args['admin_page_content'] |
|
| 2868 | + : ''; |
|
| 2869 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
| 2870 | + ? $this->_template_args['before_admin_page_content'] |
|
| 2871 | + : ''; |
|
| 2872 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
| 2873 | + ? $this->_template_args['after_admin_page_content'] |
|
| 2874 | + : ''; |
|
| 2875 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2876 | + $template_path, |
|
| 2877 | + $this->_template_args, |
|
| 2878 | + true |
|
| 2879 | + ); |
|
| 2880 | + // the final template wrapper |
|
| 2881 | + $this->admin_page_wrapper($about); |
|
| 2882 | + } |
|
| 2883 | + |
|
| 2884 | + |
|
| 2885 | + /** |
|
| 2886 | + * This is used to display caf preview pages. |
|
| 2887 | + * |
|
| 2888 | + * @since 4.3.2 |
|
| 2889 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
| 2890 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
| 2891 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
| 2892 | + * @return void |
|
| 2893 | + * @throws DomainException |
|
| 2894 | + * @throws EE_Error |
|
| 2895 | + * @throws InvalidArgumentException |
|
| 2896 | + * @throws InvalidDataTypeException |
|
| 2897 | + * @throws InvalidInterfaceException |
|
| 2898 | + */ |
|
| 2899 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
| 2900 | + { |
|
| 2901 | + // let's generate a default preview action button if there isn't one already present. |
|
| 2902 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
| 2903 | + 'Upgrade to Event Espresso 4 Right Now', |
|
| 2904 | + 'event_espresso' |
|
| 2905 | + ); |
|
| 2906 | + $buy_now_url = add_query_arg( |
|
| 2907 | + array( |
|
| 2908 | + 'ee_ver' => 'ee4', |
|
| 2909 | + 'utm_source' => 'ee4_plugin_admin', |
|
| 2910 | + 'utm_medium' => 'link', |
|
| 2911 | + 'utm_campaign' => $utm_campaign_source, |
|
| 2912 | + 'utm_content' => 'buy_now_button', |
|
| 2913 | + ), |
|
| 2914 | + 'http://eventespresso.com/pricing/' |
|
| 2915 | + ); |
|
| 2916 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
| 2917 | + ? $this->get_action_link_or_button( |
|
| 2918 | + '', |
|
| 2919 | + 'buy_now', |
|
| 2920 | + array(), |
|
| 2921 | + 'button-primary button-large', |
|
| 2922 | + $buy_now_url, |
|
| 2923 | + true |
|
| 2924 | + ) |
|
| 2925 | + : $this->_template_args['preview_action_button']; |
|
| 2926 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2927 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2928 | + $this->_template_args, |
|
| 2929 | + true |
|
| 2930 | + ); |
|
| 2931 | + $this->_display_admin_page($display_sidebar); |
|
| 2932 | + } |
|
| 2933 | + |
|
| 2934 | + |
|
| 2935 | + /** |
|
| 2936 | + * display_admin_list_table_page_with_sidebar |
|
| 2937 | + * generates HTML wrapper for an admin_page with list_table |
|
| 2938 | + * |
|
| 2939 | + * @return void |
|
| 2940 | + * @throws DomainException |
|
| 2941 | + * @throws EE_Error |
|
| 2942 | + * @throws InvalidArgumentException |
|
| 2943 | + * @throws InvalidDataTypeException |
|
| 2944 | + * @throws InvalidInterfaceException |
|
| 2945 | + */ |
|
| 2946 | + public function display_admin_list_table_page_with_sidebar() |
|
| 2947 | + { |
|
| 2948 | + $this->_display_admin_list_table_page(true); |
|
| 2949 | + } |
|
| 2950 | + |
|
| 2951 | + |
|
| 2952 | + /** |
|
| 2953 | + * display_admin_list_table_page_with_no_sidebar |
|
| 2954 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
| 2955 | + * |
|
| 2956 | + * @return void |
|
| 2957 | + * @throws DomainException |
|
| 2958 | + * @throws EE_Error |
|
| 2959 | + * @throws InvalidArgumentException |
|
| 2960 | + * @throws InvalidDataTypeException |
|
| 2961 | + * @throws InvalidInterfaceException |
|
| 2962 | + */ |
|
| 2963 | + public function display_admin_list_table_page_with_no_sidebar() |
|
| 2964 | + { |
|
| 2965 | + $this->_display_admin_list_table_page(); |
|
| 2966 | + } |
|
| 2967 | + |
|
| 2968 | + |
|
| 2969 | + /** |
|
| 2970 | + * generates html wrapper for an admin_list_table page |
|
| 2971 | + * |
|
| 2972 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
| 2973 | + * @return void |
|
| 2974 | + * @throws DomainException |
|
| 2975 | + * @throws EE_Error |
|
| 2976 | + * @throws InvalidArgumentException |
|
| 2977 | + * @throws InvalidDataTypeException |
|
| 2978 | + * @throws InvalidInterfaceException |
|
| 2979 | + */ |
|
| 2980 | + private function _display_admin_list_table_page($sidebar = false) |
|
| 2981 | + { |
|
| 2982 | + // setup search attributes |
|
| 2983 | + $this->_set_search_attributes(); |
|
| 2984 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
| 2985 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2986 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
| 2987 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
| 2988 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
| 2989 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
| 2990 | + $this->_template_args['current_route'] = $this->_req_action; |
|
| 2991 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
| 2992 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
| 2993 | + if (! empty($ajax_sorting_callback)) { |
|
| 2994 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
| 2995 | + $ajax_sorting_callback . '_nonce', |
|
| 2996 | + $ajax_sorting_callback . '_nonce', |
|
| 2997 | + false, |
|
| 2998 | + false |
|
| 2999 | + ); |
|
| 3000 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
| 3001 | + . $this->page_slug |
|
| 3002 | + . '" />'; |
|
| 3003 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
| 3004 | + . $ajax_sorting_callback |
|
| 3005 | + . '" />'; |
|
| 3006 | + } else { |
|
| 3007 | + $sortable_list_table_form_fields = ''; |
|
| 3008 | + } |
|
| 3009 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
| 3010 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
| 3011 | + ? $this->_template_args['list_table_hidden_fields'] |
|
| 3012 | + : ''; |
|
| 3013 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3014 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
| 3015 | + . $nonce_ref |
|
| 3016 | + . '" value="' |
|
| 3017 | + . wp_create_nonce($nonce_ref) |
|
| 3018 | + . '">'; |
|
| 3019 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
| 3020 | + // display message about search results? |
|
| 3021 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
| 3022 | + ? '<p class="ee-search-results">' . sprintf( |
|
| 3023 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
| 3024 | + trim($this->_req_data['s'], '%') |
|
| 3025 | + ) . '</p>' |
|
| 3026 | + : ''; |
|
| 3027 | + // filter before_list_table template arg |
|
| 3028 | + $this->_template_args['before_list_table'] = apply_filters( |
|
| 3029 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
| 3030 | + $this->_template_args['before_list_table'], |
|
| 3031 | + $this->page_slug, |
|
| 3032 | + $this->_req_data, |
|
| 3033 | + $this->_req_action |
|
| 3034 | + ); |
|
| 3035 | + // convert to array and filter again |
|
| 3036 | + // arrays are easier to inject new items in a specific location, |
|
| 3037 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3038 | + $this->_template_args['before_list_table'] = implode( |
|
| 3039 | + " \n", |
|
| 3040 | + (array) apply_filters( |
|
| 3041 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
| 3042 | + (array) $this->_template_args['before_list_table'], |
|
| 3043 | + $this->page_slug, |
|
| 3044 | + $this->_req_data, |
|
| 3045 | + $this->_req_action |
|
| 3046 | + ) |
|
| 3047 | + ); |
|
| 3048 | + // filter after_list_table template arg |
|
| 3049 | + $this->_template_args['after_list_table'] = apply_filters( |
|
| 3050 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
| 3051 | + $this->_template_args['after_list_table'], |
|
| 3052 | + $this->page_slug, |
|
| 3053 | + $this->_req_data, |
|
| 3054 | + $this->_req_action |
|
| 3055 | + ); |
|
| 3056 | + // convert to array and filter again |
|
| 3057 | + // arrays are easier to inject new items in a specific location, |
|
| 3058 | + // but would not be backwards compatible, so we have to add a new filter |
|
| 3059 | + $this->_template_args['after_list_table'] = implode( |
|
| 3060 | + " \n", |
|
| 3061 | + (array) apply_filters( |
|
| 3062 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
| 3063 | + (array) $this->_template_args['after_list_table'], |
|
| 3064 | + $this->page_slug, |
|
| 3065 | + $this->_req_data, |
|
| 3066 | + $this->_req_action |
|
| 3067 | + ) |
|
| 3068 | + ); |
|
| 3069 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3070 | + $template_path, |
|
| 3071 | + $this->_template_args, |
|
| 3072 | + true |
|
| 3073 | + ); |
|
| 3074 | + // the final template wrapper |
|
| 3075 | + if ($sidebar) { |
|
| 3076 | + $this->display_admin_page_with_sidebar(); |
|
| 3077 | + } else { |
|
| 3078 | + $this->display_admin_page_with_no_sidebar(); |
|
| 3079 | + } |
|
| 3080 | + } |
|
| 3081 | + |
|
| 3082 | + |
|
| 3083 | + /** |
|
| 3084 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
| 3085 | + * html string for the legend. |
|
| 3086 | + * $items are expected in an array in the following format: |
|
| 3087 | + * $legend_items = array( |
|
| 3088 | + * 'item_id' => array( |
|
| 3089 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
| 3090 | + * 'desc' => esc_html__('localized description of item'); |
|
| 3091 | + * ) |
|
| 3092 | + * ); |
|
| 3093 | + * |
|
| 3094 | + * @param array $items see above for format of array |
|
| 3095 | + * @return string html string of legend |
|
| 3096 | + * @throws DomainException |
|
| 3097 | + */ |
|
| 3098 | + protected function _display_legend($items) |
|
| 3099 | + { |
|
| 3100 | + $this->_template_args['items'] = apply_filters( |
|
| 3101 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
| 3102 | + (array) $items, |
|
| 3103 | + $this |
|
| 3104 | + ); |
|
| 3105 | + /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
|
| 3106 | + $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
|
| 3107 | + if (! $status_change_notice->isDismissed()) { |
|
| 3108 | + $this->_template_args['status_change_notice'] = EEH_Template::display_template( |
|
| 3109 | + EE_ADMIN_TEMPLATE . 'status_change_notice.template.php', |
|
| 3110 | + [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ], |
|
| 3111 | + true |
|
| 3112 | + ); |
|
| 3113 | + } |
|
| 3114 | + return EEH_Template::display_template( |
|
| 3115 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3116 | + $this->_template_args, |
|
| 3117 | + true |
|
| 3118 | + ); |
|
| 3119 | + } |
|
| 3120 | + |
|
| 3121 | + |
|
| 3122 | + /** |
|
| 3123 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
| 3124 | + * The returned json object is created from an array in the following format: |
|
| 3125 | + * array( |
|
| 3126 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
| 3127 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
| 3128 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
| 3129 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
| 3130 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
| 3131 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
| 3132 | + * that might be included in here) |
|
| 3133 | + * ) |
|
| 3134 | + * The json object is populated by whatever is set in the $_template_args property. |
|
| 3135 | + * |
|
| 3136 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
| 3137 | + * instead of displayed. |
|
| 3138 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
| 3139 | + * @return void |
|
| 3140 | + * @throws EE_Error |
|
| 3141 | + * @throws InvalidArgumentException |
|
| 3142 | + * @throws InvalidDataTypeException |
|
| 3143 | + * @throws InvalidInterfaceException |
|
| 3144 | + */ |
|
| 3145 | + protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
| 3146 | + { |
|
| 3147 | + // make sure any EE_Error notices have been handled. |
|
| 3148 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
| 3149 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
| 3150 | + unset($this->_template_args['data']); |
|
| 3151 | + $json = array( |
|
| 3152 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
| 3153 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
| 3154 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
| 3155 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
| 3156 | + 'notices' => EE_Error::get_notices(), |
|
| 3157 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
| 3158 | + ? $this->_template_args['admin_page_content'] : '', |
|
| 3159 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
| 3160 | + 'isEEajax' => true |
|
| 3161 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
| 3162 | + ); |
|
| 3163 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
| 3164 | + if (null === error_get_last() || ! headers_sent()) { |
|
| 3165 | + header('Content-Type: application/json; charset=UTF-8'); |
|
| 3166 | + } |
|
| 3167 | + echo wp_json_encode($json); |
|
| 3168 | + exit(); |
|
| 3169 | + } |
|
| 3170 | + |
|
| 3171 | + |
|
| 3172 | + /** |
|
| 3173 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
| 3174 | + * |
|
| 3175 | + * @return void |
|
| 3176 | + * @throws EE_Error |
|
| 3177 | + * @throws InvalidArgumentException |
|
| 3178 | + * @throws InvalidDataTypeException |
|
| 3179 | + * @throws InvalidInterfaceException |
|
| 3180 | + */ |
|
| 3181 | + public function return_json() |
|
| 3182 | + { |
|
| 3183 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3184 | + $this->_return_json(); |
|
| 3185 | + } else { |
|
| 3186 | + throw new EE_Error( |
|
| 3187 | + sprintf( |
|
| 3188 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
| 3189 | + __FUNCTION__ |
|
| 3190 | + ) |
|
| 3191 | + ); |
|
| 3192 | + } |
|
| 3193 | + } |
|
| 3194 | + |
|
| 3195 | + |
|
| 3196 | + /** |
|
| 3197 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
| 3198 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
| 3199 | + * |
|
| 3200 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
| 3201 | + */ |
|
| 3202 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
| 3203 | + { |
|
| 3204 | + $this->_hook_obj = $hook_obj; |
|
| 3205 | + } |
|
| 3206 | + |
|
| 3207 | + |
|
| 3208 | + /** |
|
| 3209 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
| 3210 | + * |
|
| 3211 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
| 3212 | + * @return void |
|
| 3213 | + * @throws DomainException |
|
| 3214 | + * @throws EE_Error |
|
| 3215 | + * @throws InvalidArgumentException |
|
| 3216 | + * @throws InvalidDataTypeException |
|
| 3217 | + * @throws InvalidInterfaceException |
|
| 3218 | + */ |
|
| 3219 | + public function admin_page_wrapper($about = false) |
|
| 3220 | + { |
|
| 3221 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3222 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
| 3223 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
| 3224 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
| 3225 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
| 3226 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3227 | + isset($this->_template_args['before_admin_page_content']) |
|
| 3228 | + ? $this->_template_args['before_admin_page_content'] |
|
| 3229 | + : '' |
|
| 3230 | + ); |
|
| 3231 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
| 3232 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
| 3233 | + isset($this->_template_args['after_admin_page_content']) |
|
| 3234 | + ? $this->_template_args['after_admin_page_content'] |
|
| 3235 | + : '' |
|
| 3236 | + ); |
|
| 3237 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
| 3238 | + // load settings page wrapper template |
|
| 3239 | + $template_path = ! defined('DOING_AJAX') |
|
| 3240 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
| 3241 | + : EE_ADMIN_TEMPLATE |
|
| 3242 | + . 'admin_wrapper_ajax.template.php'; |
|
| 3243 | + // about page? |
|
| 3244 | + $template_path = $about |
|
| 3245 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
| 3246 | + : $template_path; |
|
| 3247 | + if (defined('DOING_AJAX')) { |
|
| 3248 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 3249 | + $template_path, |
|
| 3250 | + $this->_template_args, |
|
| 3251 | + true |
|
| 3252 | + ); |
|
| 3253 | + $this->_return_json(); |
|
| 3254 | + } else { |
|
| 3255 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
| 3256 | + } |
|
| 3257 | + } |
|
| 3258 | + |
|
| 3259 | + |
|
| 3260 | + /** |
|
| 3261 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
| 3262 | + * |
|
| 3263 | + * @return string html |
|
| 3264 | + * @throws EE_Error |
|
| 3265 | + */ |
|
| 3266 | + protected function _get_main_nav_tabs() |
|
| 3267 | + { |
|
| 3268 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
| 3269 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
| 3270 | + // (rather than setting in the page_routes array) |
|
| 3271 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
| 3272 | + } |
|
| 3273 | + |
|
| 3274 | + |
|
| 3275 | + /** |
|
| 3276 | + * sort nav tabs |
|
| 3277 | + * |
|
| 3278 | + * @param $a |
|
| 3279 | + * @param $b |
|
| 3280 | + * @return int |
|
| 3281 | + */ |
|
| 3282 | + private function _sort_nav_tabs($a, $b) |
|
| 3283 | + { |
|
| 3284 | + if ($a['order'] === $b['order']) { |
|
| 3285 | + return 0; |
|
| 3286 | + } |
|
| 3287 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
| 3288 | + } |
|
| 3289 | + |
|
| 3290 | + |
|
| 3291 | + /** |
|
| 3292 | + * generates HTML for the forms used on admin pages |
|
| 3293 | + * |
|
| 3294 | + * @param array $input_vars - array of input field details |
|
| 3295 | + * @param string $generator indicates which generator to use: options are 'string' or 'array' |
|
| 3296 | + * @param bool $id |
|
| 3297 | + * @return array|string |
|
| 3298 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
| 3299 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
| 3300 | + */ |
|
| 3301 | + protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false) |
|
| 3302 | + { |
|
| 3303 | + return $generator === 'string' |
|
| 3304 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
| 3305 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
| 3306 | + } |
|
| 3307 | + |
|
| 3308 | + |
|
| 3309 | + /** |
|
| 3310 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
| 3311 | + * |
|
| 3312 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
| 3313 | + * Close" button. |
|
| 3314 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
| 3315 | + * 'Save', [1] => 'save & close') |
|
| 3316 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
| 3317 | + * via the "name" value in the button). We can also use this to just dump |
|
| 3318 | + * default actions by submitting some other value. |
|
| 3319 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
| 3320 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
| 3321 | + * close (normal form handling). |
|
| 3322 | + */ |
|
| 3323 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
| 3324 | + { |
|
| 3325 | + // make sure $text and $actions are in an array |
|
| 3326 | + $text = (array) $text; |
|
| 3327 | + $actions = (array) $actions; |
|
| 3328 | + $referrer_url = empty($referrer) |
|
| 3329 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3330 | + . $_SERVER['REQUEST_URI'] |
|
| 3331 | + . '" />' |
|
| 3332 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
| 3333 | + . $referrer |
|
| 3334 | + . '" />'; |
|
| 3335 | + $button_text = ! empty($text) |
|
| 3336 | + ? $text |
|
| 3337 | + : array( |
|
| 3338 | + esc_html__('Save', 'event_espresso'), |
|
| 3339 | + esc_html__('Save and Close', 'event_espresso'), |
|
| 3340 | + ); |
|
| 3341 | + $default_names = array('save', 'save_and_close'); |
|
| 3342 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
| 3343 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
| 3344 | + foreach ($button_text as $key => $button) { |
|
| 3345 | + $ref = $default_names[ $key ]; |
|
| 3346 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
| 3347 | + . $ref |
|
| 3348 | + . '" value="' |
|
| 3349 | + . $button |
|
| 3350 | + . '" name="' |
|
| 3351 | + . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3352 | + . '" id="' |
|
| 3353 | + . $this->_current_view . '_' . $ref |
|
| 3354 | + . '" />'; |
|
| 3355 | + if (! $both) { |
|
| 3356 | + break; |
|
| 3357 | + } |
|
| 3358 | + } |
|
| 3359 | + } |
|
| 3360 | + |
|
| 3361 | + |
|
| 3362 | + /** |
|
| 3363 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
| 3364 | + * |
|
| 3365 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
| 3366 | + * @since 4.6.0 |
|
| 3367 | + * @param string $route |
|
| 3368 | + * @param array $additional_hidden_fields |
|
| 3369 | + */ |
|
| 3370 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3371 | + { |
|
| 3372 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
| 3373 | + } |
|
| 3374 | + |
|
| 3375 | + |
|
| 3376 | + /** |
|
| 3377 | + * set form open and close tags on add/edit pages. |
|
| 3378 | + * |
|
| 3379 | + * @param string $route the route you want the form to direct to |
|
| 3380 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
| 3381 | + * @return void |
|
| 3382 | + */ |
|
| 3383 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
| 3384 | + { |
|
| 3385 | + if (empty($route)) { |
|
| 3386 | + $user_msg = esc_html__( |
|
| 3387 | + 'An error occurred. No action was set for this page\'s form.', |
|
| 3388 | + 'event_espresso' |
|
| 3389 | + ); |
|
| 3390 | + $dev_msg = $user_msg . "\n" |
|
| 3391 | + . sprintf( |
|
| 3392 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
| 3393 | + __FUNCTION__, |
|
| 3394 | + EE_Admin_Page::class |
|
| 3395 | + ); |
|
| 3396 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3397 | + } |
|
| 3398 | + // open form |
|
| 3399 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
| 3400 | + . $this->_admin_base_url |
|
| 3401 | + . '" id="' |
|
| 3402 | + . $route |
|
| 3403 | + . '_event_form" >'; |
|
| 3404 | + // add nonce |
|
| 3405 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3406 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3407 | + // add REQUIRED form action |
|
| 3408 | + $hidden_fields = array( |
|
| 3409 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
| 3410 | + ); |
|
| 3411 | + // merge arrays |
|
| 3412 | + $hidden_fields = is_array($additional_hidden_fields) |
|
| 3413 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
| 3414 | + : $hidden_fields; |
|
| 3415 | + // generate form fields |
|
| 3416 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
| 3417 | + // add fields to form |
|
| 3418 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
| 3419 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3420 | + } |
|
| 3421 | + // close form |
|
| 3422 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
| 3423 | + } |
|
| 3424 | + |
|
| 3425 | + |
|
| 3426 | + /** |
|
| 3427 | + * Public Wrapper for _redirect_after_action() method since its |
|
| 3428 | + * discovered it would be useful for external code to have access. |
|
| 3429 | + * |
|
| 3430 | + * @param bool $success |
|
| 3431 | + * @param string $what |
|
| 3432 | + * @param string $action_desc |
|
| 3433 | + * @param array $query_args |
|
| 3434 | + * @param bool $override_overwrite |
|
| 3435 | + * @throws EE_Error |
|
| 3436 | + * @throws InvalidArgumentException |
|
| 3437 | + * @throws InvalidDataTypeException |
|
| 3438 | + * @throws InvalidInterfaceException |
|
| 3439 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
| 3440 | + * @since 4.5.0 |
|
| 3441 | + */ |
|
| 3442 | + public function redirect_after_action( |
|
| 3443 | + $success = false, |
|
| 3444 | + $what = 'item', |
|
| 3445 | + $action_desc = 'processed', |
|
| 3446 | + $query_args = array(), |
|
| 3447 | + $override_overwrite = false |
|
| 3448 | + ) { |
|
| 3449 | + $this->_redirect_after_action( |
|
| 3450 | + $success, |
|
| 3451 | + $what, |
|
| 3452 | + $action_desc, |
|
| 3453 | + $query_args, |
|
| 3454 | + $override_overwrite |
|
| 3455 | + ); |
|
| 3456 | + } |
|
| 3457 | + |
|
| 3458 | + |
|
| 3459 | + /** |
|
| 3460 | + * Helper method for merging existing request data with the returned redirect url. |
|
| 3461 | + * |
|
| 3462 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
| 3463 | + * filters are still applied. |
|
| 3464 | + * |
|
| 3465 | + * @param array $new_route_data |
|
| 3466 | + * @return array |
|
| 3467 | + */ |
|
| 3468 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
| 3469 | + { |
|
| 3470 | + foreach ($this->_req_data as $ref => $value) { |
|
| 3471 | + // unset nonces |
|
| 3472 | + if (strpos($ref, 'nonce') !== false) { |
|
| 3473 | + unset($this->_req_data[ $ref ]); |
|
| 3474 | + continue; |
|
| 3475 | + } |
|
| 3476 | + // urlencode values. |
|
| 3477 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 3478 | + $this->_req_data[ $ref ] = $value; |
|
| 3479 | + } |
|
| 3480 | + return array_merge($this->_req_data, $new_route_data); |
|
| 3481 | + } |
|
| 3482 | + |
|
| 3483 | + |
|
| 3484 | + /** |
|
| 3485 | + * _redirect_after_action |
|
| 3486 | + * |
|
| 3487 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
| 3488 | + * @param string $what - what the action was performed on |
|
| 3489 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
| 3490 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
| 3491 | + * action is completed |
|
| 3492 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
| 3493 | + * override this so that they show. |
|
| 3494 | + * @return void |
|
| 3495 | + * @throws EE_Error |
|
| 3496 | + * @throws InvalidArgumentException |
|
| 3497 | + * @throws InvalidDataTypeException |
|
| 3498 | + * @throws InvalidInterfaceException |
|
| 3499 | + */ |
|
| 3500 | + protected function _redirect_after_action( |
|
| 3501 | + $success = 0, |
|
| 3502 | + $what = 'item', |
|
| 3503 | + $action_desc = 'processed', |
|
| 3504 | + $query_args = array(), |
|
| 3505 | + $override_overwrite = false |
|
| 3506 | + ) { |
|
| 3507 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3508 | + // class name for actions/filters. |
|
| 3509 | + $classname = get_class($this); |
|
| 3510 | + // set redirect url. |
|
| 3511 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
| 3512 | + // otherwise we go with whatever is set as the _admin_base_url |
|
| 3513 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
| 3514 | + $notices = EE_Error::get_notices(false); |
|
| 3515 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
| 3516 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3517 | + EE_Error::overwrite_success(); |
|
| 3518 | + } |
|
| 3519 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3520 | + // how many records affected ? more than one record ? or just one ? |
|
| 3521 | + if ($success > 1) { |
|
| 3522 | + // set plural msg |
|
| 3523 | + EE_Error::add_success( |
|
| 3524 | + sprintf( |
|
| 3525 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
| 3526 | + $what, |
|
| 3527 | + $action_desc |
|
| 3528 | + ), |
|
| 3529 | + __FILE__, |
|
| 3530 | + __FUNCTION__, |
|
| 3531 | + __LINE__ |
|
| 3532 | + ); |
|
| 3533 | + } elseif ($success === 1) { |
|
| 3534 | + // set singular msg |
|
| 3535 | + EE_Error::add_success( |
|
| 3536 | + sprintf( |
|
| 3537 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
| 3538 | + $what, |
|
| 3539 | + $action_desc |
|
| 3540 | + ), |
|
| 3541 | + __FILE__, |
|
| 3542 | + __FUNCTION__, |
|
| 3543 | + __LINE__ |
|
| 3544 | + ); |
|
| 3545 | + } |
|
| 3546 | + } |
|
| 3547 | + // check that $query_args isn't something crazy |
|
| 3548 | + if (! is_array($query_args)) { |
|
| 3549 | + $query_args = array(); |
|
| 3550 | + } |
|
| 3551 | + /** |
|
| 3552 | + * Allow injecting actions before the query_args are modified for possible different |
|
| 3553 | + * redirections on save and close actions |
|
| 3554 | + * |
|
| 3555 | + * @since 4.2.0 |
|
| 3556 | + * @param array $query_args The original query_args array coming into the |
|
| 3557 | + * method. |
|
| 3558 | + */ |
|
| 3559 | + do_action( |
|
| 3560 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
| 3561 | + $query_args |
|
| 3562 | + ); |
|
| 3563 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
| 3564 | + if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
| 3565 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
| 3566 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
| 3567 | + // regenerate query args array from referrer URL |
|
| 3568 | + parse_str($parsed_url['query'], $query_args); |
|
| 3569 | + // correct page and action will be in the query args now |
|
| 3570 | + $redirect_url = admin_url('admin.php'); |
|
| 3571 | + } |
|
| 3572 | + // merge any default query_args set in _default_route_query_args property |
|
| 3573 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3574 | + $args_to_merge = array(); |
|
| 3575 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
| 3576 | + // is there a wp_referer array in our _default_route_query_args property? |
|
| 3577 | + if ($query_param === 'wp_referer') { |
|
| 3578 | + $query_value = (array) $query_value; |
|
| 3579 | + foreach ($query_value as $reference => $value) { |
|
| 3580 | + if (strpos($reference, 'nonce') !== false) { |
|
| 3581 | + continue; |
|
| 3582 | + } |
|
| 3583 | + // finally we will override any arguments in the referer with |
|
| 3584 | + // what might be set on the _default_route_query_args array. |
|
| 3585 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3586 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3587 | + } else { |
|
| 3588 | + $args_to_merge[ $reference ] = urlencode($value); |
|
| 3589 | + } |
|
| 3590 | + } |
|
| 3591 | + continue; |
|
| 3592 | + } |
|
| 3593 | + $args_to_merge[ $query_param ] = $query_value; |
|
| 3594 | + } |
|
| 3595 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
| 3596 | + // redirect. |
|
| 3597 | + $query_args = array_merge($args_to_merge, $query_args); |
|
| 3598 | + } |
|
| 3599 | + $this->_process_notices($query_args); |
|
| 3600 | + // generate redirect url |
|
| 3601 | + // if redirecting to anything other than the main page, add a nonce |
|
| 3602 | + if (isset($query_args['action'])) { |
|
| 3603 | + // manually generate wp_nonce and merge that with the query vars |
|
| 3604 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
| 3605 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3606 | + } |
|
| 3607 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
| 3608 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
| 3609 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3610 | + $redirect_url = apply_filters( |
|
| 3611 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3612 | + EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
|
| 3613 | + $query_args |
|
| 3614 | + ); |
|
| 3615 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
| 3616 | + if (defined('DOING_AJAX')) { |
|
| 3617 | + $default_data = array( |
|
| 3618 | + 'close' => true, |
|
| 3619 | + 'redirect_url' => $redirect_url, |
|
| 3620 | + 'where' => 'main', |
|
| 3621 | + 'what' => 'append', |
|
| 3622 | + ); |
|
| 3623 | + $this->_template_args['success'] = $success; |
|
| 3624 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
| 3625 | + $default_data, |
|
| 3626 | + $this->_template_args['data'] |
|
| 3627 | + ) : $default_data; |
|
| 3628 | + $this->_return_json(); |
|
| 3629 | + } |
|
| 3630 | + wp_safe_redirect($redirect_url); |
|
| 3631 | + exit(); |
|
| 3632 | + } |
|
| 3633 | + |
|
| 3634 | + |
|
| 3635 | + /** |
|
| 3636 | + * process any notices before redirecting (or returning ajax request) |
|
| 3637 | + * This method sets the $this->_template_args['notices'] attribute; |
|
| 3638 | + * |
|
| 3639 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
| 3640 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
| 3641 | + * page_routes haven't been defined yet. |
|
| 3642 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
| 3643 | + * still save a transient for the notice. |
|
| 3644 | + * @return void |
|
| 3645 | + * @throws EE_Error |
|
| 3646 | + * @throws InvalidArgumentException |
|
| 3647 | + * @throws InvalidDataTypeException |
|
| 3648 | + * @throws InvalidInterfaceException |
|
| 3649 | + */ |
|
| 3650 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
| 3651 | + { |
|
| 3652 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
| 3653 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 3654 | + $notices = EE_Error::get_notices(false); |
|
| 3655 | + if (empty($this->_template_args['success'])) { |
|
| 3656 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
| 3657 | + } |
|
| 3658 | + if (empty($this->_template_args['errors'])) { |
|
| 3659 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
| 3660 | + } |
|
| 3661 | + if (empty($this->_template_args['attention'])) { |
|
| 3662 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
| 3663 | + } |
|
| 3664 | + } |
|
| 3665 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 3666 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
| 3667 | + if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3668 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
| 3669 | + $this->_add_transient( |
|
| 3670 | + $route, |
|
| 3671 | + $this->_template_args['notices'], |
|
| 3672 | + true, |
|
| 3673 | + $skip_route_verify |
|
| 3674 | + ); |
|
| 3675 | + } |
|
| 3676 | + } |
|
| 3677 | + |
|
| 3678 | + |
|
| 3679 | + /** |
|
| 3680 | + * get_action_link_or_button |
|
| 3681 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
| 3682 | + * |
|
| 3683 | + * @param string $action use this to indicate which action the url is generated with. |
|
| 3684 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
| 3685 | + * property. |
|
| 3686 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
| 3687 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
| 3688 | + * @param string $base_url If this is not provided |
|
| 3689 | + * the _admin_base_url will be used as the default for the button base_url. |
|
| 3690 | + * Otherwise this value will be used. |
|
| 3691 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
| 3692 | + * @return string |
|
| 3693 | + * @throws InvalidArgumentException |
|
| 3694 | + * @throws InvalidInterfaceException |
|
| 3695 | + * @throws InvalidDataTypeException |
|
| 3696 | + * @throws EE_Error |
|
| 3697 | + */ |
|
| 3698 | + public function get_action_link_or_button( |
|
| 3699 | + $action, |
|
| 3700 | + $type = 'add', |
|
| 3701 | + $extra_request = array(), |
|
| 3702 | + $class = 'button-primary', |
|
| 3703 | + $base_url = '', |
|
| 3704 | + $exclude_nonce = false |
|
| 3705 | + ) { |
|
| 3706 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
| 3707 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3708 | + throw new EE_Error( |
|
| 3709 | + sprintf( |
|
| 3710 | + esc_html__( |
|
| 3711 | + 'There is no page route for given action for the button. This action was given: %s', |
|
| 3712 | + 'event_espresso' |
|
| 3713 | + ), |
|
| 3714 | + $action |
|
| 3715 | + ) |
|
| 3716 | + ); |
|
| 3717 | + } |
|
| 3718 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3719 | + throw new EE_Error( |
|
| 3720 | + sprintf( |
|
| 3721 | + __( |
|
| 3722 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
| 3723 | + 'event_espresso' |
|
| 3724 | + ), |
|
| 3725 | + $type |
|
| 3726 | + ) |
|
| 3727 | + ); |
|
| 3728 | + } |
|
| 3729 | + // finally check user access for this button. |
|
| 3730 | + $has_access = $this->check_user_access($action, true); |
|
| 3731 | + if (! $has_access) { |
|
| 3732 | + return ''; |
|
| 3733 | + } |
|
| 3734 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
| 3735 | + $query_args = array( |
|
| 3736 | + 'action' => $action, |
|
| 3737 | + ); |
|
| 3738 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
| 3739 | + if (! empty($extra_request)) { |
|
| 3740 | + $query_args = array_merge($extra_request, $query_args); |
|
| 3741 | + } |
|
| 3742 | + $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
| 3743 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3744 | + } |
|
| 3745 | + |
|
| 3746 | + |
|
| 3747 | + /** |
|
| 3748 | + * _per_page_screen_option |
|
| 3749 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
| 3750 | + * |
|
| 3751 | + * @return void |
|
| 3752 | + * @throws InvalidArgumentException |
|
| 3753 | + * @throws InvalidInterfaceException |
|
| 3754 | + * @throws InvalidDataTypeException |
|
| 3755 | + */ |
|
| 3756 | + protected function _per_page_screen_option() |
|
| 3757 | + { |
|
| 3758 | + $option = 'per_page'; |
|
| 3759 | + $args = array( |
|
| 3760 | + 'label' => apply_filters( |
|
| 3761 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
| 3762 | + $this->_admin_page_title, |
|
| 3763 | + $this |
|
| 3764 | + ), |
|
| 3765 | + 'default' => (int) apply_filters( |
|
| 3766 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
| 3767 | + 20 |
|
| 3768 | + ), |
|
| 3769 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3770 | + ); |
|
| 3771 | + // ONLY add the screen option if the user has access to it. |
|
| 3772 | + if ($this->check_user_access($this->_current_view, true)) { |
|
| 3773 | + add_screen_option($option, $args); |
|
| 3774 | + } |
|
| 3775 | + } |
|
| 3776 | + |
|
| 3777 | + |
|
| 3778 | + /** |
|
| 3779 | + * set_per_page_screen_option |
|
| 3780 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
| 3781 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
| 3782 | + * admin_menu. |
|
| 3783 | + * |
|
| 3784 | + * @return void |
|
| 3785 | + */ |
|
| 3786 | + private function _set_per_page_screen_options() |
|
| 3787 | + { |
|
| 3788 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
| 3789 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
| 3790 | + if (! $user = wp_get_current_user()) { |
|
| 3791 | + return; |
|
| 3792 | + } |
|
| 3793 | + $option = $_POST['wp_screen_options']['option']; |
|
| 3794 | + $value = $_POST['wp_screen_options']['value']; |
|
| 3795 | + if ($option !== sanitize_key($option)) { |
|
| 3796 | + return; |
|
| 3797 | + } |
|
| 3798 | + $map_option = $option; |
|
| 3799 | + $option = str_replace('-', '_', $option); |
|
| 3800 | + switch ($map_option) { |
|
| 3801 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3802 | + $value = (int) $value; |
|
| 3803 | + $max_value = apply_filters( |
|
| 3804 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
| 3805 | + 999, |
|
| 3806 | + $this->_current_page, |
|
| 3807 | + $this->_current_view |
|
| 3808 | + ); |
|
| 3809 | + if ($value < 1) { |
|
| 3810 | + return; |
|
| 3811 | + } |
|
| 3812 | + $value = min($value, $max_value); |
|
| 3813 | + break; |
|
| 3814 | + default: |
|
| 3815 | + $value = apply_filters( |
|
| 3816 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
| 3817 | + false, |
|
| 3818 | + $option, |
|
| 3819 | + $value |
|
| 3820 | + ); |
|
| 3821 | + if (false === $value) { |
|
| 3822 | + return; |
|
| 3823 | + } |
|
| 3824 | + break; |
|
| 3825 | + } |
|
| 3826 | + update_user_meta($user->ID, $option, $value); |
|
| 3827 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
| 3828 | + exit; |
|
| 3829 | + } |
|
| 3830 | + } |
|
| 3831 | + |
|
| 3832 | + |
|
| 3833 | + /** |
|
| 3834 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
| 3835 | + * |
|
| 3836 | + * @param array $data array that will be assigned to template args. |
|
| 3837 | + */ |
|
| 3838 | + public function set_template_args($data) |
|
| 3839 | + { |
|
| 3840 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
| 3841 | + } |
|
| 3842 | + |
|
| 3843 | + |
|
| 3844 | + /** |
|
| 3845 | + * This makes available the WP transient system for temporarily moving data between routes |
|
| 3846 | + * |
|
| 3847 | + * @param string $route the route that should receive the transient |
|
| 3848 | + * @param array $data the data that gets sent |
|
| 3849 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
| 3850 | + * normal route transient. |
|
| 3851 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
| 3852 | + * when we are adding a transient before page_routes have been defined. |
|
| 3853 | + * @return void |
|
| 3854 | + * @throws EE_Error |
|
| 3855 | + */ |
|
| 3856 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
| 3857 | + { |
|
| 3858 | + $user_id = get_current_user_id(); |
|
| 3859 | + if (! $skip_route_verify) { |
|
| 3860 | + $this->_verify_route($route); |
|
| 3861 | + } |
|
| 3862 | + // now let's set the string for what kind of transient we're setting |
|
| 3863 | + $transient = $notices |
|
| 3864 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3865 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3866 | + $data = $notices ? array('notices' => $data) : $data; |
|
| 3867 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
| 3868 | + $existing = is_multisite() && is_network_admin() |
|
| 3869 | + ? get_site_transient($transient) |
|
| 3870 | + : get_transient($transient); |
|
| 3871 | + if ($existing) { |
|
| 3872 | + $data = array_merge((array) $data, (array) $existing); |
|
| 3873 | + } |
|
| 3874 | + if (is_multisite() && is_network_admin()) { |
|
| 3875 | + set_site_transient($transient, $data, 8); |
|
| 3876 | + } else { |
|
| 3877 | + set_transient($transient, $data, 8); |
|
| 3878 | + } |
|
| 3879 | + } |
|
| 3880 | + |
|
| 3881 | + |
|
| 3882 | + /** |
|
| 3883 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
| 3884 | + * |
|
| 3885 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
| 3886 | + * @param string $route |
|
| 3887 | + * @return mixed data |
|
| 3888 | + */ |
|
| 3889 | + protected function _get_transient($notices = false, $route = '') |
|
| 3890 | + { |
|
| 3891 | + $user_id = get_current_user_id(); |
|
| 3892 | + $route = ! $route ? $this->_req_action : $route; |
|
| 3893 | + $transient = $notices |
|
| 3894 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3895 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3896 | + $data = is_multisite() && is_network_admin() |
|
| 3897 | + ? get_site_transient($transient) |
|
| 3898 | + : get_transient($transient); |
|
| 3899 | + // delete transient after retrieval (just in case it hasn't expired); |
|
| 3900 | + if (is_multisite() && is_network_admin()) { |
|
| 3901 | + delete_site_transient($transient); |
|
| 3902 | + } else { |
|
| 3903 | + delete_transient($transient); |
|
| 3904 | + } |
|
| 3905 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
| 3906 | + } |
|
| 3907 | + |
|
| 3908 | + |
|
| 3909 | + /** |
|
| 3910 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
| 3911 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
| 3912 | + * default route callback on the EE_Admin page you want it run.) |
|
| 3913 | + * |
|
| 3914 | + * @return void |
|
| 3915 | + */ |
|
| 3916 | + protected function _transient_garbage_collection() |
|
| 3917 | + { |
|
| 3918 | + global $wpdb; |
|
| 3919 | + // retrieve all existing transients |
|
| 3920 | + $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
| 3921 | + if ($results = $wpdb->get_results($query)) { |
|
| 3922 | + foreach ($results as $result) { |
|
| 3923 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
| 3924 | + get_transient($transient); |
|
| 3925 | + if (is_multisite() && is_network_admin()) { |
|
| 3926 | + get_site_transient($transient); |
|
| 3927 | + } |
|
| 3928 | + } |
|
| 3929 | + } |
|
| 3930 | + } |
|
| 3931 | + |
|
| 3932 | + |
|
| 3933 | + /** |
|
| 3934 | + * get_view |
|
| 3935 | + * |
|
| 3936 | + * @return string content of _view property |
|
| 3937 | + */ |
|
| 3938 | + public function get_view() |
|
| 3939 | + { |
|
| 3940 | + return $this->_view; |
|
| 3941 | + } |
|
| 3942 | + |
|
| 3943 | + |
|
| 3944 | + /** |
|
| 3945 | + * getter for the protected $_views property |
|
| 3946 | + * |
|
| 3947 | + * @return array |
|
| 3948 | + */ |
|
| 3949 | + public function get_views() |
|
| 3950 | + { |
|
| 3951 | + return $this->_views; |
|
| 3952 | + } |
|
| 3953 | + |
|
| 3954 | + |
|
| 3955 | + /** |
|
| 3956 | + * get_current_page |
|
| 3957 | + * |
|
| 3958 | + * @return string _current_page property value |
|
| 3959 | + */ |
|
| 3960 | + public function get_current_page() |
|
| 3961 | + { |
|
| 3962 | + return $this->_current_page; |
|
| 3963 | + } |
|
| 3964 | + |
|
| 3965 | + |
|
| 3966 | + /** |
|
| 3967 | + * get_current_view |
|
| 3968 | + * |
|
| 3969 | + * @return string _current_view property value |
|
| 3970 | + */ |
|
| 3971 | + public function get_current_view() |
|
| 3972 | + { |
|
| 3973 | + return $this->_current_view; |
|
| 3974 | + } |
|
| 3975 | + |
|
| 3976 | + |
|
| 3977 | + /** |
|
| 3978 | + * get_current_screen |
|
| 3979 | + * |
|
| 3980 | + * @return object The current WP_Screen object |
|
| 3981 | + */ |
|
| 3982 | + public function get_current_screen() |
|
| 3983 | + { |
|
| 3984 | + return $this->_current_screen; |
|
| 3985 | + } |
|
| 3986 | + |
|
| 3987 | + |
|
| 3988 | + /** |
|
| 3989 | + * get_current_page_view_url |
|
| 3990 | + * |
|
| 3991 | + * @return string This returns the url for the current_page_view. |
|
| 3992 | + */ |
|
| 3993 | + public function get_current_page_view_url() |
|
| 3994 | + { |
|
| 3995 | + return $this->_current_page_view_url; |
|
| 3996 | + } |
|
| 3997 | + |
|
| 3998 | + |
|
| 3999 | + /** |
|
| 4000 | + * just returns the _req_data property |
|
| 4001 | + * |
|
| 4002 | + * @return array |
|
| 4003 | + */ |
|
| 4004 | + public function get_request_data() |
|
| 4005 | + { |
|
| 4006 | + return $this->_req_data; |
|
| 4007 | + } |
|
| 4008 | + |
|
| 4009 | + |
|
| 4010 | + /** |
|
| 4011 | + * returns the _req_data protected property |
|
| 4012 | + * |
|
| 4013 | + * @return string |
|
| 4014 | + */ |
|
| 4015 | + public function get_req_action() |
|
| 4016 | + { |
|
| 4017 | + return $this->_req_action; |
|
| 4018 | + } |
|
| 4019 | + |
|
| 4020 | + |
|
| 4021 | + /** |
|
| 4022 | + * @return bool value of $_is_caf property |
|
| 4023 | + */ |
|
| 4024 | + public function is_caf() |
|
| 4025 | + { |
|
| 4026 | + return $this->_is_caf; |
|
| 4027 | + } |
|
| 4028 | + |
|
| 4029 | + |
|
| 4030 | + /** |
|
| 4031 | + * @return mixed |
|
| 4032 | + */ |
|
| 4033 | + public function default_espresso_metaboxes() |
|
| 4034 | + { |
|
| 4035 | + return $this->_default_espresso_metaboxes; |
|
| 4036 | + } |
|
| 4037 | + |
|
| 4038 | + |
|
| 4039 | + /** |
|
| 4040 | + * @return mixed |
|
| 4041 | + */ |
|
| 4042 | + public function admin_base_url() |
|
| 4043 | + { |
|
| 4044 | + return $this->_admin_base_url; |
|
| 4045 | + } |
|
| 4046 | + |
|
| 4047 | + |
|
| 4048 | + /** |
|
| 4049 | + * @return mixed |
|
| 4050 | + */ |
|
| 4051 | + public function wp_page_slug() |
|
| 4052 | + { |
|
| 4053 | + return $this->_wp_page_slug; |
|
| 4054 | + } |
|
| 4055 | + |
|
| 4056 | + |
|
| 4057 | + /** |
|
| 4058 | + * updates espresso configuration settings |
|
| 4059 | + * |
|
| 4060 | + * @param string $tab |
|
| 4061 | + * @param EE_Config_Base|EE_Config $config |
|
| 4062 | + * @param string $file file where error occurred |
|
| 4063 | + * @param string $func function where error occurred |
|
| 4064 | + * @param string $line line no where error occurred |
|
| 4065 | + * @return boolean |
|
| 4066 | + */ |
|
| 4067 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
| 4068 | + { |
|
| 4069 | + // remove any options that are NOT going to be saved with the config settings. |
|
| 4070 | + if (isset($config->core->ee_ueip_optin)) { |
|
| 4071 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
| 4072 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
| 4073 | + update_option('ee_ueip_has_notified', true); |
|
| 4074 | + } |
|
| 4075 | + // and save it (note we're also doing the network save here) |
|
| 4076 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
| 4077 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
| 4078 | + if ($config_saved && $net_saved) { |
|
| 4079 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
| 4080 | + return true; |
|
| 4081 | + } |
|
| 4082 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
| 4083 | + return false; |
|
| 4084 | + } |
|
| 4085 | + |
|
| 4086 | + |
|
| 4087 | + /** |
|
| 4088 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
| 4089 | + * |
|
| 4090 | + * @return array |
|
| 4091 | + */ |
|
| 4092 | + public function get_yes_no_values() |
|
| 4093 | + { |
|
| 4094 | + return $this->_yes_no_values; |
|
| 4095 | + } |
|
| 4096 | + |
|
| 4097 | + |
|
| 4098 | + /** |
|
| 4099 | + * @return string |
|
| 4100 | + * @throws ReflectionException |
|
| 4101 | + * @since $VID:$ |
|
| 4102 | + */ |
|
| 4103 | + protected function _get_dir() |
|
| 4104 | + { |
|
| 4105 | + $reflector = new ReflectionClass(get_class($this)); |
|
| 4106 | + return dirname($reflector->getFileName()); |
|
| 4107 | + } |
|
| 4108 | + |
|
| 4109 | + |
|
| 4110 | + /** |
|
| 4111 | + * A helper for getting a "next link". |
|
| 4112 | + * |
|
| 4113 | + * @param string $url The url to link to |
|
| 4114 | + * @param string $class The class to use. |
|
| 4115 | + * @return string |
|
| 4116 | + */ |
|
| 4117 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
| 4118 | + { |
|
| 4119 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4120 | + } |
|
| 4121 | + |
|
| 4122 | + |
|
| 4123 | + /** |
|
| 4124 | + * A helper for getting a "previous link". |
|
| 4125 | + * |
|
| 4126 | + * @param string $url The url to link to |
|
| 4127 | + * @param string $class The class to use. |
|
| 4128 | + * @return string |
|
| 4129 | + */ |
|
| 4130 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
| 4131 | + { |
|
| 4132 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4133 | + } |
|
| 4134 | + |
|
| 4135 | + |
|
| 4136 | + |
|
| 4137 | + |
|
| 4138 | + |
|
| 4139 | + |
|
| 4140 | + |
|
| 4141 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
| 4142 | + |
|
| 4143 | + |
|
| 4144 | + /** |
|
| 4145 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
| 4146 | + * 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 |
|
| 4147 | + * _req_data array. |
|
| 4148 | + * |
|
| 4149 | + * @return bool success/fail |
|
| 4150 | + * @throws EE_Error |
|
| 4151 | + * @throws InvalidArgumentException |
|
| 4152 | + * @throws ReflectionException |
|
| 4153 | + * @throws InvalidDataTypeException |
|
| 4154 | + * @throws InvalidInterfaceException |
|
| 4155 | + */ |
|
| 4156 | + protected function _process_resend_registration() |
|
| 4157 | + { |
|
| 4158 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
| 4159 | + do_action( |
|
| 4160 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
| 4161 | + $this->_template_args['success'], |
|
| 4162 | + $this->_req_data |
|
| 4163 | + ); |
|
| 4164 | + return $this->_template_args['success']; |
|
| 4165 | + } |
|
| 4166 | + |
|
| 4167 | + |
|
| 4168 | + /** |
|
| 4169 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
| 4170 | + * |
|
| 4171 | + * @param EE_Payment $payment |
|
| 4172 | + * @return bool success/fail |
|
| 4173 | + */ |
|
| 4174 | + protected function _process_payment_notification(EE_Payment $payment) |
|
| 4175 | + { |
|
| 4176 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
| 4177 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
| 4178 | + $this->_template_args['success'] = apply_filters( |
|
| 4179 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
| 4180 | + false, |
|
| 4181 | + $payment |
|
| 4182 | + ); |
|
| 4183 | + return $this->_template_args['success']; |
|
| 4184 | + } |
|
| 4185 | 4185 | } |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | ); |
| 572 | 572 | global $ee_menu_slugs; |
| 573 | 573 | $ee_menu_slugs = (array) $ee_menu_slugs; |
| 574 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
| 574 | + if ( ! defined('DOING_AJAX') && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
| 575 | 575 | return; |
| 576 | 576 | } |
| 577 | 577 | // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | ? $this->_req_data['route'] |
| 596 | 596 | : $this->_req_action; |
| 597 | 597 | $this->_current_view = $this->_req_action; |
| 598 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
| 598 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
| 599 | 599 | $this->_define_page_props(); |
| 600 | 600 | $this->_current_page_view_url = add_query_arg( |
| 601 | 601 | array('page' => $this->_current_page, 'action' => $this->_current_view), |
@@ -629,21 +629,21 @@ discard block |
||
| 629 | 629 | } |
| 630 | 630 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
| 631 | 631 | $this->_page_routes = apply_filters( |
| 632 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
| 632 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
| 633 | 633 | $this->_page_routes, |
| 634 | 634 | $this |
| 635 | 635 | ); |
| 636 | 636 | $this->_page_config = apply_filters( |
| 637 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
| 637 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
| 638 | 638 | $this->_page_config, |
| 639 | 639 | $this |
| 640 | 640 | ); |
| 641 | 641 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
| 642 | 642 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
| 643 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
| 643 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
| 644 | 644 | add_action( |
| 645 | 645 | 'AHEE__EE_Admin_Page__route_admin_request', |
| 646 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
| 646 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), |
|
| 647 | 647 | 10, |
| 648 | 648 | 2 |
| 649 | 649 | ); |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | if ($this->_is_UI_request) { |
| 657 | 657 | // admin_init stuff - global, all views for this page class, specific view |
| 658 | 658 | add_action('admin_init', array($this, 'admin_init'), 10); |
| 659 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
| 660 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
| 659 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
| 660 | + add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15); |
|
| 661 | 661 | } |
| 662 | 662 | } else { |
| 663 | 663 | // hijack regular WP loading and route admin request immediately |
@@ -676,12 +676,12 @@ discard block |
||
| 676 | 676 | */ |
| 677 | 677 | private function _do_other_page_hooks() |
| 678 | 678 | { |
| 679 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
| 679 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array()); |
|
| 680 | 680 | foreach ($registered_pages as $page) { |
| 681 | 681 | // now let's setup the file name and class that should be present |
| 682 | 682 | $classname = str_replace('.class.php', '', $page); |
| 683 | 683 | // autoloaders should take care of loading file |
| 684 | - if (! class_exists($classname)) { |
|
| 684 | + if ( ! class_exists($classname)) { |
|
| 685 | 685 | $error_msg[] = sprintf( |
| 686 | 686 | esc_html__( |
| 687 | 687 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | ), |
| 699 | 699 | $page, |
| 700 | 700 | '<br />', |
| 701 | - '<strong>' . $classname . '</strong>' |
|
| 701 | + '<strong>'.$classname.'</strong>' |
|
| 702 | 702 | ); |
| 703 | 703 | throw new EE_Error(implode('||', $error_msg)); |
| 704 | 704 | } |
@@ -746,13 +746,13 @@ discard block |
||
| 746 | 746 | // load admin_notices - global, page class, and view specific |
| 747 | 747 | add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
| 748 | 748 | add_action('admin_notices', array($this, 'admin_notices'), 10); |
| 749 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
| 750 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
| 749 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
| 750 | + add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15); |
|
| 751 | 751 | } |
| 752 | 752 | // load network admin_notices - global, page class, and view specific |
| 753 | 753 | add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
| 754 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
| 755 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
| 754 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
| 755 | + add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view)); |
|
| 756 | 756 | } |
| 757 | 757 | // this will save any per_page screen options if they are present |
| 758 | 758 | $this->_set_per_page_screen_options(); |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | */ |
| 874 | 874 | protected function _verify_routes() |
| 875 | 875 | { |
| 876 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 876 | + if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
| 877 | 877 | return false; |
| 878 | 878 | } |
| 879 | 879 | $this->_route = false; |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | $this->_admin_page_title |
| 886 | 886 | ); |
| 887 | 887 | // developer error msg |
| 888 | - $error_msg .= '||' . $error_msg |
|
| 888 | + $error_msg .= '||'.$error_msg |
|
| 889 | 889 | . esc_html__( |
| 890 | 890 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
| 891 | 891 | 'event_espresso' |
@@ -894,9 +894,9 @@ discard block |
||
| 894 | 894 | } |
| 895 | 895 | // and that the requested page route exists |
| 896 | 896 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
| 897 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
| 898 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
| 899 | - ? $this->_page_config[ $this->_req_action ] : array(); |
|
| 897 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
| 898 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
| 899 | + ? $this->_page_config[$this->_req_action] : array(); |
|
| 900 | 900 | } else { |
| 901 | 901 | // user error msg |
| 902 | 902 | $error_msg = sprintf( |
@@ -907,7 +907,7 @@ discard block |
||
| 907 | 907 | $this->_admin_page_title |
| 908 | 908 | ); |
| 909 | 909 | // developer error msg |
| 910 | - $error_msg .= '||' . $error_msg |
|
| 910 | + $error_msg .= '||'.$error_msg |
|
| 911 | 911 | . sprintf( |
| 912 | 912 | esc_html__( |
| 913 | 913 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | throw new EE_Error($error_msg); |
| 919 | 919 | } |
| 920 | 920 | // and that a default route exists |
| 921 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
| 921 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
| 922 | 922 | // user error msg |
| 923 | 923 | $error_msg = sprintf( |
| 924 | 924 | esc_html__( |
@@ -928,7 +928,7 @@ discard block |
||
| 928 | 928 | $this->_admin_page_title |
| 929 | 929 | ); |
| 930 | 930 | // developer error msg |
| 931 | - $error_msg .= '||' . $error_msg |
|
| 931 | + $error_msg .= '||'.$error_msg |
|
| 932 | 932 | . esc_html__( |
| 933 | 933 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
| 934 | 934 | 'event_espresso' |
@@ -968,7 +968,7 @@ discard block |
||
| 968 | 968 | $this->_admin_page_title |
| 969 | 969 | ); |
| 970 | 970 | // developer error msg |
| 971 | - $error_msg .= '||' . $error_msg |
|
| 971 | + $error_msg .= '||'.$error_msg |
|
| 972 | 972 | . sprintf( |
| 973 | 973 | esc_html__( |
| 974 | 974 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | protected function _verify_nonce($nonce, $nonce_ref) |
| 997 | 997 | { |
| 998 | 998 | // verify nonce against expected value |
| 999 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 999 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
| 1000 | 1000 | // these are not the droids you are looking for !!! |
| 1001 | 1001 | $msg = sprintf( |
| 1002 | 1002 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | EE_Admin_Page::class |
| 1014 | 1014 | ); |
| 1015 | 1015 | } |
| 1016 | - if (! defined('DOING_AJAX')) { |
|
| 1016 | + if ( ! defined('DOING_AJAX')) { |
|
| 1017 | 1017 | wp_die($msg); |
| 1018 | 1018 | } else { |
| 1019 | 1019 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | */ |
| 1039 | 1039 | protected function _route_admin_request() |
| 1040 | 1040 | { |
| 1041 | - if (! $this->_is_UI_request) { |
|
| 1041 | + if ( ! $this->_is_UI_request) { |
|
| 1042 | 1042 | $this->_verify_routes(); |
| 1043 | 1043 | } |
| 1044 | 1044 | $nonce_check = isset($this->_route_config['require_nonce']) |
@@ -1046,8 +1046,8 @@ discard block |
||
| 1046 | 1046 | : true; |
| 1047 | 1047 | if ($this->_req_action !== 'default' && $nonce_check) { |
| 1048 | 1048 | // set nonce from post data |
| 1049 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 1050 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
| 1049 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 1050 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
| 1051 | 1051 | : ''; |
| 1052 | 1052 | $this->_verify_nonce($nonce, $this->_req_nonce); |
| 1053 | 1053 | } |
@@ -1062,7 +1062,7 @@ discard block |
||
| 1062 | 1062 | $error_msg = ''; |
| 1063 | 1063 | // action right before calling route |
| 1064 | 1064 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
| 1065 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1065 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
| 1066 | 1066 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
| 1067 | 1067 | } |
| 1068 | 1068 | // right before calling the route, let's remove _wp_http_referer from the |
@@ -1071,7 +1071,7 @@ discard block |
||
| 1071 | 1071 | '_wp_http_referer', |
| 1072 | 1072 | wp_unslash($_SERVER['REQUEST_URI']) |
| 1073 | 1073 | ); |
| 1074 | - if (! empty($func)) { |
|
| 1074 | + if ( ! empty($func)) { |
|
| 1075 | 1075 | if (is_array($func)) { |
| 1076 | 1076 | [$class, $method] = $func; |
| 1077 | 1077 | } elseif (strpos($func, '::') !== false) { |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | $class = $this; |
| 1081 | 1081 | $method = $func; |
| 1082 | 1082 | } |
| 1083 | - if (! (is_object($class) && $class === $this)) { |
|
| 1083 | + if ( ! (is_object($class) && $class === $this)) { |
|
| 1084 | 1084 | // send along this admin page object for access by addons. |
| 1085 | 1085 | $args['admin_page_object'] = $this; |
| 1086 | 1086 | } |
@@ -1114,7 +1114,7 @@ discard block |
||
| 1114 | 1114 | $method |
| 1115 | 1115 | ); |
| 1116 | 1116 | } |
| 1117 | - if (! empty($error_msg)) { |
|
| 1117 | + if ( ! empty($error_msg)) { |
|
| 1118 | 1118 | throw new EE_Error($error_msg); |
| 1119 | 1119 | } |
| 1120 | 1120 | } |
@@ -1198,7 +1198,7 @@ discard block |
||
| 1198 | 1198 | if (strpos($key, 'nonce') !== false) { |
| 1199 | 1199 | continue; |
| 1200 | 1200 | } |
| 1201 | - $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
| 1201 | + $args['wp_referer['.$key.']'] = $value; |
|
| 1202 | 1202 | } |
| 1203 | 1203 | } |
| 1204 | 1204 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1239,8 +1239,8 @@ discard block |
||
| 1239 | 1239 | protected function _add_help_tabs() |
| 1240 | 1240 | { |
| 1241 | 1241 | $tour_buttons = ''; |
| 1242 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
| 1243 | - $config = $this->_page_config[ $this->_req_action ]; |
|
| 1242 | + if (isset($this->_page_config[$this->_req_action])) { |
|
| 1243 | + $config = $this->_page_config[$this->_req_action]; |
|
| 1244 | 1244 | // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
| 1245 | 1245 | // is there a help tour for the current route? if there is let's setup the tour buttons |
| 1246 | 1246 | // if (isset($this->_help_tour[ $this->_req_action ])) { |
@@ -1263,7 +1263,7 @@ discard block |
||
| 1263 | 1263 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
| 1264 | 1264 | if (is_array($config) && isset($config['help_sidebar'])) { |
| 1265 | 1265 | // check that the callback given is valid |
| 1266 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
| 1266 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
| 1267 | 1267 | throw new EE_Error( |
| 1268 | 1268 | sprintf( |
| 1269 | 1269 | esc_html__( |
@@ -1276,7 +1276,7 @@ discard block |
||
| 1276 | 1276 | ); |
| 1277 | 1277 | } |
| 1278 | 1278 | $content = apply_filters( |
| 1279 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
| 1279 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
| 1280 | 1280 | $this->{$config['help_sidebar']}() |
| 1281 | 1281 | ); |
| 1282 | 1282 | $content .= $tour_buttons; // add help tour buttons. |
@@ -1284,30 +1284,30 @@ discard block |
||
| 1284 | 1284 | $this->_current_screen->set_help_sidebar($content); |
| 1285 | 1285 | } |
| 1286 | 1286 | // if there ARE tour buttons... |
| 1287 | - if (! empty($tour_buttons)) { |
|
| 1287 | + if ( ! empty($tour_buttons)) { |
|
| 1288 | 1288 | // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar. |
| 1289 | - if (! isset($config['help_sidebar'])) { |
|
| 1289 | + if ( ! isset($config['help_sidebar'])) { |
|
| 1290 | 1290 | $this->_current_screen->set_help_sidebar($tour_buttons); |
| 1291 | 1291 | } |
| 1292 | 1292 | // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
| 1293 | - if (! isset($config['help_tabs'])) { |
|
| 1293 | + if ( ! isset($config['help_tabs'])) { |
|
| 1294 | 1294 | $_ht['id'] = $this->page_slug; |
| 1295 | 1295 | $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
| 1296 | 1296 | $_ht['content'] = '<p>' |
| 1297 | 1297 | . esc_html__( |
| 1298 | 1298 | 'The buttons to the right allow you to start/restart any help tours available for this page', |
| 1299 | 1299 | 'event_espresso' |
| 1300 | - ) . '</p>'; |
|
| 1300 | + ).'</p>'; |
|
| 1301 | 1301 | $this->_current_screen->add_help_tab($_ht); |
| 1302 | 1302 | } |
| 1303 | 1303 | } |
| 1304 | - if (! isset($config['help_tabs'])) { |
|
| 1304 | + if ( ! isset($config['help_tabs'])) { |
|
| 1305 | 1305 | return; |
| 1306 | 1306 | } //no help tabs for this route |
| 1307 | 1307 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
| 1308 | 1308 | // we're here so there ARE help tabs! |
| 1309 | 1309 | // make sure we've got what we need |
| 1310 | - if (! isset($cfg['title'])) { |
|
| 1310 | + if ( ! isset($cfg['title'])) { |
|
| 1311 | 1311 | throw new EE_Error( |
| 1312 | 1312 | esc_html__( |
| 1313 | 1313 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1315,7 +1315,7 @@ discard block |
||
| 1315 | 1315 | ) |
| 1316 | 1316 | ); |
| 1317 | 1317 | } |
| 1318 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1318 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
| 1319 | 1319 | throw new EE_Error( |
| 1320 | 1320 | esc_html__( |
| 1321 | 1321 | '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', |
@@ -1324,11 +1324,11 @@ discard block |
||
| 1324 | 1324 | ); |
| 1325 | 1325 | } |
| 1326 | 1326 | // first priority goes to content. |
| 1327 | - if (! empty($cfg['content'])) { |
|
| 1327 | + if ( ! empty($cfg['content'])) { |
|
| 1328 | 1328 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
| 1329 | 1329 | // second priority goes to filename |
| 1330 | - } elseif (! empty($cfg['filename'])) { |
|
| 1331 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
| 1330 | + } elseif ( ! empty($cfg['filename'])) { |
|
| 1331 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
| 1332 | 1332 | // 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) |
| 1333 | 1333 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
| 1334 | 1334 | . basename($this->_get_dir()) |
@@ -1336,7 +1336,7 @@ discard block |
||
| 1336 | 1336 | . $cfg['filename'] |
| 1337 | 1337 | . '.help_tab.php' : $file_path; |
| 1338 | 1338 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
| 1339 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1339 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
| 1340 | 1340 | EE_Error::add_error( |
| 1341 | 1341 | sprintf( |
| 1342 | 1342 | esc_html__( |
@@ -1383,7 +1383,7 @@ discard block |
||
| 1383 | 1383 | return; |
| 1384 | 1384 | } |
| 1385 | 1385 | // setup config array for help tab method |
| 1386 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
| 1386 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
| 1387 | 1387 | $_ht = array( |
| 1388 | 1388 | 'id' => $id, |
| 1389 | 1389 | 'title' => $cfg['title'], |
@@ -1514,8 +1514,8 @@ discard block |
||
| 1514 | 1514 | $qtips = (array) $this->_route_config['qtips']; |
| 1515 | 1515 | // load qtip loader |
| 1516 | 1516 | $path = array( |
| 1517 | - $this->_get_dir() . '/qtips/', |
|
| 1518 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
| 1517 | + $this->_get_dir().'/qtips/', |
|
| 1518 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
| 1519 | 1519 | ); |
| 1520 | 1520 | $qtip_loader = EEH_Qtip_Loader::instance(); |
| 1521 | 1521 | if ($qtip_loader instanceof EEH_Qtip_Loader) { |
@@ -1558,12 +1558,12 @@ discard block |
||
| 1558 | 1558 | // nav tab is only to appear when route requested. |
| 1559 | 1559 | continue; |
| 1560 | 1560 | } |
| 1561 | - if (! $this->check_user_access($slug, true)) { |
|
| 1561 | + if ( ! $this->check_user_access($slug, true)) { |
|
| 1562 | 1562 | // no nav tab because current user does not have access. |
| 1563 | 1563 | continue; |
| 1564 | 1564 | } |
| 1565 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
| 1566 | - $this->_nav_tabs[ $slug ] = array( |
|
| 1565 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
| 1566 | + $this->_nav_tabs[$slug] = array( |
|
| 1567 | 1567 | 'url' => isset($config['nav']['url']) |
| 1568 | 1568 | ? $config['nav']['url'] |
| 1569 | 1569 | : EE_Admin_Page::add_query_args_and_nonce( |
@@ -1575,14 +1575,14 @@ discard block |
||
| 1575 | 1575 | : ucwords( |
| 1576 | 1576 | str_replace('_', ' ', $slug) |
| 1577 | 1577 | ), |
| 1578 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
| 1578 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
| 1579 | 1579 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
| 1580 | 1580 | ); |
| 1581 | 1581 | $i++; |
| 1582 | 1582 | } |
| 1583 | 1583 | // if $this->_nav_tabs is empty then lets set the default |
| 1584 | 1584 | if (empty($this->_nav_tabs)) { |
| 1585 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
| 1585 | + $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
| 1586 | 1586 | 'url' => $this->_admin_base_url, |
| 1587 | 1587 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
| 1588 | 1588 | 'css_class' => 'nav-tab-active', |
@@ -1607,10 +1607,10 @@ discard block |
||
| 1607 | 1607 | foreach ($this->_route_config['labels'] as $label => $text) { |
| 1608 | 1608 | if (is_array($text)) { |
| 1609 | 1609 | foreach ($text as $sublabel => $subtext) { |
| 1610 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
| 1610 | + $this->_labels[$label][$sublabel] = $subtext; |
|
| 1611 | 1611 | } |
| 1612 | 1612 | } else { |
| 1613 | - $this->_labels[ $label ] = $text; |
|
| 1613 | + $this->_labels[$label] = $text; |
|
| 1614 | 1614 | } |
| 1615 | 1615 | } |
| 1616 | 1616 | } |
@@ -1632,12 +1632,12 @@ discard block |
||
| 1632 | 1632 | { |
| 1633 | 1633 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 1634 | 1634 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
| 1635 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
| 1635 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
| 1636 | 1636 | && is_array( |
| 1637 | - $this->_page_routes[ $route_to_check ] |
|
| 1637 | + $this->_page_routes[$route_to_check] |
|
| 1638 | 1638 | ) |
| 1639 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
| 1640 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
| 1639 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
| 1640 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
| 1641 | 1641 | if (empty($capability) && empty($route_to_check)) { |
| 1642 | 1642 | $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
| 1643 | 1643 | : $this->_route['capability']; |
@@ -1752,7 +1752,7 @@ discard block |
||
| 1752 | 1752 | public function admin_footer_global() |
| 1753 | 1753 | { |
| 1754 | 1754 | // dialog container for dialog helper |
| 1755 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
| 1755 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n"; |
|
| 1756 | 1756 | $d_cont .= '<div class="ee-notices"></div>'; |
| 1757 | 1757 | $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
| 1758 | 1758 | $d_cont .= '</div>'; |
@@ -1763,7 +1763,7 @@ discard block |
||
| 1763 | 1763 | // echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
| 1764 | 1764 | // } |
| 1765 | 1765 | // current set timezone for timezone js |
| 1766 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
| 1766 | + echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>'; |
|
| 1767 | 1767 | } |
| 1768 | 1768 | |
| 1769 | 1769 | |
@@ -1797,7 +1797,7 @@ discard block |
||
| 1797 | 1797 | // loop through the array and setup content |
| 1798 | 1798 | foreach ($help_array as $trigger => $help) { |
| 1799 | 1799 | // make sure the array is setup properly |
| 1800 | - if (! isset($help['title'], $help['content'])) { |
|
| 1800 | + if ( ! isset($help['title'], $help['content'])) { |
|
| 1801 | 1801 | throw new EE_Error( |
| 1802 | 1802 | esc_html__( |
| 1803 | 1803 | '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', |
@@ -1812,7 +1812,7 @@ discard block |
||
| 1812 | 1812 | 'help_popup_content' => $help['content'], |
| 1813 | 1813 | ); |
| 1814 | 1814 | $content .= EEH_Template::display_template( |
| 1815 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
| 1815 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
| 1816 | 1816 | $template_args, |
| 1817 | 1817 | true |
| 1818 | 1818 | ); |
@@ -1834,15 +1834,15 @@ discard block |
||
| 1834 | 1834 | private function _get_help_content() |
| 1835 | 1835 | { |
| 1836 | 1836 | // what is the method we're looking for? |
| 1837 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
| 1837 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
| 1838 | 1838 | // if method doesn't exist let's get out. |
| 1839 | - if (! method_exists($this, $method_name)) { |
|
| 1839 | + if ( ! method_exists($this, $method_name)) { |
|
| 1840 | 1840 | return array(); |
| 1841 | 1841 | } |
| 1842 | 1842 | // k we're good to go let's retrieve the help array |
| 1843 | 1843 | $help_array = $this->{$method_name}(); |
| 1844 | 1844 | // make sure we've got an array! |
| 1845 | - if (! is_array($help_array)) { |
|
| 1845 | + if ( ! is_array($help_array)) { |
|
| 1846 | 1846 | throw new EE_Error( |
| 1847 | 1847 | esc_html__( |
| 1848 | 1848 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1874,8 +1874,8 @@ discard block |
||
| 1874 | 1874 | // 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 |
| 1875 | 1875 | $help_array = $this->_get_help_content(); |
| 1876 | 1876 | $help_content = ''; |
| 1877 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
| 1878 | - $help_array[ $trigger_id ] = array( |
|
| 1877 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
| 1878 | + $help_array[$trigger_id] = array( |
|
| 1879 | 1879 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
| 1880 | 1880 | 'content' => esc_html__( |
| 1881 | 1881 | '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.)', |
@@ -2073,12 +2073,12 @@ discard block |
||
| 2073 | 2073 | protected function _set_list_table() |
| 2074 | 2074 | { |
| 2075 | 2075 | // first is this a list_table view? |
| 2076 | - if (! isset($this->_route_config['list_table'])) { |
|
| 2076 | + if ( ! isset($this->_route_config['list_table'])) { |
|
| 2077 | 2077 | return; |
| 2078 | 2078 | } //not a list_table view so get out. |
| 2079 | 2079 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
| 2080 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
| 2081 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2080 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
| 2081 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
| 2082 | 2082 | // user error msg |
| 2083 | 2083 | $error_msg = esc_html__( |
| 2084 | 2084 | 'An error occurred. The requested list table views could not be found.', |
@@ -2098,10 +2098,10 @@ discard block |
||
| 2098 | 2098 | } |
| 2099 | 2099 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
| 2100 | 2100 | $this->_views = apply_filters( |
| 2101 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
| 2101 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
| 2102 | 2102 | $this->_views |
| 2103 | 2103 | ); |
| 2104 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
| 2104 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
| 2105 | 2105 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
| 2106 | 2106 | $this->_set_list_table_view(); |
| 2107 | 2107 | $this->_set_list_table_object(); |
@@ -2117,7 +2117,7 @@ discard block |
||
| 2117 | 2117 | { |
| 2118 | 2118 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2119 | 2119 | // looking at active items or dumpster diving ? |
| 2120 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2120 | + if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
| 2121 | 2121 | $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
| 2122 | 2122 | } else { |
| 2123 | 2123 | $this->_view = sanitize_key($this->_req_data['status']); |
@@ -2138,7 +2138,7 @@ discard block |
||
| 2138 | 2138 | protected function _set_list_table_object() |
| 2139 | 2139 | { |
| 2140 | 2140 | if (isset($this->_route_config['list_table'])) { |
| 2141 | - if (! class_exists($this->_route_config['list_table'])) { |
|
| 2141 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
| 2142 | 2142 | throw new EE_Error( |
| 2143 | 2143 | sprintf( |
| 2144 | 2144 | esc_html__( |
@@ -2176,17 +2176,17 @@ discard block |
||
| 2176 | 2176 | foreach ($this->_views as $key => $view) { |
| 2177 | 2177 | $query_args = array(); |
| 2178 | 2178 | // check for current view |
| 2179 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2179 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
| 2180 | 2180 | $query_args['action'] = $this->_req_action; |
| 2181 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 2181 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 2182 | 2182 | $query_args['status'] = $view['slug']; |
| 2183 | 2183 | // merge any other arguments sent in. |
| 2184 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
| 2185 | - foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) { |
|
| 2184 | + if (isset($extra_query_args[$view['slug']])) { |
|
| 2185 | + foreach ($extra_query_args[$view['slug']] as $extra_query_arg) { |
|
| 2186 | 2186 | $query_args[] = $extra_query_arg; |
| 2187 | 2187 | } |
| 2188 | 2188 | } |
| 2189 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2189 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2190 | 2190 | } |
| 2191 | 2191 | return $this->_views; |
| 2192 | 2192 | } |
@@ -2205,7 +2205,7 @@ discard block |
||
| 2205 | 2205 | { |
| 2206 | 2206 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2207 | 2207 | $values = array(10, 25, 50, 100); |
| 2208 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2208 | + $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
| 2209 | 2209 | if ($max_entries) { |
| 2210 | 2210 | $values[] = $max_entries; |
| 2211 | 2211 | sort($values); |
@@ -2217,14 +2217,14 @@ discard block |
||
| 2217 | 2217 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
| 2218 | 2218 | foreach ($values as $value) { |
| 2219 | 2219 | if ($value < $max_entries) { |
| 2220 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2220 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2221 | 2221 | $entries_per_page_dropdown .= ' |
| 2222 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
| 2222 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
| 2223 | 2223 | } |
| 2224 | 2224 | } |
| 2225 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
| 2225 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
| 2226 | 2226 | $entries_per_page_dropdown .= ' |
| 2227 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
| 2227 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
| 2228 | 2228 | $entries_per_page_dropdown .= ' |
| 2229 | 2229 | </select> |
| 2230 | 2230 | entries |
@@ -2248,7 +2248,7 @@ discard block |
||
| 2248 | 2248 | empty($this->_search_btn_label) ? $this->page_label |
| 2249 | 2249 | : $this->_search_btn_label |
| 2250 | 2250 | ); |
| 2251 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
| 2251 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
| 2252 | 2252 | } |
| 2253 | 2253 | |
| 2254 | 2254 | |
@@ -2336,7 +2336,7 @@ discard block |
||
| 2336 | 2336 | $total_columns = ! empty($screen_columns) |
| 2337 | 2337 | ? $screen_columns |
| 2338 | 2338 | : $this->_route_config['columns'][1]; |
| 2339 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
| 2339 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
| 2340 | 2340 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2341 | 2341 | $this->_template_args['screen'] = $this->_current_screen; |
| 2342 | 2342 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2381,7 +2381,7 @@ discard block |
||
| 2381 | 2381 | */ |
| 2382 | 2382 | protected function _espresso_ratings_request() |
| 2383 | 2383 | { |
| 2384 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2384 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
| 2385 | 2385 | return; |
| 2386 | 2386 | } |
| 2387 | 2387 | $ratings_box_title = apply_filters( |
@@ -2408,7 +2408,7 @@ discard block |
||
| 2408 | 2408 | */ |
| 2409 | 2409 | public function espresso_ratings_request() |
| 2410 | 2410 | { |
| 2411 | - EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php'); |
|
| 2411 | + EEH_Template::display_template(EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php'); |
|
| 2412 | 2412 | } |
| 2413 | 2413 | |
| 2414 | 2414 | |
@@ -2419,17 +2419,17 @@ discard block |
||
| 2419 | 2419 | . '</p><p class="hide-if-js">' |
| 2420 | 2420 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
| 2421 | 2421 | . '</p>'; |
| 2422 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
| 2423 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
| 2424 | - $post = '</div>' . "\n"; |
|
| 2425 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
| 2422 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
| 2423 | + $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>'; |
|
| 2424 | + $post = '</div>'."\n"; |
|
| 2425 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
| 2426 | 2426 | $output = get_transient($cache_key); |
| 2427 | 2427 | if ($output !== false) { |
| 2428 | - echo $pre . $output . $post; |
|
| 2428 | + echo $pre.$output.$post; |
|
| 2429 | 2429 | return true; |
| 2430 | 2430 | } |
| 2431 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2432 | - echo $pre . $loading . $post; |
|
| 2431 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 2432 | + echo $pre.$loading.$post; |
|
| 2433 | 2433 | return false; |
| 2434 | 2434 | } |
| 2435 | 2435 | ob_start(); |
@@ -2496,19 +2496,19 @@ discard block |
||
| 2496 | 2496 | public function espresso_sponsors_post_box() |
| 2497 | 2497 | { |
| 2498 | 2498 | EEH_Template::display_template( |
| 2499 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2499 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
| 2500 | 2500 | ); |
| 2501 | 2501 | } |
| 2502 | 2502 | |
| 2503 | 2503 | |
| 2504 | 2504 | private function _publish_post_box() |
| 2505 | 2505 | { |
| 2506 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
| 2506 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
| 2507 | 2507 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
| 2508 | 2508 | // then we'll use that for the metabox label. |
| 2509 | 2509 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
| 2510 | - if (! empty($this->_labels['publishbox'])) { |
|
| 2511 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
| 2510 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 2511 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
| 2512 | 2512 | : $this->_labels['publishbox']; |
| 2513 | 2513 | } else { |
| 2514 | 2514 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2537,7 +2537,7 @@ discard block |
||
| 2537 | 2537 | ? $this->_template_args['publish_box_extra_content'] |
| 2538 | 2538 | : ''; |
| 2539 | 2539 | echo EEH_Template::display_template( |
| 2540 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
| 2540 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
| 2541 | 2541 | $this->_template_args, |
| 2542 | 2542 | true |
| 2543 | 2543 | ); |
@@ -2627,8 +2627,8 @@ discard block |
||
| 2627 | 2627 | ); |
| 2628 | 2628 | } |
| 2629 | 2629 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
| 2630 | - if (! empty($name) && ! empty($id)) { |
|
| 2631 | - $hidden_field_arr[ $name ] = array( |
|
| 2630 | + if ( ! empty($name) && ! empty($id)) { |
|
| 2631 | + $hidden_field_arr[$name] = array( |
|
| 2632 | 2632 | 'type' => 'hidden', |
| 2633 | 2633 | 'value' => $id, |
| 2634 | 2634 | ); |
@@ -2638,7 +2638,7 @@ discard block |
||
| 2638 | 2638 | } |
| 2639 | 2639 | // add hidden field |
| 2640 | 2640 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
| 2641 | - ? $hf[ $name ]['field'] |
|
| 2641 | + ? $hf[$name]['field'] |
|
| 2642 | 2642 | : $hf; |
| 2643 | 2643 | } |
| 2644 | 2644 | |
@@ -2740,7 +2740,7 @@ discard block |
||
| 2740 | 2740 | } |
| 2741 | 2741 | // 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) |
| 2742 | 2742 | $call_back_func = $create_func |
| 2743 | - ? static function ($post, $metabox) { |
|
| 2743 | + ? static function($post, $metabox) { |
|
| 2744 | 2744 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2745 | 2745 | echo EEH_Template::display_template( |
| 2746 | 2746 | $metabox['args']['template_path'], |
@@ -2750,7 +2750,7 @@ discard block |
||
| 2750 | 2750 | } |
| 2751 | 2751 | : $callback; |
| 2752 | 2752 | add_meta_box( |
| 2753 | - str_replace('_', '-', $action) . '-mbox', |
|
| 2753 | + str_replace('_', '-', $action).'-mbox', |
|
| 2754 | 2754 | $title, |
| 2755 | 2755 | $call_back_func, |
| 2756 | 2756 | $this->_wp_page_slug, |
@@ -2857,9 +2857,9 @@ discard block |
||
| 2857 | 2857 | : 'espresso-default-admin'; |
| 2858 | 2858 | $template_path = $sidebar |
| 2859 | 2859 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
| 2860 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2860 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
| 2861 | 2861 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 2862 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2862 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
| 2863 | 2863 | } |
| 2864 | 2864 | $template_path = ! empty($this->_column_template_path) |
| 2865 | 2865 | ? $this->_column_template_path : $template_path; |
@@ -2924,7 +2924,7 @@ discard block |
||
| 2924 | 2924 | ) |
| 2925 | 2925 | : $this->_template_args['preview_action_button']; |
| 2926 | 2926 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 2927 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
| 2927 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
| 2928 | 2928 | $this->_template_args, |
| 2929 | 2929 | true |
| 2930 | 2930 | ); |
@@ -2982,7 +2982,7 @@ discard block |
||
| 2982 | 2982 | // setup search attributes |
| 2983 | 2983 | $this->_set_search_attributes(); |
| 2984 | 2984 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
| 2985 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
| 2985 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
| 2986 | 2986 | $this->_template_args['table_url'] = defined('DOING_AJAX') |
| 2987 | 2987 | ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
| 2988 | 2988 | : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
@@ -2990,10 +2990,10 @@ discard block |
||
| 2990 | 2990 | $this->_template_args['current_route'] = $this->_req_action; |
| 2991 | 2991 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
| 2992 | 2992 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
| 2993 | - if (! empty($ajax_sorting_callback)) { |
|
| 2993 | + if ( ! empty($ajax_sorting_callback)) { |
|
| 2994 | 2994 | $sortable_list_table_form_fields = wp_nonce_field( |
| 2995 | - $ajax_sorting_callback . '_nonce', |
|
| 2996 | - $ajax_sorting_callback . '_nonce', |
|
| 2995 | + $ajax_sorting_callback.'_nonce', |
|
| 2996 | + $ajax_sorting_callback.'_nonce', |
|
| 2997 | 2997 | false, |
| 2998 | 2998 | false |
| 2999 | 2999 | ); |
@@ -3010,7 +3010,7 @@ discard block |
||
| 3010 | 3010 | $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
| 3011 | 3011 | ? $this->_template_args['list_table_hidden_fields'] |
| 3012 | 3012 | : ''; |
| 3013 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
| 3013 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
| 3014 | 3014 | $hidden_form_fields .= '<input type="hidden" name="' |
| 3015 | 3015 | . $nonce_ref |
| 3016 | 3016 | . '" value="' |
@@ -3019,10 +3019,10 @@ discard block |
||
| 3019 | 3019 | $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
| 3020 | 3020 | // display message about search results? |
| 3021 | 3021 | $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
| 3022 | - ? '<p class="ee-search-results">' . sprintf( |
|
| 3022 | + ? '<p class="ee-search-results">'.sprintf( |
|
| 3023 | 3023 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
| 3024 | 3024 | trim($this->_req_data['s'], '%') |
| 3025 | - ) . '</p>' |
|
| 3025 | + ).'</p>' |
|
| 3026 | 3026 | : ''; |
| 3027 | 3027 | // filter before_list_table template arg |
| 3028 | 3028 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -3104,15 +3104,15 @@ discard block |
||
| 3104 | 3104 | ); |
| 3105 | 3105 | /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */ |
| 3106 | 3106 | $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice'); |
| 3107 | - if (! $status_change_notice->isDismissed()) { |
|
| 3107 | + if ( ! $status_change_notice->isDismissed()) { |
|
| 3108 | 3108 | $this->_template_args['status_change_notice'] = EEH_Template::display_template( |
| 3109 | - EE_ADMIN_TEMPLATE . 'status_change_notice.template.php', |
|
| 3110 | - [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ], |
|
| 3109 | + EE_ADMIN_TEMPLATE.'status_change_notice.template.php', |
|
| 3110 | + ['context' => '__admin-legend', 'page_slug' => $this->page_slug], |
|
| 3111 | 3111 | true |
| 3112 | 3112 | ); |
| 3113 | 3113 | } |
| 3114 | 3114 | return EEH_Template::display_template( |
| 3115 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
| 3115 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
| 3116 | 3116 | $this->_template_args, |
| 3117 | 3117 | true |
| 3118 | 3118 | ); |
@@ -3342,17 +3342,17 @@ discard block |
||
| 3342 | 3342 | // add in a hidden index for the current page (so save and close redirects properly) |
| 3343 | 3343 | $this->_template_args['save_buttons'] = $referrer_url; |
| 3344 | 3344 | foreach ($button_text as $key => $button) { |
| 3345 | - $ref = $default_names[ $key ]; |
|
| 3345 | + $ref = $default_names[$key]; |
|
| 3346 | 3346 | $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
| 3347 | 3347 | . $ref |
| 3348 | 3348 | . '" value="' |
| 3349 | 3349 | . $button |
| 3350 | 3350 | . '" name="' |
| 3351 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
| 3351 | + . ( ! empty($actions) ? $actions[$key] : $ref) |
|
| 3352 | 3352 | . '" id="' |
| 3353 | - . $this->_current_view . '_' . $ref |
|
| 3353 | + . $this->_current_view.'_'.$ref |
|
| 3354 | 3354 | . '" />'; |
| 3355 | - if (! $both) { |
|
| 3355 | + if ( ! $both) { |
|
| 3356 | 3356 | break; |
| 3357 | 3357 | } |
| 3358 | 3358 | } |
@@ -3387,13 +3387,13 @@ discard block |
||
| 3387 | 3387 | 'An error occurred. No action was set for this page\'s form.', |
| 3388 | 3388 | 'event_espresso' |
| 3389 | 3389 | ); |
| 3390 | - $dev_msg = $user_msg . "\n" |
|
| 3390 | + $dev_msg = $user_msg."\n" |
|
| 3391 | 3391 | . sprintf( |
| 3392 | 3392 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
| 3393 | 3393 | __FUNCTION__, |
| 3394 | 3394 | EE_Admin_Page::class |
| 3395 | 3395 | ); |
| 3396 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3396 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 3397 | 3397 | } |
| 3398 | 3398 | // open form |
| 3399 | 3399 | $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
@@ -3402,8 +3402,8 @@ discard block |
||
| 3402 | 3402 | . $route |
| 3403 | 3403 | . '_event_form" >'; |
| 3404 | 3404 | // add nonce |
| 3405 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
| 3406 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
| 3405 | + $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
| 3406 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
| 3407 | 3407 | // add REQUIRED form action |
| 3408 | 3408 | $hidden_fields = array( |
| 3409 | 3409 | 'action' => array('type' => 'hidden', 'value' => $route), |
@@ -3416,7 +3416,7 @@ discard block |
||
| 3416 | 3416 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
| 3417 | 3417 | // add fields to form |
| 3418 | 3418 | foreach ((array) $form_fields as $field_name => $form_field) { |
| 3419 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
| 3419 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
| 3420 | 3420 | } |
| 3421 | 3421 | // close form |
| 3422 | 3422 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3470,12 +3470,12 @@ discard block |
||
| 3470 | 3470 | foreach ($this->_req_data as $ref => $value) { |
| 3471 | 3471 | // unset nonces |
| 3472 | 3472 | if (strpos($ref, 'nonce') !== false) { |
| 3473 | - unset($this->_req_data[ $ref ]); |
|
| 3473 | + unset($this->_req_data[$ref]); |
|
| 3474 | 3474 | continue; |
| 3475 | 3475 | } |
| 3476 | 3476 | // urlencode values. |
| 3477 | 3477 | $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
| 3478 | - $this->_req_data[ $ref ] = $value; |
|
| 3478 | + $this->_req_data[$ref] = $value; |
|
| 3479 | 3479 | } |
| 3480 | 3480 | return array_merge($this->_req_data, $new_route_data); |
| 3481 | 3481 | } |
@@ -3513,10 +3513,10 @@ discard block |
||
| 3513 | 3513 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
| 3514 | 3514 | $notices = EE_Error::get_notices(false); |
| 3515 | 3515 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
| 3516 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3516 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
| 3517 | 3517 | EE_Error::overwrite_success(); |
| 3518 | 3518 | } |
| 3519 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3519 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
| 3520 | 3520 | // how many records affected ? more than one record ? or just one ? |
| 3521 | 3521 | if ($success > 1) { |
| 3522 | 3522 | // set plural msg |
@@ -3545,7 +3545,7 @@ discard block |
||
| 3545 | 3545 | } |
| 3546 | 3546 | } |
| 3547 | 3547 | // check that $query_args isn't something crazy |
| 3548 | - if (! is_array($query_args)) { |
|
| 3548 | + if ( ! is_array($query_args)) { |
|
| 3549 | 3549 | $query_args = array(); |
| 3550 | 3550 | } |
| 3551 | 3551 | /** |
@@ -3570,7 +3570,7 @@ discard block |
||
| 3570 | 3570 | $redirect_url = admin_url('admin.php'); |
| 3571 | 3571 | } |
| 3572 | 3572 | // merge any default query_args set in _default_route_query_args property |
| 3573 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3573 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
| 3574 | 3574 | $args_to_merge = array(); |
| 3575 | 3575 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
| 3576 | 3576 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3582,15 +3582,15 @@ discard block |
||
| 3582 | 3582 | } |
| 3583 | 3583 | // finally we will override any arguments in the referer with |
| 3584 | 3584 | // what might be set on the _default_route_query_args array. |
| 3585 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
| 3586 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
| 3585 | + if (isset($this->_default_route_query_args[$reference])) { |
|
| 3586 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
| 3587 | 3587 | } else { |
| 3588 | - $args_to_merge[ $reference ] = urlencode($value); |
|
| 3588 | + $args_to_merge[$reference] = urlencode($value); |
|
| 3589 | 3589 | } |
| 3590 | 3590 | } |
| 3591 | 3591 | continue; |
| 3592 | 3592 | } |
| 3593 | - $args_to_merge[ $query_param ] = $query_value; |
|
| 3593 | + $args_to_merge[$query_param] = $query_value; |
|
| 3594 | 3594 | } |
| 3595 | 3595 | // now let's merge these arguments but override with what was specifically sent in to the |
| 3596 | 3596 | // redirect. |
@@ -3602,13 +3602,13 @@ discard block |
||
| 3602 | 3602 | if (isset($query_args['action'])) { |
| 3603 | 3603 | // manually generate wp_nonce and merge that with the query vars |
| 3604 | 3604 | // becuz the wp_nonce_url function wrecks havoc on some vars |
| 3605 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
| 3605 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
| 3606 | 3606 | } |
| 3607 | 3607 | // we're adding some hooks and filters in here for processing any things just before redirects |
| 3608 | 3608 | // (example: an admin page has done an insert or update and we want to run something after that). |
| 3609 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
| 3609 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
| 3610 | 3610 | $redirect_url = apply_filters( |
| 3611 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
| 3611 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
| 3612 | 3612 | EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url), |
| 3613 | 3613 | $query_args |
| 3614 | 3614 | ); |
@@ -3664,7 +3664,7 @@ discard block |
||
| 3664 | 3664 | } |
| 3665 | 3665 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 3666 | 3666 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
| 3667 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3667 | + if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
| 3668 | 3668 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
| 3669 | 3669 | $this->_add_transient( |
| 3670 | 3670 | $route, |
@@ -3704,7 +3704,7 @@ discard block |
||
| 3704 | 3704 | $exclude_nonce = false |
| 3705 | 3705 | ) { |
| 3706 | 3706 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
| 3707 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
| 3707 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
| 3708 | 3708 | throw new EE_Error( |
| 3709 | 3709 | sprintf( |
| 3710 | 3710 | esc_html__( |
@@ -3715,7 +3715,7 @@ discard block |
||
| 3715 | 3715 | ) |
| 3716 | 3716 | ); |
| 3717 | 3717 | } |
| 3718 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
| 3718 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
| 3719 | 3719 | throw new EE_Error( |
| 3720 | 3720 | sprintf( |
| 3721 | 3721 | __( |
@@ -3728,7 +3728,7 @@ discard block |
||
| 3728 | 3728 | } |
| 3729 | 3729 | // finally check user access for this button. |
| 3730 | 3730 | $has_access = $this->check_user_access($action, true); |
| 3731 | - if (! $has_access) { |
|
| 3731 | + if ( ! $has_access) { |
|
| 3732 | 3732 | return ''; |
| 3733 | 3733 | } |
| 3734 | 3734 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3736,11 +3736,11 @@ discard block |
||
| 3736 | 3736 | 'action' => $action, |
| 3737 | 3737 | ); |
| 3738 | 3738 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
| 3739 | - if (! empty($extra_request)) { |
|
| 3739 | + if ( ! empty($extra_request)) { |
|
| 3740 | 3740 | $query_args = array_merge($extra_request, $query_args); |
| 3741 | 3741 | } |
| 3742 | 3742 | $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
| 3743 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
| 3743 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
| 3744 | 3744 | } |
| 3745 | 3745 | |
| 3746 | 3746 | |
@@ -3766,7 +3766,7 @@ discard block |
||
| 3766 | 3766 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
| 3767 | 3767 | 20 |
| 3768 | 3768 | ), |
| 3769 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
| 3769 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
| 3770 | 3770 | ); |
| 3771 | 3771 | // ONLY add the screen option if the user has access to it. |
| 3772 | 3772 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3787,7 +3787,7 @@ discard block |
||
| 3787 | 3787 | { |
| 3788 | 3788 | if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
| 3789 | 3789 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
| 3790 | - if (! $user = wp_get_current_user()) { |
|
| 3790 | + if ( ! $user = wp_get_current_user()) { |
|
| 3791 | 3791 | return; |
| 3792 | 3792 | } |
| 3793 | 3793 | $option = $_POST['wp_screen_options']['option']; |
@@ -3798,7 +3798,7 @@ discard block |
||
| 3798 | 3798 | $map_option = $option; |
| 3799 | 3799 | $option = str_replace('-', '_', $option); |
| 3800 | 3800 | switch ($map_option) { |
| 3801 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
| 3801 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
| 3802 | 3802 | $value = (int) $value; |
| 3803 | 3803 | $max_value = apply_filters( |
| 3804 | 3804 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
@@ -3856,13 +3856,13 @@ discard block |
||
| 3856 | 3856 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
| 3857 | 3857 | { |
| 3858 | 3858 | $user_id = get_current_user_id(); |
| 3859 | - if (! $skip_route_verify) { |
|
| 3859 | + if ( ! $skip_route_verify) { |
|
| 3860 | 3860 | $this->_verify_route($route); |
| 3861 | 3861 | } |
| 3862 | 3862 | // now let's set the string for what kind of transient we're setting |
| 3863 | 3863 | $transient = $notices |
| 3864 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3865 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3864 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3865 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3866 | 3866 | $data = $notices ? array('notices' => $data) : $data; |
| 3867 | 3867 | // is there already a transient for this route? If there is then let's ADD to that transient |
| 3868 | 3868 | $existing = is_multisite() && is_network_admin() |
@@ -3891,8 +3891,8 @@ discard block |
||
| 3891 | 3891 | $user_id = get_current_user_id(); |
| 3892 | 3892 | $route = ! $route ? $this->_req_action : $route; |
| 3893 | 3893 | $transient = $notices |
| 3894 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
| 3895 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
| 3894 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
| 3895 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
| 3896 | 3896 | $data = is_multisite() && is_network_admin() |
| 3897 | 3897 | ? get_site_transient($transient) |
| 3898 | 3898 | : get_transient($transient); |
@@ -4116,7 +4116,7 @@ discard block |
||
| 4116 | 4116 | */ |
| 4117 | 4117 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
| 4118 | 4118 | { |
| 4119 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4119 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4120 | 4120 | } |
| 4121 | 4121 | |
| 4122 | 4122 | |
@@ -4129,7 +4129,7 @@ discard block |
||
| 4129 | 4129 | */ |
| 4130 | 4130 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
| 4131 | 4131 | { |
| 4132 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
| 4132 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
| 4133 | 4133 | } |
| 4134 | 4134 | |
| 4135 | 4135 | |
@@ -14,73 +14,73 @@ |
||
| 14 | 14 | class FeatureFlags |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var CapabilitiesChecker $capabilities_checker |
|
| 19 | - */ |
|
| 20 | - private $capabilities_checker; |
|
| 17 | + /** |
|
| 18 | + * @var CapabilitiesChecker $capabilities_checker |
|
| 19 | + */ |
|
| 20 | + private $capabilities_checker; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * array of key value pairs where the key is the feature flag in question |
|
| 24 | - * and the value is either a boolean or a CapCheck object defining the required permissions |
|
| 25 | - * example: |
|
| 26 | - * [ |
|
| 27 | - * 'use_bulk_edit' => true, |
|
| 28 | - * 'use_death_ray' => new CapCheck( 'ee-death-ray-cap', 'context-desc' ) |
|
| 29 | - * ] |
|
| 30 | - * array is filterable via FHEE__EventEspresso_core_domain_services_capabilities_FeatureFlags |
|
| 31 | - * |
|
| 32 | - * @var boolean[]|CapCheck[] |
|
| 33 | - */ |
|
| 34 | - private $feature_flags; |
|
| 22 | + /** |
|
| 23 | + * array of key value pairs where the key is the feature flag in question |
|
| 24 | + * and the value is either a boolean or a CapCheck object defining the required permissions |
|
| 25 | + * example: |
|
| 26 | + * [ |
|
| 27 | + * 'use_bulk_edit' => true, |
|
| 28 | + * 'use_death_ray' => new CapCheck( 'ee-death-ray-cap', 'context-desc' ) |
|
| 29 | + * ] |
|
| 30 | + * array is filterable via FHEE__EventEspresso_core_domain_services_capabilities_FeatureFlags |
|
| 31 | + * |
|
| 32 | + * @var boolean[]|CapCheck[] |
|
| 33 | + */ |
|
| 34 | + private $feature_flags; |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * FeatureFlags constructor. |
|
| 39 | - * |
|
| 40 | - * @param CapabilitiesChecker $capabilities_checker |
|
| 41 | - */ |
|
| 42 | - public function __construct(CapabilitiesChecker $capabilities_checker) |
|
| 43 | - { |
|
| 44 | - $this->capabilities_checker = $capabilities_checker; |
|
| 45 | - $this->feature_flags = apply_filters( |
|
| 46 | - 'FHEE__EventEspresso_core_domain_services_capabilities_FeatureFlags', |
|
| 47 | - [ |
|
| 48 | - 'use_advanced_event_editor' => false, |
|
| 49 | - 'use_bulk_edit' => false, |
|
| 50 | - 'use_default_ticket_manager' => false, |
|
| 51 | - 'use_event_description_rte' => false, |
|
| 52 | - 'use_experimental_rte' => false, |
|
| 53 | - 'use_reg_form_builder' => false, |
|
| 54 | - 'use_reg_options_meta_box' => false, |
|
| 55 | - ] |
|
| 56 | - ); |
|
| 57 | - } |
|
| 37 | + /** |
|
| 38 | + * FeatureFlags constructor. |
|
| 39 | + * |
|
| 40 | + * @param CapabilitiesChecker $capabilities_checker |
|
| 41 | + */ |
|
| 42 | + public function __construct(CapabilitiesChecker $capabilities_checker) |
|
| 43 | + { |
|
| 44 | + $this->capabilities_checker = $capabilities_checker; |
|
| 45 | + $this->feature_flags = apply_filters( |
|
| 46 | + 'FHEE__EventEspresso_core_domain_services_capabilities_FeatureFlags', |
|
| 47 | + [ |
|
| 48 | + 'use_advanced_event_editor' => false, |
|
| 49 | + 'use_bulk_edit' => false, |
|
| 50 | + 'use_default_ticket_manager' => false, |
|
| 51 | + 'use_event_description_rte' => false, |
|
| 52 | + 'use_experimental_rte' => false, |
|
| 53 | + 'use_reg_form_builder' => false, |
|
| 54 | + 'use_reg_options_meta_box' => false, |
|
| 55 | + ] |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param string $feature |
|
| 62 | - * @return bool |
|
| 63 | - */ |
|
| 64 | - public function allowed(string $feature): bool |
|
| 65 | - { |
|
| 66 | - $flag = $this->feature_flags[ $feature ] ?? false; |
|
| 67 | - try { |
|
| 68 | - return $flag instanceof CapCheck |
|
| 69 | - ? $this->capabilities_checker->processCapCheck($flag) |
|
| 70 | - : filter_var($flag, FILTER_VALIDATE_BOOLEAN); |
|
| 71 | - } catch (InsufficientPermissionsException $e) { |
|
| 72 | - // eat the exception |
|
| 73 | - } |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 60 | + /** |
|
| 61 | + * @param string $feature |
|
| 62 | + * @return bool |
|
| 63 | + */ |
|
| 64 | + public function allowed(string $feature): bool |
|
| 65 | + { |
|
| 66 | + $flag = $this->feature_flags[ $feature ] ?? false; |
|
| 67 | + try { |
|
| 68 | + return $flag instanceof CapCheck |
|
| 69 | + ? $this->capabilities_checker->processCapCheck($flag) |
|
| 70 | + : filter_var($flag, FILTER_VALIDATE_BOOLEAN); |
|
| 71 | + } catch (InsufficientPermissionsException $e) { |
|
| 72 | + // eat the exception |
|
| 73 | + } |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function getAllowedFeatures(): array |
|
| 82 | - { |
|
| 83 | - $allowed = array_filter($this->feature_flags, [$this, 'allowed'], ARRAY_FILTER_USE_KEY); |
|
| 84 | - return array_keys($allowed); |
|
| 85 | - } |
|
| 78 | + /** |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function getAllowedFeatures(): array |
|
| 82 | + { |
|
| 83 | + $allowed = array_filter($this->feature_flags, [$this, 'allowed'], ARRAY_FILTER_USE_KEY); |
|
| 84 | + return array_keys($allowed); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | */ |
| 64 | 64 | public function allowed(string $feature): bool |
| 65 | 65 | { |
| 66 | - $flag = $this->feature_flags[ $feature ] ?? false; |
|
| 66 | + $flag = $this->feature_flags[$feature] ?? false; |
|
| 67 | 67 | try { |
| 68 | 68 | return $flag instanceof CapCheck |
| 69 | 69 | ? $this->capabilities_checker->processCapCheck($flag) |
@@ -16,47 +16,47 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * returns true if the current request matches this route |
|
| 21 | - * child classes can override and use Request directly to match route with request |
|
| 22 | - * or supply a RouteMatchSpecification class and just use the below |
|
| 23 | - * |
|
| 24 | - * @return bool |
|
| 25 | - * @since $VID:$ |
|
| 26 | - */ |
|
| 27 | - public function matchesCurrentRequest(): bool |
|
| 28 | - { |
|
| 29 | - return ($this->request->isFrontend() || $this->request->isFrontAjax() || $this->request->isIframe()) |
|
| 30 | - && ! $this->maintenance_mode->level(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @since $VID:$ |
|
| 36 | - */ |
|
| 37 | - protected function registerDependencies() |
|
| 38 | - { |
|
| 39 | - $this->dependency_map->registerDependencies( |
|
| 40 | - 'EE_Front_Controller', |
|
| 41 | - [ |
|
| 42 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 43 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 44 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 45 | - ] |
|
| 46 | - ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * implements logic required to run during request |
|
| 52 | - * |
|
| 53 | - * @return bool |
|
| 54 | - * @since $VID:$ |
|
| 55 | - */ |
|
| 56 | - protected function requestHandler(): bool |
|
| 57 | - { |
|
| 58 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 59 | - $this->loader->getShared('EE_Front_Controller'); |
|
| 60 | - return true; |
|
| 61 | - } |
|
| 19 | + /** |
|
| 20 | + * returns true if the current request matches this route |
|
| 21 | + * child classes can override and use Request directly to match route with request |
|
| 22 | + * or supply a RouteMatchSpecification class and just use the below |
|
| 23 | + * |
|
| 24 | + * @return bool |
|
| 25 | + * @since $VID:$ |
|
| 26 | + */ |
|
| 27 | + public function matchesCurrentRequest(): bool |
|
| 28 | + { |
|
| 29 | + return ($this->request->isFrontend() || $this->request->isFrontAjax() || $this->request->isIframe()) |
|
| 30 | + && ! $this->maintenance_mode->level(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @since $VID:$ |
|
| 36 | + */ |
|
| 37 | + protected function registerDependencies() |
|
| 38 | + { |
|
| 39 | + $this->dependency_map->registerDependencies( |
|
| 40 | + 'EE_Front_Controller', |
|
| 41 | + [ |
|
| 42 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 43 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 44 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 45 | + ] |
|
| 46 | + ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * implements logic required to run during request |
|
| 52 | + * |
|
| 53 | + * @return bool |
|
| 54 | + * @since $VID:$ |
|
| 55 | + */ |
|
| 56 | + protected function requestHandler(): bool |
|
| 57 | + { |
|
| 58 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 59 | + $this->loader->getShared('EE_Front_Controller'); |
|
| 60 | + return true; |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -16,1486 +16,1486 @@ |
||
| 16 | 16 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * cached value for the the logical active status for the event |
|
| 21 | - * |
|
| 22 | - * @see get_active_status() |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $_active_status = ''; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 29 | - * |
|
| 30 | - * @var EE_Datetime |
|
| 31 | - */ |
|
| 32 | - protected $_Primary_Datetime; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
| 36 | - */ |
|
| 37 | - protected $available_spaces_calculator; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param array $props_n_values incoming values |
|
| 42 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 43 | - * used.) |
|
| 44 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 45 | - * date_format and the second value is the time format |
|
| 46 | - * @return EE_Event |
|
| 47 | - * @throws EE_Error |
|
| 48 | - */ |
|
| 49 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 50 | - { |
|
| 51 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 52 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param array $props_n_values incoming values from the database |
|
| 58 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 59 | - * the website will be used. |
|
| 60 | - * @return EE_Event |
|
| 61 | - * @throws EE_Error |
|
| 62 | - */ |
|
| 63 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 64 | - { |
|
| 65 | - return new self($props_n_values, true, $timezone); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return EventSpacesCalculator |
|
| 71 | - * @throws \EE_Error |
|
| 72 | - */ |
|
| 73 | - public function getAvailableSpacesCalculator() |
|
| 74 | - { |
|
| 75 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 76 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 77 | - } |
|
| 78 | - return $this->available_spaces_calculator; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 84 | - * |
|
| 85 | - * @param string $field_name |
|
| 86 | - * @param mixed $field_value |
|
| 87 | - * @param bool $use_default |
|
| 88 | - * @throws EE_Error |
|
| 89 | - */ |
|
| 90 | - public function set($field_name, $field_value, $use_default = false) |
|
| 91 | - { |
|
| 92 | - switch ($field_name) { |
|
| 93 | - case 'status': |
|
| 94 | - $this->set_status($field_value, $use_default); |
|
| 95 | - break; |
|
| 96 | - default: |
|
| 97 | - parent::set($field_name, $field_value, $use_default); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * set_status |
|
| 104 | - * Checks if event status is being changed to SOLD OUT |
|
| 105 | - * and updates event meta data with previous event status |
|
| 106 | - * so that we can revert things if/when the event is no longer sold out |
|
| 107 | - * |
|
| 108 | - * @access public |
|
| 109 | - * @param string $new_status |
|
| 110 | - * @param bool $use_default |
|
| 111 | - * @return void |
|
| 112 | - * @throws EE_Error |
|
| 113 | - */ |
|
| 114 | - public function set_status($new_status = null, $use_default = false) |
|
| 115 | - { |
|
| 116 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 117 | - if (empty($new_status) && ! $use_default) { |
|
| 118 | - return; |
|
| 119 | - } |
|
| 120 | - // get current Event status |
|
| 121 | - $old_status = $this->status(); |
|
| 122 | - // if status has changed |
|
| 123 | - if ($old_status !== $new_status) { |
|
| 124 | - // TO sold_out |
|
| 125 | - if ($new_status === EEM_Event::sold_out) { |
|
| 126 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
| 127 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
| 128 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 129 | - // OR FROM sold_out |
|
| 130 | - } elseif ($old_status === EEM_Event::sold_out) { |
|
| 131 | - $this->delete_post_meta('_previous_event_status'); |
|
| 132 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 133 | - } |
|
| 134 | - // clear out the active status so that it gets reset the next time it is requested |
|
| 135 | - $this->_active_status = null; |
|
| 136 | - // update status |
|
| 137 | - parent::set('status', $new_status, $use_default); |
|
| 138 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 139 | - return; |
|
| 140 | - } |
|
| 141 | - // even though the old value matches the new value, it's still good to |
|
| 142 | - // allow the parent set method to have a say |
|
| 143 | - parent::set('status', $new_status, $use_default); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Gets all the datetimes for this event |
|
| 149 | - * |
|
| 150 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 151 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 152 | - * @throws EE_Error |
|
| 153 | - */ |
|
| 154 | - public function datetimes($query_params = array()) |
|
| 155 | - { |
|
| 156 | - return $this->get_many_related('Datetime', $query_params); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 162 | - * |
|
| 163 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 164 | - * @throws EE_Error |
|
| 165 | - */ |
|
| 166 | - public function datetimes_in_chronological_order() |
|
| 167 | - { |
|
| 168 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 174 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 175 | - * after running our query, so that this timezone isn't set for EVERY query |
|
| 176 | - * on EEM_Datetime for the rest of the request, no? |
|
| 177 | - * |
|
| 178 | - * @param boolean $show_expired whether or not to include expired events |
|
| 179 | - * @param boolean $show_deleted whether or not to include deleted events |
|
| 180 | - * @param null $limit |
|
| 181 | - * @return EE_Datetime[] |
|
| 182 | - * @throws EE_Error |
|
| 183 | - */ |
|
| 184 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 185 | - { |
|
| 186 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 187 | - $this->ID(), |
|
| 188 | - $show_expired, |
|
| 189 | - $show_deleted, |
|
| 190 | - $limit |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
| 197 | - * |
|
| 198 | - * @return EE_Base_Class|EE_Datetime |
|
| 199 | - * @throws EE_Error |
|
| 200 | - */ |
|
| 201 | - public function first_datetime() |
|
| 202 | - { |
|
| 203 | - return $this->get_first_related('Datetime'); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Returns the 'primary' datetime for the event |
|
| 209 | - * |
|
| 210 | - * @param bool $try_to_exclude_expired |
|
| 211 | - * @param bool $try_to_exclude_deleted |
|
| 212 | - * @return EE_Datetime |
|
| 213 | - * @throws EE_Error |
|
| 214 | - */ |
|
| 215 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 216 | - { |
|
| 217 | - if (! empty($this->_Primary_Datetime)) { |
|
| 218 | - return $this->_Primary_Datetime; |
|
| 219 | - } |
|
| 220 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 221 | - $this->ID(), |
|
| 222 | - $try_to_exclude_expired, |
|
| 223 | - $try_to_exclude_deleted |
|
| 224 | - ); |
|
| 225 | - return $this->_Primary_Datetime; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Gets all the tickets available for purchase of this event |
|
| 231 | - * |
|
| 232 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 233 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 234 | - * @throws EE_Error |
|
| 235 | - */ |
|
| 236 | - public function tickets($query_params = array()) |
|
| 237 | - { |
|
| 238 | - // first get all datetimes |
|
| 239 | - $datetimes = $this->datetimes_ordered(); |
|
| 240 | - if (! $datetimes) { |
|
| 241 | - return array(); |
|
| 242 | - } |
|
| 243 | - $datetime_ids = array(); |
|
| 244 | - foreach ($datetimes as $datetime) { |
|
| 245 | - $datetime_ids[] = $datetime->ID(); |
|
| 246 | - } |
|
| 247 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 248 | - // if incoming $query_params has where conditions let's merge but not override existing. |
|
| 249 | - if (is_array($query_params) && isset($query_params[0])) { |
|
| 250 | - $where_params = array_merge($query_params[0], $where_params); |
|
| 251 | - unset($query_params[0]); |
|
| 252 | - } |
|
| 253 | - // now add $where_params to $query_params |
|
| 254 | - $query_params[0] = $where_params; |
|
| 255 | - return EEM_Ticket::instance()->get_all($query_params); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * get all unexpired untrashed tickets |
|
| 261 | - * |
|
| 262 | - * @return EE_Ticket[] |
|
| 263 | - * @throws EE_Error |
|
| 264 | - */ |
|
| 265 | - public function active_tickets() |
|
| 266 | - { |
|
| 267 | - return $this->tickets( |
|
| 268 | - array( |
|
| 269 | - array( |
|
| 270 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 271 | - 'TKT_deleted' => false, |
|
| 272 | - ), |
|
| 273 | - ) |
|
| 274 | - ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @return bool |
|
| 280 | - * @throws EE_Error |
|
| 281 | - */ |
|
| 282 | - public function additional_limit() |
|
| 283 | - { |
|
| 284 | - return $this->get('EVT_additional_limit'); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @return bool |
|
| 290 | - * @throws EE_Error |
|
| 291 | - */ |
|
| 292 | - public function allow_overflow() |
|
| 293 | - { |
|
| 294 | - return $this->get('EVT_allow_overflow'); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @return bool |
|
| 300 | - * @throws EE_Error |
|
| 301 | - */ |
|
| 302 | - public function created() |
|
| 303 | - { |
|
| 304 | - return $this->get('EVT_created'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * @return bool |
|
| 310 | - * @throws EE_Error |
|
| 311 | - */ |
|
| 312 | - public function description() |
|
| 313 | - { |
|
| 314 | - return $this->get('EVT_desc'); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Runs do_shortcode and wpautop on the description |
|
| 320 | - * |
|
| 321 | - * @return string of html |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function description_filtered() |
|
| 325 | - { |
|
| 326 | - return $this->get_pretty('EVT_desc'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @return bool |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - public function display_description() |
|
| 335 | - { |
|
| 336 | - return $this->get('EVT_display_desc'); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * @return bool |
|
| 342 | - * @throws EE_Error |
|
| 343 | - */ |
|
| 344 | - public function display_ticket_selector() |
|
| 345 | - { |
|
| 346 | - return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @return bool |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - public function external_url() |
|
| 355 | - { |
|
| 356 | - return $this->get('EVT_external_URL'); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @return bool |
|
| 362 | - * @throws EE_Error |
|
| 363 | - */ |
|
| 364 | - public function member_only() |
|
| 365 | - { |
|
| 366 | - return $this->get('EVT_member_only'); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * @return bool |
|
| 372 | - * @throws EE_Error |
|
| 373 | - */ |
|
| 374 | - public function phone() |
|
| 375 | - { |
|
| 376 | - return $this->get('EVT_phone'); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @return bool |
|
| 382 | - * @throws EE_Error |
|
| 383 | - */ |
|
| 384 | - public function modified() |
|
| 385 | - { |
|
| 386 | - return $this->get('EVT_modified'); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * @return bool |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function name() |
|
| 395 | - { |
|
| 396 | - return $this->get('EVT_name'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @return bool |
|
| 402 | - * @throws EE_Error |
|
| 403 | - */ |
|
| 404 | - public function order() |
|
| 405 | - { |
|
| 406 | - return $this->get('EVT_order'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * @return bool|string |
|
| 412 | - * @throws EE_Error |
|
| 413 | - */ |
|
| 414 | - public function default_registration_status() |
|
| 415 | - { |
|
| 416 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 417 | - return ! empty($event_default_registration_status) |
|
| 418 | - ? $event_default_registration_status |
|
| 419 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @param int $num_words |
|
| 425 | - * @param null $more |
|
| 426 | - * @param bool $not_full_desc |
|
| 427 | - * @return bool|string |
|
| 428 | - * @throws EE_Error |
|
| 429 | - */ |
|
| 430 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 431 | - { |
|
| 432 | - $short_desc = $this->get('EVT_short_desc'); |
|
| 433 | - if (! empty($short_desc) || $not_full_desc) { |
|
| 434 | - return $short_desc; |
|
| 435 | - } |
|
| 436 | - $full_desc = $this->get('EVT_desc'); |
|
| 437 | - return wp_trim_words($full_desc, $num_words, $more); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @return bool |
|
| 443 | - * @throws EE_Error |
|
| 444 | - */ |
|
| 445 | - public function slug() |
|
| 446 | - { |
|
| 447 | - return $this->get('EVT_slug'); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @return bool |
|
| 453 | - * @throws EE_Error |
|
| 454 | - */ |
|
| 455 | - public function timezone_string() |
|
| 456 | - { |
|
| 457 | - return $this->get('EVT_timezone_string'); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * @return bool |
|
| 463 | - * @throws EE_Error |
|
| 464 | - */ |
|
| 465 | - public function visible_on() |
|
| 466 | - { |
|
| 467 | - return $this->get('EVT_visible_on'); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @return int |
|
| 473 | - * @throws EE_Error |
|
| 474 | - */ |
|
| 475 | - public function wp_user() |
|
| 476 | - { |
|
| 477 | - return $this->get('EVT_wp_user'); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @return bool |
|
| 483 | - * @throws EE_Error |
|
| 484 | - */ |
|
| 485 | - public function donations() |
|
| 486 | - { |
|
| 487 | - return $this->get('EVT_donations'); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @param $limit |
|
| 493 | - * @throws EE_Error |
|
| 494 | - */ |
|
| 495 | - public function set_additional_limit($limit) |
|
| 496 | - { |
|
| 497 | - $this->set('EVT_additional_limit', $limit); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param $created |
|
| 503 | - * @throws EE_Error |
|
| 504 | - */ |
|
| 505 | - public function set_created($created) |
|
| 506 | - { |
|
| 507 | - $this->set('EVT_created', $created); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * @param $desc |
|
| 513 | - * @throws EE_Error |
|
| 514 | - */ |
|
| 515 | - public function set_description($desc) |
|
| 516 | - { |
|
| 517 | - $this->set('EVT_desc', $desc); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @param $display_desc |
|
| 523 | - * @throws EE_Error |
|
| 524 | - */ |
|
| 525 | - public function set_display_description($display_desc) |
|
| 526 | - { |
|
| 527 | - $this->set('EVT_display_desc', $display_desc); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * @param $display_ticket_selector |
|
| 533 | - * @throws EE_Error |
|
| 534 | - */ |
|
| 535 | - public function set_display_ticket_selector($display_ticket_selector) |
|
| 536 | - { |
|
| 537 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * @param $external_url |
|
| 543 | - * @throws EE_Error |
|
| 544 | - */ |
|
| 545 | - public function set_external_url($external_url) |
|
| 546 | - { |
|
| 547 | - $this->set('EVT_external_URL', $external_url); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * @param $member_only |
|
| 553 | - * @throws EE_Error |
|
| 554 | - */ |
|
| 555 | - public function set_member_only($member_only) |
|
| 556 | - { |
|
| 557 | - $this->set('EVT_member_only', $member_only); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @param $event_phone |
|
| 563 | - * @throws EE_Error |
|
| 564 | - */ |
|
| 565 | - public function set_event_phone($event_phone) |
|
| 566 | - { |
|
| 567 | - $this->set('EVT_phone', $event_phone); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * @param $modified |
|
| 573 | - * @throws EE_Error |
|
| 574 | - */ |
|
| 575 | - public function set_modified($modified) |
|
| 576 | - { |
|
| 577 | - $this->set('EVT_modified', $modified); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * @param $name |
|
| 583 | - * @throws EE_Error |
|
| 584 | - */ |
|
| 585 | - public function set_name($name) |
|
| 586 | - { |
|
| 587 | - $this->set('EVT_name', $name); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * @param $order |
|
| 593 | - * @throws EE_Error |
|
| 594 | - */ |
|
| 595 | - public function set_order($order) |
|
| 596 | - { |
|
| 597 | - $this->set('EVT_order', $order); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * @param $short_desc |
|
| 603 | - * @throws EE_Error |
|
| 604 | - */ |
|
| 605 | - public function set_short_description($short_desc) |
|
| 606 | - { |
|
| 607 | - $this->set('EVT_short_desc', $short_desc); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * @param $slug |
|
| 613 | - * @throws EE_Error |
|
| 614 | - */ |
|
| 615 | - public function set_slug($slug) |
|
| 616 | - { |
|
| 617 | - $this->set('EVT_slug', $slug); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @param $timezone_string |
|
| 623 | - * @throws EE_Error |
|
| 624 | - */ |
|
| 625 | - public function set_timezone_string($timezone_string) |
|
| 626 | - { |
|
| 627 | - $this->set('EVT_timezone_string', $timezone_string); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * @param $visible_on |
|
| 633 | - * @throws EE_Error |
|
| 634 | - */ |
|
| 635 | - public function set_visible_on($visible_on) |
|
| 636 | - { |
|
| 637 | - $this->set('EVT_visible_on', $visible_on); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * @param $wp_user |
|
| 643 | - * @throws EE_Error |
|
| 644 | - */ |
|
| 645 | - public function set_wp_user($wp_user) |
|
| 646 | - { |
|
| 647 | - $this->set('EVT_wp_user', $wp_user); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * @param $default_registration_status |
|
| 653 | - * @throws EE_Error |
|
| 654 | - */ |
|
| 655 | - public function set_default_registration_status($default_registration_status) |
|
| 656 | - { |
|
| 657 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param $donations |
|
| 663 | - * @throws EE_Error |
|
| 664 | - */ |
|
| 665 | - public function set_donations($donations) |
|
| 666 | - { |
|
| 667 | - $this->set('EVT_donations', $donations); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Adds a venue to this event |
|
| 673 | - * |
|
| 674 | - * @param int|EE_Venue /int $venue_id_or_obj |
|
| 675 | - * @return EE_Base_Class|EE_Venue |
|
| 676 | - * @throws EE_Error |
|
| 677 | - * @throws ReflectionException |
|
| 678 | - */ |
|
| 679 | - public function add_venue($venue_id_or_obj): EE_Venue |
|
| 680 | - { |
|
| 681 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Removes a venue from the event |
|
| 687 | - * |
|
| 688 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 689 | - * @return EE_Base_Class|EE_Venue |
|
| 690 | - * @throws EE_Error |
|
| 691 | - * @throws ReflectionException |
|
| 692 | - */ |
|
| 693 | - public function remove_venue($venue_id_or_obj): EE_Venue |
|
| 694 | - { |
|
| 695 | - $venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue(); |
|
| 696 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Gets the venue related to the event. May provide additional $query_params if desired |
|
| 702 | - * |
|
| 703 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 704 | - * @return int |
|
| 705 | - * @throws EE_Error |
|
| 706 | - * @throws ReflectionException |
|
| 707 | - */ |
|
| 708 | - public function venue_ID(array $query_params = array()): int |
|
| 709 | - { |
|
| 710 | - $venue = $this->get_first_related('Venue', $query_params); |
|
| 711 | - return $venue instanceof EE_Venue ? $venue->ID() : 0; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * Gets the venue related to the event. May provide additional $query_params if desired |
|
| 717 | - * |
|
| 718 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 719 | - * @return EE_Base_Class|EE_Venue |
|
| 720 | - * @throws EE_Error |
|
| 721 | - * @throws ReflectionException |
|
| 722 | - */ |
|
| 723 | - public function venue(array $query_params = array()) |
|
| 724 | - { |
|
| 725 | - return $this->get_first_related('Venue', $query_params); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * @param array $query_params |
|
| 731 | - * @return EE_Base_Class[]|EE_Venue[] |
|
| 732 | - * @throws EE_Error |
|
| 733 | - * @throws ReflectionException |
|
| 734 | - * @deprecated $VID:$ |
|
| 735 | - */ |
|
| 736 | - public function venues(array $query_params = array()): array |
|
| 737 | - { |
|
| 738 | - return [$this->venue($query_params)]; |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * check if event id is present and if event is published |
|
| 744 | - * |
|
| 745 | - * @access public |
|
| 746 | - * @return boolean true yes, false no |
|
| 747 | - * @throws EE_Error |
|
| 748 | - */ |
|
| 749 | - private function _has_ID_and_is_published() |
|
| 750 | - { |
|
| 751 | - // first check if event id is present and not NULL, |
|
| 752 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 753 | - return |
|
| 754 | - $this->ID() && $this->ID() !== null |
|
| 755 | - && ( |
|
| 756 | - $this->status() === 'publish' |
|
| 757 | - || $this->status() === EEM_Event::sold_out |
|
| 758 | - || $this->status() === EEM_Event::postponed |
|
| 759 | - || $this->status() === EEM_Event::cancelled |
|
| 760 | - ); |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 766 | - * |
|
| 767 | - * @access public |
|
| 768 | - * @return boolean true yes, false no |
|
| 769 | - * @throws EE_Error |
|
| 770 | - */ |
|
| 771 | - public function is_upcoming() |
|
| 772 | - { |
|
| 773 | - // check if event id is present and if this event is published |
|
| 774 | - if ($this->is_inactive()) { |
|
| 775 | - return false; |
|
| 776 | - } |
|
| 777 | - // set initial value |
|
| 778 | - $upcoming = false; |
|
| 779 | - // next let's get all datetimes and loop through them |
|
| 780 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 781 | - foreach ($datetimes as $datetime) { |
|
| 782 | - if ($datetime instanceof EE_Datetime) { |
|
| 783 | - // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 784 | - if ($datetime->is_expired()) { |
|
| 785 | - continue; |
|
| 786 | - } |
|
| 787 | - // if this dtt is active then we return false. |
|
| 788 | - if ($datetime->is_active()) { |
|
| 789 | - return false; |
|
| 790 | - } |
|
| 791 | - // otherwise let's check upcoming status |
|
| 792 | - $upcoming = $datetime->is_upcoming(); |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - return $upcoming; |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * @return bool |
|
| 801 | - * @throws EE_Error |
|
| 802 | - */ |
|
| 803 | - public function is_active() |
|
| 804 | - { |
|
| 805 | - // check if event id is present and if this event is published |
|
| 806 | - if ($this->is_inactive()) { |
|
| 807 | - return false; |
|
| 808 | - } |
|
| 809 | - // set initial value |
|
| 810 | - $active = false; |
|
| 811 | - // next let's get all datetimes and loop through them |
|
| 812 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 813 | - foreach ($datetimes as $datetime) { |
|
| 814 | - if ($datetime instanceof EE_Datetime) { |
|
| 815 | - // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 816 | - if ($datetime->is_expired()) { |
|
| 817 | - continue; |
|
| 818 | - } |
|
| 819 | - // if this dtt is upcoming then we return false. |
|
| 820 | - if ($datetime->is_upcoming()) { |
|
| 821 | - return false; |
|
| 822 | - } |
|
| 823 | - // otherwise let's check active status |
|
| 824 | - $active = $datetime->is_active(); |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - return $active; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * @return bool |
|
| 833 | - * @throws EE_Error |
|
| 834 | - */ |
|
| 835 | - public function is_expired() |
|
| 836 | - { |
|
| 837 | - // check if event id is present and if this event is published |
|
| 838 | - if ($this->is_inactive()) { |
|
| 839 | - return false; |
|
| 840 | - } |
|
| 841 | - // set initial value |
|
| 842 | - $expired = false; |
|
| 843 | - // first let's get all datetimes and loop through them |
|
| 844 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 845 | - foreach ($datetimes as $datetime) { |
|
| 846 | - if ($datetime instanceof EE_Datetime) { |
|
| 847 | - // if this dtt is upcoming or active then we return false. |
|
| 848 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 849 | - return false; |
|
| 850 | - } |
|
| 851 | - // otherwise let's check active status |
|
| 852 | - $expired = $datetime->is_expired(); |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - return $expired; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * @return bool |
|
| 861 | - * @throws EE_Error |
|
| 862 | - */ |
|
| 863 | - public function is_inactive() |
|
| 864 | - { |
|
| 865 | - // check if event id is present and if this event is published |
|
| 866 | - if ($this->_has_ID_and_is_published()) { |
|
| 867 | - return false; |
|
| 868 | - } |
|
| 869 | - return true; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * calculate spaces remaining based on "saleable" tickets |
|
| 875 | - * |
|
| 876 | - * @param array $tickets |
|
| 877 | - * @param bool $filtered |
|
| 878 | - * @return int|float |
|
| 879 | - * @throws EE_Error |
|
| 880 | - * @throws DomainException |
|
| 881 | - * @throws UnexpectedEntityException |
|
| 882 | - */ |
|
| 883 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 884 | - { |
|
| 885 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 886 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 887 | - return $filtered |
|
| 888 | - ? apply_filters( |
|
| 889 | - 'FHEE_EE_Event__spaces_remaining', |
|
| 890 | - $spaces_remaining, |
|
| 891 | - $this, |
|
| 892 | - $tickets |
|
| 893 | - ) |
|
| 894 | - : $spaces_remaining; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * perform_sold_out_status_check |
|
| 900 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
| 901 | - * available... if NOT, then the event status will get toggled to 'sold_out' |
|
| 902 | - * |
|
| 903 | - * @return bool return the ACTUAL sold out state. |
|
| 904 | - * @throws EE_Error |
|
| 905 | - * @throws DomainException |
|
| 906 | - * @throws UnexpectedEntityException |
|
| 907 | - */ |
|
| 908 | - public function perform_sold_out_status_check() |
|
| 909 | - { |
|
| 910 | - // get all tickets |
|
| 911 | - $tickets = $this->tickets( |
|
| 912 | - array( |
|
| 913 | - 'default_where_conditions' => 'none', |
|
| 914 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 915 | - ) |
|
| 916 | - ); |
|
| 917 | - $all_expired = true; |
|
| 918 | - foreach ($tickets as $ticket) { |
|
| 919 | - if (! $ticket->is_expired()) { |
|
| 920 | - $all_expired = false; |
|
| 921 | - break; |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
| 925 | - if ($all_expired) { |
|
| 926 | - return true; |
|
| 927 | - } |
|
| 928 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 929 | - if ($spaces_remaining < 1) { |
|
| 930 | - if ($this->status() !== EEM_Event::post_status_private) { |
|
| 931 | - $this->set_status(EEM_Event::sold_out); |
|
| 932 | - $this->save(); |
|
| 933 | - } |
|
| 934 | - $sold_out = true; |
|
| 935 | - } else { |
|
| 936 | - $sold_out = false; |
|
| 937 | - // was event previously marked as sold out ? |
|
| 938 | - if ($this->status() === EEM_Event::sold_out) { |
|
| 939 | - // revert status to previous value, if it was set |
|
| 940 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 941 | - if ($previous_event_status) { |
|
| 942 | - $this->set_status($previous_event_status); |
|
| 943 | - $this->save(); |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 948 | - return $sold_out; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * This returns the total remaining spaces for sale on this event. |
|
| 954 | - * |
|
| 955 | - * @uses EE_Event::total_available_spaces() |
|
| 956 | - * @return float|int |
|
| 957 | - * @throws EE_Error |
|
| 958 | - * @throws DomainException |
|
| 959 | - * @throws UnexpectedEntityException |
|
| 960 | - */ |
|
| 961 | - public function spaces_remaining_for_sale() |
|
| 962 | - { |
|
| 963 | - return $this->total_available_spaces(true); |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * This returns the total spaces available for an event |
|
| 969 | - * while considering all the qtys on the tickets and the reg limits |
|
| 970 | - * on the datetimes attached to this event. |
|
| 971 | - * |
|
| 972 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 973 | - * If this is false, then we return the most tickets that could ever be sold |
|
| 974 | - * for this event with the datetime and tickets setup on the event under optimal |
|
| 975 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 976 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
| 977 | - * may appear to equal remaining tickets. However, the more tickets are |
|
| 978 | - * sold out, the more accurate the "live" total is. |
|
| 979 | - * @return float|int |
|
| 980 | - * @throws EE_Error |
|
| 981 | - * @throws DomainException |
|
| 982 | - * @throws UnexpectedEntityException |
|
| 983 | - */ |
|
| 984 | - public function total_available_spaces($consider_sold = false) |
|
| 985 | - { |
|
| 986 | - $spaces_available = $consider_sold |
|
| 987 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 988 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 989 | - return apply_filters( |
|
| 990 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 991 | - $spaces_available, |
|
| 992 | - $this, |
|
| 993 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 994 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 995 | - ); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * Checks if the event is set to sold out |
|
| 1001 | - * |
|
| 1002 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 1003 | - * actual status but also to flip the status if necessary to sold |
|
| 1004 | - * out If false, we just check the existing status of the event |
|
| 1005 | - * @return boolean |
|
| 1006 | - * @throws EE_Error |
|
| 1007 | - */ |
|
| 1008 | - public function is_sold_out($actual = false) |
|
| 1009 | - { |
|
| 1010 | - if (! $actual) { |
|
| 1011 | - return $this->status() === EEM_Event::sold_out; |
|
| 1012 | - } |
|
| 1013 | - return $this->perform_sold_out_status_check(); |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - |
|
| 1017 | - /** |
|
| 1018 | - * Checks if the event is marked as postponed |
|
| 1019 | - * |
|
| 1020 | - * @return boolean |
|
| 1021 | - */ |
|
| 1022 | - public function is_postponed() |
|
| 1023 | - { |
|
| 1024 | - return $this->status() === EEM_Event::postponed; |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * Checks if the event is marked as cancelled |
|
| 1030 | - * |
|
| 1031 | - * @return boolean |
|
| 1032 | - */ |
|
| 1033 | - public function is_cancelled() |
|
| 1034 | - { |
|
| 1035 | - return $this->status() === EEM_Event::cancelled; |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - |
|
| 1039 | - /** |
|
| 1040 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 1041 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 1042 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 1043 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1044 | - * the event is considered expired. |
|
| 1045 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
| 1046 | - * status set on the EVENT when it is not published and thus is done |
|
| 1047 | - * |
|
| 1048 | - * @param bool $reset |
|
| 1049 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1050 | - * @throws EE_Error |
|
| 1051 | - */ |
|
| 1052 | - public function get_active_status($reset = false) |
|
| 1053 | - { |
|
| 1054 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1055 | - if (! empty($this->_active_status) && ! $reset) { |
|
| 1056 | - return $this->_active_status; |
|
| 1057 | - } |
|
| 1058 | - // first check if event id is present on this object |
|
| 1059 | - if (! $this->ID()) { |
|
| 1060 | - return false; |
|
| 1061 | - } |
|
| 1062 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1063 | - // if event is published: |
|
| 1064 | - if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
| 1065 | - // active? |
|
| 1066 | - if ( |
|
| 1067 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1068 | - EE_Datetime::active, |
|
| 1069 | - $where_params_for_event |
|
| 1070 | - ) > 0 |
|
| 1071 | - ) { |
|
| 1072 | - $this->_active_status = EE_Datetime::active; |
|
| 1073 | - } else { |
|
| 1074 | - // upcoming? |
|
| 1075 | - if ( |
|
| 1076 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1077 | - EE_Datetime::upcoming, |
|
| 1078 | - $where_params_for_event |
|
| 1079 | - ) > 0 |
|
| 1080 | - ) { |
|
| 1081 | - $this->_active_status = EE_Datetime::upcoming; |
|
| 1082 | - } else { |
|
| 1083 | - // expired? |
|
| 1084 | - if ( |
|
| 1085 | - EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1086 | - EE_Datetime::expired, |
|
| 1087 | - $where_params_for_event |
|
| 1088 | - ) > 0 |
|
| 1089 | - ) { |
|
| 1090 | - $this->_active_status = EE_Datetime::expired; |
|
| 1091 | - } else { |
|
| 1092 | - // it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1093 | - // attached to the event. So in this case it will just be considered inactive. |
|
| 1094 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - } |
|
| 1098 | - } else { |
|
| 1099 | - // the event is not published, so let's just set it's active status according to its' post status |
|
| 1100 | - switch ($this->status()) { |
|
| 1101 | - case EEM_Event::sold_out: |
|
| 1102 | - $this->_active_status = EE_Datetime::sold_out; |
|
| 1103 | - break; |
|
| 1104 | - case EEM_Event::cancelled: |
|
| 1105 | - $this->_active_status = EE_Datetime::cancelled; |
|
| 1106 | - break; |
|
| 1107 | - case EEM_Event::postponed: |
|
| 1108 | - $this->_active_status = EE_Datetime::postponed; |
|
| 1109 | - break; |
|
| 1110 | - default: |
|
| 1111 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1112 | - } |
|
| 1113 | - } |
|
| 1114 | - return $this->_active_status; |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * pretty_active_status |
|
| 1120 | - * |
|
| 1121 | - * @access public |
|
| 1122 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1123 | - * @return mixed void|string |
|
| 1124 | - * @throws EE_Error |
|
| 1125 | - */ |
|
| 1126 | - public function pretty_active_status($echo = true) |
|
| 1127 | - { |
|
| 1128 | - $active_status = $this->get_active_status(); |
|
| 1129 | - $status = '<span class="ee-status event-active-status-' |
|
| 1130 | - . $active_status |
|
| 1131 | - . '">' |
|
| 1132 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1133 | - . '</span>'; |
|
| 1134 | - if ($echo) { |
|
| 1135 | - echo $status; |
|
| 1136 | - return ''; |
|
| 1137 | - } |
|
| 1138 | - return $status; |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - |
|
| 1142 | - /** |
|
| 1143 | - * @return bool|int |
|
| 1144 | - * @throws EE_Error |
|
| 1145 | - */ |
|
| 1146 | - public function get_number_of_tickets_sold() |
|
| 1147 | - { |
|
| 1148 | - $tkt_sold = 0; |
|
| 1149 | - if (! $this->ID()) { |
|
| 1150 | - return 0; |
|
| 1151 | - } |
|
| 1152 | - $datetimes = $this->datetimes(); |
|
| 1153 | - foreach ($datetimes as $datetime) { |
|
| 1154 | - if ($datetime instanceof EE_Datetime) { |
|
| 1155 | - $tkt_sold += $datetime->sold(); |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1158 | - return $tkt_sold; |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - |
|
| 1162 | - /** |
|
| 1163 | - * This just returns a count of all the registrations for this event |
|
| 1164 | - * |
|
| 1165 | - * @access public |
|
| 1166 | - * @return int |
|
| 1167 | - * @throws EE_Error |
|
| 1168 | - */ |
|
| 1169 | - public function get_count_of_all_registrations() |
|
| 1170 | - { |
|
| 1171 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - |
|
| 1175 | - /** |
|
| 1176 | - * This returns the ticket with the earliest start time that is |
|
| 1177 | - * available for this event (across all datetimes attached to the event) |
|
| 1178 | - * |
|
| 1179 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1180 | - * @throws EE_Error |
|
| 1181 | - */ |
|
| 1182 | - public function get_ticket_with_earliest_start_time() |
|
| 1183 | - { |
|
| 1184 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1185 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1186 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - |
|
| 1190 | - /** |
|
| 1191 | - * This returns the ticket with the latest end time that is available |
|
| 1192 | - * for this event (across all datetimes attached to the event) |
|
| 1193 | - * |
|
| 1194 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1195 | - * @throws EE_Error |
|
| 1196 | - */ |
|
| 1197 | - public function get_ticket_with_latest_end_time() |
|
| 1198 | - { |
|
| 1199 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1200 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1201 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - |
|
| 1205 | - /** |
|
| 1206 | - * This returns the number of different ticket types currently on sale for this event. |
|
| 1207 | - * |
|
| 1208 | - * @return int |
|
| 1209 | - * @throws EE_Error |
|
| 1210 | - */ |
|
| 1211 | - public function countTicketsOnSale() |
|
| 1212 | - { |
|
| 1213 | - $where = array( |
|
| 1214 | - 'Datetime.EVT_ID' => $this->ID(), |
|
| 1215 | - 'TKT_start_date' => array('<', time()), |
|
| 1216 | - 'TKT_end_date' => array('>', time()), |
|
| 1217 | - ); |
|
| 1218 | - return EEM_Ticket::instance()->count(array($where)); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - /** |
|
| 1223 | - * This returns whether there are any tickets on sale for this event. |
|
| 1224 | - * |
|
| 1225 | - * @return bool true = YES tickets on sale. |
|
| 1226 | - * @throws EE_Error |
|
| 1227 | - */ |
|
| 1228 | - public function tickets_on_sale() |
|
| 1229 | - { |
|
| 1230 | - return $this->countTicketsOnSale() > 0; |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - |
|
| 1234 | - /** |
|
| 1235 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1236 | - * to check for an external URL first |
|
| 1237 | - * |
|
| 1238 | - * @return string |
|
| 1239 | - * @throws EE_Error |
|
| 1240 | - */ |
|
| 1241 | - public function get_permalink() |
|
| 1242 | - { |
|
| 1243 | - if ($this->external_url()) { |
|
| 1244 | - return $this->external_url(); |
|
| 1245 | - } |
|
| 1246 | - return parent::get_permalink(); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - |
|
| 1250 | - /** |
|
| 1251 | - * Gets the first term for 'espresso_event_categories' we can find |
|
| 1252 | - * |
|
| 1253 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1254 | - * @return EE_Base_Class|EE_Term|null |
|
| 1255 | - * @throws EE_Error |
|
| 1256 | - */ |
|
| 1257 | - public function first_event_category($query_params = array()) |
|
| 1258 | - { |
|
| 1259 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1260 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1261 | - return EEM_Term::instance()->get_one($query_params); |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - |
|
| 1265 | - /** |
|
| 1266 | - * Gets all terms for 'espresso_event_categories' we can find |
|
| 1267 | - * |
|
| 1268 | - * @param array $query_params |
|
| 1269 | - * @return EE_Base_Class[]|EE_Term[] |
|
| 1270 | - * @throws EE_Error |
|
| 1271 | - */ |
|
| 1272 | - public function get_all_event_categories($query_params = array()) |
|
| 1273 | - { |
|
| 1274 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1275 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1276 | - return EEM_Term::instance()->get_all($query_params); |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * Adds a question group to this event |
|
| 1282 | - * |
|
| 1283 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1284 | - * @param bool $for_primary if true, the question group will be added for the primary |
|
| 1285 | - * registrant, if false will be added for others. default: false |
|
| 1286 | - * @return EE_Base_Class|EE_Question_Group |
|
| 1287 | - * @throws EE_Error |
|
| 1288 | - * @throws InvalidArgumentException |
|
| 1289 | - * @throws InvalidDataTypeException |
|
| 1290 | - * @throws InvalidInterfaceException |
|
| 1291 | - * @throws ReflectionException |
|
| 1292 | - */ |
|
| 1293 | - public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1294 | - { |
|
| 1295 | - // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
| 1296 | - // That's in EE_HABTM_Relation::add_relation_to(). |
|
| 1297 | - return $this->_add_relation_to( |
|
| 1298 | - $question_group_id_or_obj, |
|
| 1299 | - 'Question_Group', |
|
| 1300 | - [ |
|
| 1301 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
| 1302 | - ] |
|
| 1303 | - ); |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * Removes a question group from the event |
|
| 1309 | - * |
|
| 1310 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1311 | - * @param bool $for_primary if true, the question group will be removed from the primary |
|
| 1312 | - * registrant, if false will be removed from others. default: false |
|
| 1313 | - * @return EE_Base_Class|EE_Question_Group |
|
| 1314 | - * @throws EE_Error |
|
| 1315 | - * @throws InvalidArgumentException |
|
| 1316 | - * @throws ReflectionException |
|
| 1317 | - * @throws InvalidDataTypeException |
|
| 1318 | - * @throws InvalidInterfaceException |
|
| 1319 | - */ |
|
| 1320 | - public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1321 | - { |
|
| 1322 | - // If the question group is used for the other type (primary or additional) |
|
| 1323 | - // then just update it. If not, delete it outright. |
|
| 1324 | - $existing_relation = $this->get_first_related( |
|
| 1325 | - 'Event_Question_Group', |
|
| 1326 | - [ |
|
| 1327 | - [ |
|
| 1328 | - 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
| 1329 | - ] |
|
| 1330 | - ] |
|
| 1331 | - ); |
|
| 1332 | - $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
| 1333 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
| 1334 | - if ($existing_relation->get($other_field) === false) { |
|
| 1335 | - // Delete it. It's now no longer for primary or additional question groups. |
|
| 1336 | - return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
| 1337 | - } |
|
| 1338 | - // Just update it. They'll still use this question group for the other category |
|
| 1339 | - $existing_relation->save( |
|
| 1340 | - [ |
|
| 1341 | - $field_to_update => false |
|
| 1342 | - ] |
|
| 1343 | - ); |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - |
|
| 1347 | - /** |
|
| 1348 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1349 | - * |
|
| 1350 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1351 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1352 | - * @throws EE_Error |
|
| 1353 | - */ |
|
| 1354 | - public function question_groups($query_params = array()) |
|
| 1355 | - { |
|
| 1356 | - $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1357 | - return $this->get_many_related('Question_Group', $query_params); |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - |
|
| 1361 | - /** |
|
| 1362 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1363 | - * |
|
| 1364 | - * @see EEI_Visual_Representation for comments |
|
| 1365 | - * @return string |
|
| 1366 | - */ |
|
| 1367 | - public function get_icon() |
|
| 1368 | - { |
|
| 1369 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1375 | - * |
|
| 1376 | - * @see EEI_Admin_Links for comments |
|
| 1377 | - * @return string |
|
| 1378 | - * @throws EE_Error |
|
| 1379 | - */ |
|
| 1380 | - public function get_admin_details_link() |
|
| 1381 | - { |
|
| 1382 | - return $this->get_admin_edit_link(); |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - |
|
| 1386 | - /** |
|
| 1387 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1388 | - * |
|
| 1389 | - * @see EEI_Admin_Links for comments |
|
| 1390 | - * @return string |
|
| 1391 | - * @throws EE_Error |
|
| 1392 | - */ |
|
| 1393 | - public function get_admin_edit_link() |
|
| 1394 | - { |
|
| 1395 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1396 | - array( |
|
| 1397 | - 'page' => 'espresso_events', |
|
| 1398 | - 'action' => 'edit', |
|
| 1399 | - 'post' => $this->ID(), |
|
| 1400 | - ), |
|
| 1401 | - admin_url('admin.php') |
|
| 1402 | - ); |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1408 | - * |
|
| 1409 | - * @see EEI_Admin_Links for comments |
|
| 1410 | - * @return string |
|
| 1411 | - */ |
|
| 1412 | - public function get_admin_settings_link() |
|
| 1413 | - { |
|
| 1414 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1415 | - array( |
|
| 1416 | - 'page' => 'espresso_events', |
|
| 1417 | - 'action' => 'default_event_settings', |
|
| 1418 | - ), |
|
| 1419 | - admin_url('admin.php') |
|
| 1420 | - ); |
|
| 1421 | - } |
|
| 1422 | - |
|
| 1423 | - |
|
| 1424 | - /** |
|
| 1425 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1426 | - * |
|
| 1427 | - * @see EEI_Admin_Links for comments |
|
| 1428 | - * @return string |
|
| 1429 | - */ |
|
| 1430 | - public function get_admin_overview_link() |
|
| 1431 | - { |
|
| 1432 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1433 | - array( |
|
| 1434 | - 'page' => 'espresso_events', |
|
| 1435 | - 'action' => 'default', |
|
| 1436 | - ), |
|
| 1437 | - admin_url('admin.php') |
|
| 1438 | - ); |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - |
|
| 1442 | - /** |
|
| 1443 | - * @return string|null |
|
| 1444 | - * @throws EE_Error |
|
| 1445 | - * @throws ReflectionException |
|
| 1446 | - */ |
|
| 1447 | - public function registrationFormUuid(): ?string |
|
| 1448 | - { |
|
| 1449 | - return $this->get('FSC_UUID'); |
|
| 1450 | - } |
|
| 1451 | - |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * Gets all the form sections for this event |
|
| 1455 | - * |
|
| 1456 | - * @return EE_Base_Class[]|EE_Form_Section[] |
|
| 1457 | - * @throws EE_Error |
|
| 1458 | - * @throws ReflectionException |
|
| 1459 | - */ |
|
| 1460 | - public function registrationForm() |
|
| 1461 | - { |
|
| 1462 | - $FSC_UUID = $this->registrationFormUuid(); |
|
| 1463 | - |
|
| 1464 | - if (empty($FSC_UUID)) { |
|
| 1465 | - return []; |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - return EEM_Form_Section::instance()->get_all([ |
|
| 1469 | - [ |
|
| 1470 | - 'OR' => [ |
|
| 1471 | - 'FSC_UUID' => $FSC_UUID, // top level form |
|
| 1472 | - 'FSC_belongsTo' => $FSC_UUID, // child form sections |
|
| 1473 | - ] |
|
| 1474 | - ], |
|
| 1475 | - 'order_by' => ['FSC_order' => 'ASC'], |
|
| 1476 | - ]); |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - |
|
| 1480 | - /** |
|
| 1481 | - * @param string $UUID |
|
| 1482 | - * @throws EE_Error |
|
| 1483 | - */ |
|
| 1484 | - public function setRegistrationFormUuid(string $UUID): void |
|
| 1485 | - { |
|
| 1486 | - if (! Cuid::isCuid($UUID)) { |
|
| 1487 | - throw new InvalidArgumentException( |
|
| 1488 | - sprintf( |
|
| 1489 | - /* translators: 1: UUID value, 2: UUID generator function. */ |
|
| 1490 | - esc_html__( |
|
| 1491 | - 'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.', |
|
| 1492 | - 'event_espresso' |
|
| 1493 | - ), |
|
| 1494 | - $UUID, |
|
| 1495 | - '`Cuid::cuid()`' |
|
| 1496 | - ) |
|
| 1497 | - ); |
|
| 1498 | - } |
|
| 1499 | - $this->set('FSC_UUID', $UUID); |
|
| 1500 | - } |
|
| 19 | + /** |
|
| 20 | + * cached value for the the logical active status for the event |
|
| 21 | + * |
|
| 22 | + * @see get_active_status() |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $_active_status = ''; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 29 | + * |
|
| 30 | + * @var EE_Datetime |
|
| 31 | + */ |
|
| 32 | + protected $_Primary_Datetime; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
| 36 | + */ |
|
| 37 | + protected $available_spaces_calculator; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param array $props_n_values incoming values |
|
| 42 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 43 | + * used.) |
|
| 44 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 45 | + * date_format and the second value is the time format |
|
| 46 | + * @return EE_Event |
|
| 47 | + * @throws EE_Error |
|
| 48 | + */ |
|
| 49 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 50 | + { |
|
| 51 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 52 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param array $props_n_values incoming values from the database |
|
| 58 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 59 | + * the website will be used. |
|
| 60 | + * @return EE_Event |
|
| 61 | + * @throws EE_Error |
|
| 62 | + */ |
|
| 63 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 64 | + { |
|
| 65 | + return new self($props_n_values, true, $timezone); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return EventSpacesCalculator |
|
| 71 | + * @throws \EE_Error |
|
| 72 | + */ |
|
| 73 | + public function getAvailableSpacesCalculator() |
|
| 74 | + { |
|
| 75 | + if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 76 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 77 | + } |
|
| 78 | + return $this->available_spaces_calculator; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 84 | + * |
|
| 85 | + * @param string $field_name |
|
| 86 | + * @param mixed $field_value |
|
| 87 | + * @param bool $use_default |
|
| 88 | + * @throws EE_Error |
|
| 89 | + */ |
|
| 90 | + public function set($field_name, $field_value, $use_default = false) |
|
| 91 | + { |
|
| 92 | + switch ($field_name) { |
|
| 93 | + case 'status': |
|
| 94 | + $this->set_status($field_value, $use_default); |
|
| 95 | + break; |
|
| 96 | + default: |
|
| 97 | + parent::set($field_name, $field_value, $use_default); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * set_status |
|
| 104 | + * Checks if event status is being changed to SOLD OUT |
|
| 105 | + * and updates event meta data with previous event status |
|
| 106 | + * so that we can revert things if/when the event is no longer sold out |
|
| 107 | + * |
|
| 108 | + * @access public |
|
| 109 | + * @param string $new_status |
|
| 110 | + * @param bool $use_default |
|
| 111 | + * @return void |
|
| 112 | + * @throws EE_Error |
|
| 113 | + */ |
|
| 114 | + public function set_status($new_status = null, $use_default = false) |
|
| 115 | + { |
|
| 116 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 117 | + if (empty($new_status) && ! $use_default) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 120 | + // get current Event status |
|
| 121 | + $old_status = $this->status(); |
|
| 122 | + // if status has changed |
|
| 123 | + if ($old_status !== $new_status) { |
|
| 124 | + // TO sold_out |
|
| 125 | + if ($new_status === EEM_Event::sold_out) { |
|
| 126 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
| 127 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
| 128 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 129 | + // OR FROM sold_out |
|
| 130 | + } elseif ($old_status === EEM_Event::sold_out) { |
|
| 131 | + $this->delete_post_meta('_previous_event_status'); |
|
| 132 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 133 | + } |
|
| 134 | + // clear out the active status so that it gets reset the next time it is requested |
|
| 135 | + $this->_active_status = null; |
|
| 136 | + // update status |
|
| 137 | + parent::set('status', $new_status, $use_default); |
|
| 138 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 139 | + return; |
|
| 140 | + } |
|
| 141 | + // even though the old value matches the new value, it's still good to |
|
| 142 | + // allow the parent set method to have a say |
|
| 143 | + parent::set('status', $new_status, $use_default); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Gets all the datetimes for this event |
|
| 149 | + * |
|
| 150 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 151 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 152 | + * @throws EE_Error |
|
| 153 | + */ |
|
| 154 | + public function datetimes($query_params = array()) |
|
| 155 | + { |
|
| 156 | + return $this->get_many_related('Datetime', $query_params); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 162 | + * |
|
| 163 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 164 | + * @throws EE_Error |
|
| 165 | + */ |
|
| 166 | + public function datetimes_in_chronological_order() |
|
| 167 | + { |
|
| 168 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 174 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 175 | + * after running our query, so that this timezone isn't set for EVERY query |
|
| 176 | + * on EEM_Datetime for the rest of the request, no? |
|
| 177 | + * |
|
| 178 | + * @param boolean $show_expired whether or not to include expired events |
|
| 179 | + * @param boolean $show_deleted whether or not to include deleted events |
|
| 180 | + * @param null $limit |
|
| 181 | + * @return EE_Datetime[] |
|
| 182 | + * @throws EE_Error |
|
| 183 | + */ |
|
| 184 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 185 | + { |
|
| 186 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 187 | + $this->ID(), |
|
| 188 | + $show_expired, |
|
| 189 | + $show_deleted, |
|
| 190 | + $limit |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
| 197 | + * |
|
| 198 | + * @return EE_Base_Class|EE_Datetime |
|
| 199 | + * @throws EE_Error |
|
| 200 | + */ |
|
| 201 | + public function first_datetime() |
|
| 202 | + { |
|
| 203 | + return $this->get_first_related('Datetime'); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Returns the 'primary' datetime for the event |
|
| 209 | + * |
|
| 210 | + * @param bool $try_to_exclude_expired |
|
| 211 | + * @param bool $try_to_exclude_deleted |
|
| 212 | + * @return EE_Datetime |
|
| 213 | + * @throws EE_Error |
|
| 214 | + */ |
|
| 215 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 216 | + { |
|
| 217 | + if (! empty($this->_Primary_Datetime)) { |
|
| 218 | + return $this->_Primary_Datetime; |
|
| 219 | + } |
|
| 220 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 221 | + $this->ID(), |
|
| 222 | + $try_to_exclude_expired, |
|
| 223 | + $try_to_exclude_deleted |
|
| 224 | + ); |
|
| 225 | + return $this->_Primary_Datetime; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Gets all the tickets available for purchase of this event |
|
| 231 | + * |
|
| 232 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 233 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 234 | + * @throws EE_Error |
|
| 235 | + */ |
|
| 236 | + public function tickets($query_params = array()) |
|
| 237 | + { |
|
| 238 | + // first get all datetimes |
|
| 239 | + $datetimes = $this->datetimes_ordered(); |
|
| 240 | + if (! $datetimes) { |
|
| 241 | + return array(); |
|
| 242 | + } |
|
| 243 | + $datetime_ids = array(); |
|
| 244 | + foreach ($datetimes as $datetime) { |
|
| 245 | + $datetime_ids[] = $datetime->ID(); |
|
| 246 | + } |
|
| 247 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 248 | + // if incoming $query_params has where conditions let's merge but not override existing. |
|
| 249 | + if (is_array($query_params) && isset($query_params[0])) { |
|
| 250 | + $where_params = array_merge($query_params[0], $where_params); |
|
| 251 | + unset($query_params[0]); |
|
| 252 | + } |
|
| 253 | + // now add $where_params to $query_params |
|
| 254 | + $query_params[0] = $where_params; |
|
| 255 | + return EEM_Ticket::instance()->get_all($query_params); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * get all unexpired untrashed tickets |
|
| 261 | + * |
|
| 262 | + * @return EE_Ticket[] |
|
| 263 | + * @throws EE_Error |
|
| 264 | + */ |
|
| 265 | + public function active_tickets() |
|
| 266 | + { |
|
| 267 | + return $this->tickets( |
|
| 268 | + array( |
|
| 269 | + array( |
|
| 270 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 271 | + 'TKT_deleted' => false, |
|
| 272 | + ), |
|
| 273 | + ) |
|
| 274 | + ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @return bool |
|
| 280 | + * @throws EE_Error |
|
| 281 | + */ |
|
| 282 | + public function additional_limit() |
|
| 283 | + { |
|
| 284 | + return $this->get('EVT_additional_limit'); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @return bool |
|
| 290 | + * @throws EE_Error |
|
| 291 | + */ |
|
| 292 | + public function allow_overflow() |
|
| 293 | + { |
|
| 294 | + return $this->get('EVT_allow_overflow'); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @return bool |
|
| 300 | + * @throws EE_Error |
|
| 301 | + */ |
|
| 302 | + public function created() |
|
| 303 | + { |
|
| 304 | + return $this->get('EVT_created'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * @return bool |
|
| 310 | + * @throws EE_Error |
|
| 311 | + */ |
|
| 312 | + public function description() |
|
| 313 | + { |
|
| 314 | + return $this->get('EVT_desc'); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Runs do_shortcode and wpautop on the description |
|
| 320 | + * |
|
| 321 | + * @return string of html |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function description_filtered() |
|
| 325 | + { |
|
| 326 | + return $this->get_pretty('EVT_desc'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * @return bool |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + public function display_description() |
|
| 335 | + { |
|
| 336 | + return $this->get('EVT_display_desc'); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * @return bool |
|
| 342 | + * @throws EE_Error |
|
| 343 | + */ |
|
| 344 | + public function display_ticket_selector() |
|
| 345 | + { |
|
| 346 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @return bool |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + public function external_url() |
|
| 355 | + { |
|
| 356 | + return $this->get('EVT_external_URL'); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @return bool |
|
| 362 | + * @throws EE_Error |
|
| 363 | + */ |
|
| 364 | + public function member_only() |
|
| 365 | + { |
|
| 366 | + return $this->get('EVT_member_only'); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * @return bool |
|
| 372 | + * @throws EE_Error |
|
| 373 | + */ |
|
| 374 | + public function phone() |
|
| 375 | + { |
|
| 376 | + return $this->get('EVT_phone'); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @return bool |
|
| 382 | + * @throws EE_Error |
|
| 383 | + */ |
|
| 384 | + public function modified() |
|
| 385 | + { |
|
| 386 | + return $this->get('EVT_modified'); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * @return bool |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function name() |
|
| 395 | + { |
|
| 396 | + return $this->get('EVT_name'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @return bool |
|
| 402 | + * @throws EE_Error |
|
| 403 | + */ |
|
| 404 | + public function order() |
|
| 405 | + { |
|
| 406 | + return $this->get('EVT_order'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * @return bool|string |
|
| 412 | + * @throws EE_Error |
|
| 413 | + */ |
|
| 414 | + public function default_registration_status() |
|
| 415 | + { |
|
| 416 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 417 | + return ! empty($event_default_registration_status) |
|
| 418 | + ? $event_default_registration_status |
|
| 419 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @param int $num_words |
|
| 425 | + * @param null $more |
|
| 426 | + * @param bool $not_full_desc |
|
| 427 | + * @return bool|string |
|
| 428 | + * @throws EE_Error |
|
| 429 | + */ |
|
| 430 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 431 | + { |
|
| 432 | + $short_desc = $this->get('EVT_short_desc'); |
|
| 433 | + if (! empty($short_desc) || $not_full_desc) { |
|
| 434 | + return $short_desc; |
|
| 435 | + } |
|
| 436 | + $full_desc = $this->get('EVT_desc'); |
|
| 437 | + return wp_trim_words($full_desc, $num_words, $more); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @return bool |
|
| 443 | + * @throws EE_Error |
|
| 444 | + */ |
|
| 445 | + public function slug() |
|
| 446 | + { |
|
| 447 | + return $this->get('EVT_slug'); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @return bool |
|
| 453 | + * @throws EE_Error |
|
| 454 | + */ |
|
| 455 | + public function timezone_string() |
|
| 456 | + { |
|
| 457 | + return $this->get('EVT_timezone_string'); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @return bool |
|
| 463 | + * @throws EE_Error |
|
| 464 | + */ |
|
| 465 | + public function visible_on() |
|
| 466 | + { |
|
| 467 | + return $this->get('EVT_visible_on'); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @return int |
|
| 473 | + * @throws EE_Error |
|
| 474 | + */ |
|
| 475 | + public function wp_user() |
|
| 476 | + { |
|
| 477 | + return $this->get('EVT_wp_user'); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @return bool |
|
| 483 | + * @throws EE_Error |
|
| 484 | + */ |
|
| 485 | + public function donations() |
|
| 486 | + { |
|
| 487 | + return $this->get('EVT_donations'); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @param $limit |
|
| 493 | + * @throws EE_Error |
|
| 494 | + */ |
|
| 495 | + public function set_additional_limit($limit) |
|
| 496 | + { |
|
| 497 | + $this->set('EVT_additional_limit', $limit); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param $created |
|
| 503 | + * @throws EE_Error |
|
| 504 | + */ |
|
| 505 | + public function set_created($created) |
|
| 506 | + { |
|
| 507 | + $this->set('EVT_created', $created); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * @param $desc |
|
| 513 | + * @throws EE_Error |
|
| 514 | + */ |
|
| 515 | + public function set_description($desc) |
|
| 516 | + { |
|
| 517 | + $this->set('EVT_desc', $desc); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @param $display_desc |
|
| 523 | + * @throws EE_Error |
|
| 524 | + */ |
|
| 525 | + public function set_display_description($display_desc) |
|
| 526 | + { |
|
| 527 | + $this->set('EVT_display_desc', $display_desc); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * @param $display_ticket_selector |
|
| 533 | + * @throws EE_Error |
|
| 534 | + */ |
|
| 535 | + public function set_display_ticket_selector($display_ticket_selector) |
|
| 536 | + { |
|
| 537 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * @param $external_url |
|
| 543 | + * @throws EE_Error |
|
| 544 | + */ |
|
| 545 | + public function set_external_url($external_url) |
|
| 546 | + { |
|
| 547 | + $this->set('EVT_external_URL', $external_url); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * @param $member_only |
|
| 553 | + * @throws EE_Error |
|
| 554 | + */ |
|
| 555 | + public function set_member_only($member_only) |
|
| 556 | + { |
|
| 557 | + $this->set('EVT_member_only', $member_only); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @param $event_phone |
|
| 563 | + * @throws EE_Error |
|
| 564 | + */ |
|
| 565 | + public function set_event_phone($event_phone) |
|
| 566 | + { |
|
| 567 | + $this->set('EVT_phone', $event_phone); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * @param $modified |
|
| 573 | + * @throws EE_Error |
|
| 574 | + */ |
|
| 575 | + public function set_modified($modified) |
|
| 576 | + { |
|
| 577 | + $this->set('EVT_modified', $modified); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * @param $name |
|
| 583 | + * @throws EE_Error |
|
| 584 | + */ |
|
| 585 | + public function set_name($name) |
|
| 586 | + { |
|
| 587 | + $this->set('EVT_name', $name); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * @param $order |
|
| 593 | + * @throws EE_Error |
|
| 594 | + */ |
|
| 595 | + public function set_order($order) |
|
| 596 | + { |
|
| 597 | + $this->set('EVT_order', $order); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * @param $short_desc |
|
| 603 | + * @throws EE_Error |
|
| 604 | + */ |
|
| 605 | + public function set_short_description($short_desc) |
|
| 606 | + { |
|
| 607 | + $this->set('EVT_short_desc', $short_desc); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * @param $slug |
|
| 613 | + * @throws EE_Error |
|
| 614 | + */ |
|
| 615 | + public function set_slug($slug) |
|
| 616 | + { |
|
| 617 | + $this->set('EVT_slug', $slug); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @param $timezone_string |
|
| 623 | + * @throws EE_Error |
|
| 624 | + */ |
|
| 625 | + public function set_timezone_string($timezone_string) |
|
| 626 | + { |
|
| 627 | + $this->set('EVT_timezone_string', $timezone_string); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * @param $visible_on |
|
| 633 | + * @throws EE_Error |
|
| 634 | + */ |
|
| 635 | + public function set_visible_on($visible_on) |
|
| 636 | + { |
|
| 637 | + $this->set('EVT_visible_on', $visible_on); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * @param $wp_user |
|
| 643 | + * @throws EE_Error |
|
| 644 | + */ |
|
| 645 | + public function set_wp_user($wp_user) |
|
| 646 | + { |
|
| 647 | + $this->set('EVT_wp_user', $wp_user); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * @param $default_registration_status |
|
| 653 | + * @throws EE_Error |
|
| 654 | + */ |
|
| 655 | + public function set_default_registration_status($default_registration_status) |
|
| 656 | + { |
|
| 657 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param $donations |
|
| 663 | + * @throws EE_Error |
|
| 664 | + */ |
|
| 665 | + public function set_donations($donations) |
|
| 666 | + { |
|
| 667 | + $this->set('EVT_donations', $donations); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Adds a venue to this event |
|
| 673 | + * |
|
| 674 | + * @param int|EE_Venue /int $venue_id_or_obj |
|
| 675 | + * @return EE_Base_Class|EE_Venue |
|
| 676 | + * @throws EE_Error |
|
| 677 | + * @throws ReflectionException |
|
| 678 | + */ |
|
| 679 | + public function add_venue($venue_id_or_obj): EE_Venue |
|
| 680 | + { |
|
| 681 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Removes a venue from the event |
|
| 687 | + * |
|
| 688 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 689 | + * @return EE_Base_Class|EE_Venue |
|
| 690 | + * @throws EE_Error |
|
| 691 | + * @throws ReflectionException |
|
| 692 | + */ |
|
| 693 | + public function remove_venue($venue_id_or_obj): EE_Venue |
|
| 694 | + { |
|
| 695 | + $venue_id_or_obj = ! empty($venue_id_or_obj) ? $venue_id_or_obj : $this->venue(); |
|
| 696 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Gets the venue related to the event. May provide additional $query_params if desired |
|
| 702 | + * |
|
| 703 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 704 | + * @return int |
|
| 705 | + * @throws EE_Error |
|
| 706 | + * @throws ReflectionException |
|
| 707 | + */ |
|
| 708 | + public function venue_ID(array $query_params = array()): int |
|
| 709 | + { |
|
| 710 | + $venue = $this->get_first_related('Venue', $query_params); |
|
| 711 | + return $venue instanceof EE_Venue ? $venue->ID() : 0; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * Gets the venue related to the event. May provide additional $query_params if desired |
|
| 717 | + * |
|
| 718 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 719 | + * @return EE_Base_Class|EE_Venue |
|
| 720 | + * @throws EE_Error |
|
| 721 | + * @throws ReflectionException |
|
| 722 | + */ |
|
| 723 | + public function venue(array $query_params = array()) |
|
| 724 | + { |
|
| 725 | + return $this->get_first_related('Venue', $query_params); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * @param array $query_params |
|
| 731 | + * @return EE_Base_Class[]|EE_Venue[] |
|
| 732 | + * @throws EE_Error |
|
| 733 | + * @throws ReflectionException |
|
| 734 | + * @deprecated $VID:$ |
|
| 735 | + */ |
|
| 736 | + public function venues(array $query_params = array()): array |
|
| 737 | + { |
|
| 738 | + return [$this->venue($query_params)]; |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * check if event id is present and if event is published |
|
| 744 | + * |
|
| 745 | + * @access public |
|
| 746 | + * @return boolean true yes, false no |
|
| 747 | + * @throws EE_Error |
|
| 748 | + */ |
|
| 749 | + private function _has_ID_and_is_published() |
|
| 750 | + { |
|
| 751 | + // first check if event id is present and not NULL, |
|
| 752 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 753 | + return |
|
| 754 | + $this->ID() && $this->ID() !== null |
|
| 755 | + && ( |
|
| 756 | + $this->status() === 'publish' |
|
| 757 | + || $this->status() === EEM_Event::sold_out |
|
| 758 | + || $this->status() === EEM_Event::postponed |
|
| 759 | + || $this->status() === EEM_Event::cancelled |
|
| 760 | + ); |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 766 | + * |
|
| 767 | + * @access public |
|
| 768 | + * @return boolean true yes, false no |
|
| 769 | + * @throws EE_Error |
|
| 770 | + */ |
|
| 771 | + public function is_upcoming() |
|
| 772 | + { |
|
| 773 | + // check if event id is present and if this event is published |
|
| 774 | + if ($this->is_inactive()) { |
|
| 775 | + return false; |
|
| 776 | + } |
|
| 777 | + // set initial value |
|
| 778 | + $upcoming = false; |
|
| 779 | + // next let's get all datetimes and loop through them |
|
| 780 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 781 | + foreach ($datetimes as $datetime) { |
|
| 782 | + if ($datetime instanceof EE_Datetime) { |
|
| 783 | + // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 784 | + if ($datetime->is_expired()) { |
|
| 785 | + continue; |
|
| 786 | + } |
|
| 787 | + // if this dtt is active then we return false. |
|
| 788 | + if ($datetime->is_active()) { |
|
| 789 | + return false; |
|
| 790 | + } |
|
| 791 | + // otherwise let's check upcoming status |
|
| 792 | + $upcoming = $datetime->is_upcoming(); |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + return $upcoming; |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * @return bool |
|
| 801 | + * @throws EE_Error |
|
| 802 | + */ |
|
| 803 | + public function is_active() |
|
| 804 | + { |
|
| 805 | + // check if event id is present and if this event is published |
|
| 806 | + if ($this->is_inactive()) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 809 | + // set initial value |
|
| 810 | + $active = false; |
|
| 811 | + // next let's get all datetimes and loop through them |
|
| 812 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 813 | + foreach ($datetimes as $datetime) { |
|
| 814 | + if ($datetime instanceof EE_Datetime) { |
|
| 815 | + // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 816 | + if ($datetime->is_expired()) { |
|
| 817 | + continue; |
|
| 818 | + } |
|
| 819 | + // if this dtt is upcoming then we return false. |
|
| 820 | + if ($datetime->is_upcoming()) { |
|
| 821 | + return false; |
|
| 822 | + } |
|
| 823 | + // otherwise let's check active status |
|
| 824 | + $active = $datetime->is_active(); |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + return $active; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * @return bool |
|
| 833 | + * @throws EE_Error |
|
| 834 | + */ |
|
| 835 | + public function is_expired() |
|
| 836 | + { |
|
| 837 | + // check if event id is present and if this event is published |
|
| 838 | + if ($this->is_inactive()) { |
|
| 839 | + return false; |
|
| 840 | + } |
|
| 841 | + // set initial value |
|
| 842 | + $expired = false; |
|
| 843 | + // first let's get all datetimes and loop through them |
|
| 844 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 845 | + foreach ($datetimes as $datetime) { |
|
| 846 | + if ($datetime instanceof EE_Datetime) { |
|
| 847 | + // if this dtt is upcoming or active then we return false. |
|
| 848 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 849 | + return false; |
|
| 850 | + } |
|
| 851 | + // otherwise let's check active status |
|
| 852 | + $expired = $datetime->is_expired(); |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + return $expired; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * @return bool |
|
| 861 | + * @throws EE_Error |
|
| 862 | + */ |
|
| 863 | + public function is_inactive() |
|
| 864 | + { |
|
| 865 | + // check if event id is present and if this event is published |
|
| 866 | + if ($this->_has_ID_and_is_published()) { |
|
| 867 | + return false; |
|
| 868 | + } |
|
| 869 | + return true; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * calculate spaces remaining based on "saleable" tickets |
|
| 875 | + * |
|
| 876 | + * @param array $tickets |
|
| 877 | + * @param bool $filtered |
|
| 878 | + * @return int|float |
|
| 879 | + * @throws EE_Error |
|
| 880 | + * @throws DomainException |
|
| 881 | + * @throws UnexpectedEntityException |
|
| 882 | + */ |
|
| 883 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 884 | + { |
|
| 885 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 886 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 887 | + return $filtered |
|
| 888 | + ? apply_filters( |
|
| 889 | + 'FHEE_EE_Event__spaces_remaining', |
|
| 890 | + $spaces_remaining, |
|
| 891 | + $this, |
|
| 892 | + $tickets |
|
| 893 | + ) |
|
| 894 | + : $spaces_remaining; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * perform_sold_out_status_check |
|
| 900 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
| 901 | + * available... if NOT, then the event status will get toggled to 'sold_out' |
|
| 902 | + * |
|
| 903 | + * @return bool return the ACTUAL sold out state. |
|
| 904 | + * @throws EE_Error |
|
| 905 | + * @throws DomainException |
|
| 906 | + * @throws UnexpectedEntityException |
|
| 907 | + */ |
|
| 908 | + public function perform_sold_out_status_check() |
|
| 909 | + { |
|
| 910 | + // get all tickets |
|
| 911 | + $tickets = $this->tickets( |
|
| 912 | + array( |
|
| 913 | + 'default_where_conditions' => 'none', |
|
| 914 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 915 | + ) |
|
| 916 | + ); |
|
| 917 | + $all_expired = true; |
|
| 918 | + foreach ($tickets as $ticket) { |
|
| 919 | + if (! $ticket->is_expired()) { |
|
| 920 | + $all_expired = false; |
|
| 921 | + break; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
| 925 | + if ($all_expired) { |
|
| 926 | + return true; |
|
| 927 | + } |
|
| 928 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 929 | + if ($spaces_remaining < 1) { |
|
| 930 | + if ($this->status() !== EEM_Event::post_status_private) { |
|
| 931 | + $this->set_status(EEM_Event::sold_out); |
|
| 932 | + $this->save(); |
|
| 933 | + } |
|
| 934 | + $sold_out = true; |
|
| 935 | + } else { |
|
| 936 | + $sold_out = false; |
|
| 937 | + // was event previously marked as sold out ? |
|
| 938 | + if ($this->status() === EEM_Event::sold_out) { |
|
| 939 | + // revert status to previous value, if it was set |
|
| 940 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 941 | + if ($previous_event_status) { |
|
| 942 | + $this->set_status($previous_event_status); |
|
| 943 | + $this->save(); |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 948 | + return $sold_out; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * This returns the total remaining spaces for sale on this event. |
|
| 954 | + * |
|
| 955 | + * @uses EE_Event::total_available_spaces() |
|
| 956 | + * @return float|int |
|
| 957 | + * @throws EE_Error |
|
| 958 | + * @throws DomainException |
|
| 959 | + * @throws UnexpectedEntityException |
|
| 960 | + */ |
|
| 961 | + public function spaces_remaining_for_sale() |
|
| 962 | + { |
|
| 963 | + return $this->total_available_spaces(true); |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * This returns the total spaces available for an event |
|
| 969 | + * while considering all the qtys on the tickets and the reg limits |
|
| 970 | + * on the datetimes attached to this event. |
|
| 971 | + * |
|
| 972 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 973 | + * If this is false, then we return the most tickets that could ever be sold |
|
| 974 | + * for this event with the datetime and tickets setup on the event under optimal |
|
| 975 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 976 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
| 977 | + * may appear to equal remaining tickets. However, the more tickets are |
|
| 978 | + * sold out, the more accurate the "live" total is. |
|
| 979 | + * @return float|int |
|
| 980 | + * @throws EE_Error |
|
| 981 | + * @throws DomainException |
|
| 982 | + * @throws UnexpectedEntityException |
|
| 983 | + */ |
|
| 984 | + public function total_available_spaces($consider_sold = false) |
|
| 985 | + { |
|
| 986 | + $spaces_available = $consider_sold |
|
| 987 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 988 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 989 | + return apply_filters( |
|
| 990 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 991 | + $spaces_available, |
|
| 992 | + $this, |
|
| 993 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 994 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 995 | + ); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * Checks if the event is set to sold out |
|
| 1001 | + * |
|
| 1002 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 1003 | + * actual status but also to flip the status if necessary to sold |
|
| 1004 | + * out If false, we just check the existing status of the event |
|
| 1005 | + * @return boolean |
|
| 1006 | + * @throws EE_Error |
|
| 1007 | + */ |
|
| 1008 | + public function is_sold_out($actual = false) |
|
| 1009 | + { |
|
| 1010 | + if (! $actual) { |
|
| 1011 | + return $this->status() === EEM_Event::sold_out; |
|
| 1012 | + } |
|
| 1013 | + return $this->perform_sold_out_status_check(); |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + |
|
| 1017 | + /** |
|
| 1018 | + * Checks if the event is marked as postponed |
|
| 1019 | + * |
|
| 1020 | + * @return boolean |
|
| 1021 | + */ |
|
| 1022 | + public function is_postponed() |
|
| 1023 | + { |
|
| 1024 | + return $this->status() === EEM_Event::postponed; |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * Checks if the event is marked as cancelled |
|
| 1030 | + * |
|
| 1031 | + * @return boolean |
|
| 1032 | + */ |
|
| 1033 | + public function is_cancelled() |
|
| 1034 | + { |
|
| 1035 | + return $this->status() === EEM_Event::cancelled; |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + |
|
| 1039 | + /** |
|
| 1040 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 1041 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 1042 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 1043 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1044 | + * the event is considered expired. |
|
| 1045 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
| 1046 | + * status set on the EVENT when it is not published and thus is done |
|
| 1047 | + * |
|
| 1048 | + * @param bool $reset |
|
| 1049 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1050 | + * @throws EE_Error |
|
| 1051 | + */ |
|
| 1052 | + public function get_active_status($reset = false) |
|
| 1053 | + { |
|
| 1054 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1055 | + if (! empty($this->_active_status) && ! $reset) { |
|
| 1056 | + return $this->_active_status; |
|
| 1057 | + } |
|
| 1058 | + // first check if event id is present on this object |
|
| 1059 | + if (! $this->ID()) { |
|
| 1060 | + return false; |
|
| 1061 | + } |
|
| 1062 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1063 | + // if event is published: |
|
| 1064 | + if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
| 1065 | + // active? |
|
| 1066 | + if ( |
|
| 1067 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1068 | + EE_Datetime::active, |
|
| 1069 | + $where_params_for_event |
|
| 1070 | + ) > 0 |
|
| 1071 | + ) { |
|
| 1072 | + $this->_active_status = EE_Datetime::active; |
|
| 1073 | + } else { |
|
| 1074 | + // upcoming? |
|
| 1075 | + if ( |
|
| 1076 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1077 | + EE_Datetime::upcoming, |
|
| 1078 | + $where_params_for_event |
|
| 1079 | + ) > 0 |
|
| 1080 | + ) { |
|
| 1081 | + $this->_active_status = EE_Datetime::upcoming; |
|
| 1082 | + } else { |
|
| 1083 | + // expired? |
|
| 1084 | + if ( |
|
| 1085 | + EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1086 | + EE_Datetime::expired, |
|
| 1087 | + $where_params_for_event |
|
| 1088 | + ) > 0 |
|
| 1089 | + ) { |
|
| 1090 | + $this->_active_status = EE_Datetime::expired; |
|
| 1091 | + } else { |
|
| 1092 | + // it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1093 | + // attached to the event. So in this case it will just be considered inactive. |
|
| 1094 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + } |
|
| 1098 | + } else { |
|
| 1099 | + // the event is not published, so let's just set it's active status according to its' post status |
|
| 1100 | + switch ($this->status()) { |
|
| 1101 | + case EEM_Event::sold_out: |
|
| 1102 | + $this->_active_status = EE_Datetime::sold_out; |
|
| 1103 | + break; |
|
| 1104 | + case EEM_Event::cancelled: |
|
| 1105 | + $this->_active_status = EE_Datetime::cancelled; |
|
| 1106 | + break; |
|
| 1107 | + case EEM_Event::postponed: |
|
| 1108 | + $this->_active_status = EE_Datetime::postponed; |
|
| 1109 | + break; |
|
| 1110 | + default: |
|
| 1111 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1112 | + } |
|
| 1113 | + } |
|
| 1114 | + return $this->_active_status; |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * pretty_active_status |
|
| 1120 | + * |
|
| 1121 | + * @access public |
|
| 1122 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1123 | + * @return mixed void|string |
|
| 1124 | + * @throws EE_Error |
|
| 1125 | + */ |
|
| 1126 | + public function pretty_active_status($echo = true) |
|
| 1127 | + { |
|
| 1128 | + $active_status = $this->get_active_status(); |
|
| 1129 | + $status = '<span class="ee-status event-active-status-' |
|
| 1130 | + . $active_status |
|
| 1131 | + . '">' |
|
| 1132 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1133 | + . '</span>'; |
|
| 1134 | + if ($echo) { |
|
| 1135 | + echo $status; |
|
| 1136 | + return ''; |
|
| 1137 | + } |
|
| 1138 | + return $status; |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * @return bool|int |
|
| 1144 | + * @throws EE_Error |
|
| 1145 | + */ |
|
| 1146 | + public function get_number_of_tickets_sold() |
|
| 1147 | + { |
|
| 1148 | + $tkt_sold = 0; |
|
| 1149 | + if (! $this->ID()) { |
|
| 1150 | + return 0; |
|
| 1151 | + } |
|
| 1152 | + $datetimes = $this->datetimes(); |
|
| 1153 | + foreach ($datetimes as $datetime) { |
|
| 1154 | + if ($datetime instanceof EE_Datetime) { |
|
| 1155 | + $tkt_sold += $datetime->sold(); |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | + return $tkt_sold; |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + |
|
| 1162 | + /** |
|
| 1163 | + * This just returns a count of all the registrations for this event |
|
| 1164 | + * |
|
| 1165 | + * @access public |
|
| 1166 | + * @return int |
|
| 1167 | + * @throws EE_Error |
|
| 1168 | + */ |
|
| 1169 | + public function get_count_of_all_registrations() |
|
| 1170 | + { |
|
| 1171 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + |
|
| 1175 | + /** |
|
| 1176 | + * This returns the ticket with the earliest start time that is |
|
| 1177 | + * available for this event (across all datetimes attached to the event) |
|
| 1178 | + * |
|
| 1179 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1180 | + * @throws EE_Error |
|
| 1181 | + */ |
|
| 1182 | + public function get_ticket_with_earliest_start_time() |
|
| 1183 | + { |
|
| 1184 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1185 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1186 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + |
|
| 1190 | + /** |
|
| 1191 | + * This returns the ticket with the latest end time that is available |
|
| 1192 | + * for this event (across all datetimes attached to the event) |
|
| 1193 | + * |
|
| 1194 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1195 | + * @throws EE_Error |
|
| 1196 | + */ |
|
| 1197 | + public function get_ticket_with_latest_end_time() |
|
| 1198 | + { |
|
| 1199 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1200 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1201 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + |
|
| 1205 | + /** |
|
| 1206 | + * This returns the number of different ticket types currently on sale for this event. |
|
| 1207 | + * |
|
| 1208 | + * @return int |
|
| 1209 | + * @throws EE_Error |
|
| 1210 | + */ |
|
| 1211 | + public function countTicketsOnSale() |
|
| 1212 | + { |
|
| 1213 | + $where = array( |
|
| 1214 | + 'Datetime.EVT_ID' => $this->ID(), |
|
| 1215 | + 'TKT_start_date' => array('<', time()), |
|
| 1216 | + 'TKT_end_date' => array('>', time()), |
|
| 1217 | + ); |
|
| 1218 | + return EEM_Ticket::instance()->count(array($where)); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * This returns whether there are any tickets on sale for this event. |
|
| 1224 | + * |
|
| 1225 | + * @return bool true = YES tickets on sale. |
|
| 1226 | + * @throws EE_Error |
|
| 1227 | + */ |
|
| 1228 | + public function tickets_on_sale() |
|
| 1229 | + { |
|
| 1230 | + return $this->countTicketsOnSale() > 0; |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + |
|
| 1234 | + /** |
|
| 1235 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1236 | + * to check for an external URL first |
|
| 1237 | + * |
|
| 1238 | + * @return string |
|
| 1239 | + * @throws EE_Error |
|
| 1240 | + */ |
|
| 1241 | + public function get_permalink() |
|
| 1242 | + { |
|
| 1243 | + if ($this->external_url()) { |
|
| 1244 | + return $this->external_url(); |
|
| 1245 | + } |
|
| 1246 | + return parent::get_permalink(); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + |
|
| 1250 | + /** |
|
| 1251 | + * Gets the first term for 'espresso_event_categories' we can find |
|
| 1252 | + * |
|
| 1253 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1254 | + * @return EE_Base_Class|EE_Term|null |
|
| 1255 | + * @throws EE_Error |
|
| 1256 | + */ |
|
| 1257 | + public function first_event_category($query_params = array()) |
|
| 1258 | + { |
|
| 1259 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1260 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1261 | + return EEM_Term::instance()->get_one($query_params); |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + |
|
| 1265 | + /** |
|
| 1266 | + * Gets all terms for 'espresso_event_categories' we can find |
|
| 1267 | + * |
|
| 1268 | + * @param array $query_params |
|
| 1269 | + * @return EE_Base_Class[]|EE_Term[] |
|
| 1270 | + * @throws EE_Error |
|
| 1271 | + */ |
|
| 1272 | + public function get_all_event_categories($query_params = array()) |
|
| 1273 | + { |
|
| 1274 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1275 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1276 | + return EEM_Term::instance()->get_all($query_params); |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * Adds a question group to this event |
|
| 1282 | + * |
|
| 1283 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1284 | + * @param bool $for_primary if true, the question group will be added for the primary |
|
| 1285 | + * registrant, if false will be added for others. default: false |
|
| 1286 | + * @return EE_Base_Class|EE_Question_Group |
|
| 1287 | + * @throws EE_Error |
|
| 1288 | + * @throws InvalidArgumentException |
|
| 1289 | + * @throws InvalidDataTypeException |
|
| 1290 | + * @throws InvalidInterfaceException |
|
| 1291 | + * @throws ReflectionException |
|
| 1292 | + */ |
|
| 1293 | + public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1294 | + { |
|
| 1295 | + // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
| 1296 | + // That's in EE_HABTM_Relation::add_relation_to(). |
|
| 1297 | + return $this->_add_relation_to( |
|
| 1298 | + $question_group_id_or_obj, |
|
| 1299 | + 'Question_Group', |
|
| 1300 | + [ |
|
| 1301 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
| 1302 | + ] |
|
| 1303 | + ); |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * Removes a question group from the event |
|
| 1309 | + * |
|
| 1310 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1311 | + * @param bool $for_primary if true, the question group will be removed from the primary |
|
| 1312 | + * registrant, if false will be removed from others. default: false |
|
| 1313 | + * @return EE_Base_Class|EE_Question_Group |
|
| 1314 | + * @throws EE_Error |
|
| 1315 | + * @throws InvalidArgumentException |
|
| 1316 | + * @throws ReflectionException |
|
| 1317 | + * @throws InvalidDataTypeException |
|
| 1318 | + * @throws InvalidInterfaceException |
|
| 1319 | + */ |
|
| 1320 | + public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1321 | + { |
|
| 1322 | + // If the question group is used for the other type (primary or additional) |
|
| 1323 | + // then just update it. If not, delete it outright. |
|
| 1324 | + $existing_relation = $this->get_first_related( |
|
| 1325 | + 'Event_Question_Group', |
|
| 1326 | + [ |
|
| 1327 | + [ |
|
| 1328 | + 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
| 1329 | + ] |
|
| 1330 | + ] |
|
| 1331 | + ); |
|
| 1332 | + $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
| 1333 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
| 1334 | + if ($existing_relation->get($other_field) === false) { |
|
| 1335 | + // Delete it. It's now no longer for primary or additional question groups. |
|
| 1336 | + return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
| 1337 | + } |
|
| 1338 | + // Just update it. They'll still use this question group for the other category |
|
| 1339 | + $existing_relation->save( |
|
| 1340 | + [ |
|
| 1341 | + $field_to_update => false |
|
| 1342 | + ] |
|
| 1343 | + ); |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + |
|
| 1347 | + /** |
|
| 1348 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1349 | + * |
|
| 1350 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1351 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1352 | + * @throws EE_Error |
|
| 1353 | + */ |
|
| 1354 | + public function question_groups($query_params = array()) |
|
| 1355 | + { |
|
| 1356 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1357 | + return $this->get_many_related('Question_Group', $query_params); |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + |
|
| 1361 | + /** |
|
| 1362 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1363 | + * |
|
| 1364 | + * @see EEI_Visual_Representation for comments |
|
| 1365 | + * @return string |
|
| 1366 | + */ |
|
| 1367 | + public function get_icon() |
|
| 1368 | + { |
|
| 1369 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1375 | + * |
|
| 1376 | + * @see EEI_Admin_Links for comments |
|
| 1377 | + * @return string |
|
| 1378 | + * @throws EE_Error |
|
| 1379 | + */ |
|
| 1380 | + public function get_admin_details_link() |
|
| 1381 | + { |
|
| 1382 | + return $this->get_admin_edit_link(); |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + |
|
| 1386 | + /** |
|
| 1387 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1388 | + * |
|
| 1389 | + * @see EEI_Admin_Links for comments |
|
| 1390 | + * @return string |
|
| 1391 | + * @throws EE_Error |
|
| 1392 | + */ |
|
| 1393 | + public function get_admin_edit_link() |
|
| 1394 | + { |
|
| 1395 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1396 | + array( |
|
| 1397 | + 'page' => 'espresso_events', |
|
| 1398 | + 'action' => 'edit', |
|
| 1399 | + 'post' => $this->ID(), |
|
| 1400 | + ), |
|
| 1401 | + admin_url('admin.php') |
|
| 1402 | + ); |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1408 | + * |
|
| 1409 | + * @see EEI_Admin_Links for comments |
|
| 1410 | + * @return string |
|
| 1411 | + */ |
|
| 1412 | + public function get_admin_settings_link() |
|
| 1413 | + { |
|
| 1414 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1415 | + array( |
|
| 1416 | + 'page' => 'espresso_events', |
|
| 1417 | + 'action' => 'default_event_settings', |
|
| 1418 | + ), |
|
| 1419 | + admin_url('admin.php') |
|
| 1420 | + ); |
|
| 1421 | + } |
|
| 1422 | + |
|
| 1423 | + |
|
| 1424 | + /** |
|
| 1425 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1426 | + * |
|
| 1427 | + * @see EEI_Admin_Links for comments |
|
| 1428 | + * @return string |
|
| 1429 | + */ |
|
| 1430 | + public function get_admin_overview_link() |
|
| 1431 | + { |
|
| 1432 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1433 | + array( |
|
| 1434 | + 'page' => 'espresso_events', |
|
| 1435 | + 'action' => 'default', |
|
| 1436 | + ), |
|
| 1437 | + admin_url('admin.php') |
|
| 1438 | + ); |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + |
|
| 1442 | + /** |
|
| 1443 | + * @return string|null |
|
| 1444 | + * @throws EE_Error |
|
| 1445 | + * @throws ReflectionException |
|
| 1446 | + */ |
|
| 1447 | + public function registrationFormUuid(): ?string |
|
| 1448 | + { |
|
| 1449 | + return $this->get('FSC_UUID'); |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * Gets all the form sections for this event |
|
| 1455 | + * |
|
| 1456 | + * @return EE_Base_Class[]|EE_Form_Section[] |
|
| 1457 | + * @throws EE_Error |
|
| 1458 | + * @throws ReflectionException |
|
| 1459 | + */ |
|
| 1460 | + public function registrationForm() |
|
| 1461 | + { |
|
| 1462 | + $FSC_UUID = $this->registrationFormUuid(); |
|
| 1463 | + |
|
| 1464 | + if (empty($FSC_UUID)) { |
|
| 1465 | + return []; |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + return EEM_Form_Section::instance()->get_all([ |
|
| 1469 | + [ |
|
| 1470 | + 'OR' => [ |
|
| 1471 | + 'FSC_UUID' => $FSC_UUID, // top level form |
|
| 1472 | + 'FSC_belongsTo' => $FSC_UUID, // child form sections |
|
| 1473 | + ] |
|
| 1474 | + ], |
|
| 1475 | + 'order_by' => ['FSC_order' => 'ASC'], |
|
| 1476 | + ]); |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + |
|
| 1480 | + /** |
|
| 1481 | + * @param string $UUID |
|
| 1482 | + * @throws EE_Error |
|
| 1483 | + */ |
|
| 1484 | + public function setRegistrationFormUuid(string $UUID): void |
|
| 1485 | + { |
|
| 1486 | + if (! Cuid::isCuid($UUID)) { |
|
| 1487 | + throw new InvalidArgumentException( |
|
| 1488 | + sprintf( |
|
| 1489 | + /* translators: 1: UUID value, 2: UUID generator function. */ |
|
| 1490 | + esc_html__( |
|
| 1491 | + 'The supplied UUID "%1$s" is invalid or missing. Please use %2$s to generate a valid one.', |
|
| 1492 | + 'event_espresso' |
|
| 1493 | + ), |
|
| 1494 | + $UUID, |
|
| 1495 | + '`Cuid::cuid()`' |
|
| 1496 | + ) |
|
| 1497 | + ); |
|
| 1498 | + } |
|
| 1499 | + $this->set('FSC_UUID', $UUID); |
|
| 1500 | + } |
|
| 1501 | 1501 | } |
@@ -12,543 +12,542 @@ |
||
| 12 | 12 | class EEH_Venue_View extends EEH_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @access private |
|
| 17 | - * @var EE_Venue |
|
| 18 | - */ |
|
| 19 | - private static $_venue = null; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * get_venue |
|
| 25 | - * attempts to retrieve an EE_Venue object any way it can |
|
| 26 | - * |
|
| 27 | - * @access public |
|
| 28 | - * @param int $VNU_ID |
|
| 29 | - * @param bool $look_in_event |
|
| 30 | - * @param bool $privacy_check Defaults to true. |
|
| 31 | - * When false, means even if the venue is private we return it regardless of access. |
|
| 32 | - * @param bool $password_check |
|
| 33 | - * @return \EE_Venue|null |
|
| 34 | - */ |
|
| 35 | - public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true) |
|
| 36 | - { |
|
| 37 | - $VNU_ID = absint($VNU_ID); |
|
| 38 | - // do we already have the Venue you are looking for? |
|
| 39 | - if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
| 40 | - // If the Venue ID matches $VNU_ID, return the venue. |
|
| 41 | - if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
| 42 | - return EEH_Venue_View::_get_venue($privacy_check); |
|
| 43 | - } |
|
| 44 | - // If the Venue ID does not match, try pulling a venue using $VNU_ID. |
|
| 45 | - $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 46 | - if ($venue instanceof EE_Venue) { |
|
| 47 | - EEH_Venue_View::$_venue = $venue; |
|
| 48 | - return EEH_Venue_View::_get_venue($privacy_check); |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - // international newspaper? |
|
| 52 | - global $post; |
|
| 53 | - if ($post instanceof WP_Post) { |
|
| 54 | - switch ($post->post_type) { |
|
| 55 | - // if this is being called from an EE_Venue post, |
|
| 56 | - // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
|
| 57 | - // then we can try to just grab the attached EE_Venue object |
|
| 58 | - case 'espresso_venues': |
|
| 59 | - // the post already contains the related EE_Venue object AND one of the following is TRUE: |
|
| 60 | - // the requested Venue ID matches the post ID OR... |
|
| 61 | - // there was no specific Venue ID requested |
|
| 62 | - if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
| 63 | - // use existing related EE_Venue object |
|
| 64 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
| 65 | - } elseif ($VNU_ID) { |
|
| 66 | - // there WAS a specific Venue ID requested, but it's NOT the current post object |
|
| 67 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 68 | - } else { |
|
| 69 | - // no specific Venue ID requested, so use post ID to generate EE_Venue object |
|
| 70 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
| 71 | - } |
|
| 72 | - break; |
|
| 73 | - |
|
| 74 | - case 'espresso_events': |
|
| 75 | - if ($look_in_event) { |
|
| 76 | - // grab the events related venues |
|
| 77 | - $venues = EEH_Venue_View::get_event_venues(); |
|
| 78 | - // make sure the result is an array |
|
| 79 | - $venues = is_array($venues) ? $venues : [$venues]; |
|
| 80 | - // do we have an ID for a specific venue? |
|
| 81 | - if ($VNU_ID) { |
|
| 82 | - // loop thru the related venues |
|
| 83 | - foreach ($venues as $venue) { |
|
| 84 | - if ($venue instanceof EE_Venue) { |
|
| 85 | - // until we find the venue we're looking for |
|
| 86 | - if ($venue->ID() == $VNU_ID) { |
|
| 87 | - EEH_Venue_View::$_venue = $venue; |
|
| 88 | - break; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - // no venue ID ? |
|
| 93 | - // then the global post is an events post and this function was called with no argument |
|
| 94 | - } else { |
|
| 95 | - // just grab the first related event venue |
|
| 96 | - EEH_Venue_View::$_venue = reset($venues); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - break; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
|
| 103 | - if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
| 104 | - // sigh... pull it from the db |
|
| 105 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 106 | - } |
|
| 107 | - return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * return a single venue |
|
| 114 | - * |
|
| 115 | - * @param bool $privacy_check Defaults to true. |
|
| 116 | - * When false, means even if the venue is private we return it regardless of access. |
|
| 117 | - * @param bool $password_check |
|
| 118 | - * @return EE_Venue |
|
| 119 | - */ |
|
| 120 | - protected static function _get_venue($privacy_check = true, $password_check = true) |
|
| 121 | - { |
|
| 122 | - // check for private venues. |
|
| 123 | - if ( |
|
| 124 | - EEH_Venue_View::$_venue instanceof EE_Venue |
|
| 125 | - && EEH_Venue_View::$_venue->status() == 'private' |
|
| 126 | - && $privacy_check |
|
| 127 | - && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
| 128 | - ) { |
|
| 129 | - return null; |
|
| 130 | - } |
|
| 131 | - // check for password protected venues |
|
| 132 | - if ( |
|
| 133 | - EEH_Venue_View::$_venue instanceof EE_Venue |
|
| 134 | - && $password_check |
|
| 135 | - && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
| 136 | - ) { |
|
| 137 | - return null; |
|
| 138 | - } |
|
| 139 | - return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * get_event_venues |
|
| 146 | - * |
|
| 147 | - * @access public |
|
| 148 | - * @return EE_Venue[] |
|
| 149 | - */ |
|
| 150 | - public static function get_event_venues() |
|
| 151 | - { |
|
| 152 | - global $post; |
|
| 153 | - if ($post->post_type == 'espresso_events') { |
|
| 154 | - if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
| 155 | - return $post->EE_Event->venue(); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - return array(); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Simply checks whether a venue for the given ID (or the internally derived venue is private). |
|
| 166 | - * |
|
| 167 | - * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but is not |
|
| 168 | - * private. So it is important to do explicit boolean checks when using this conditional. |
|
| 169 | - * |
|
| 170 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
| 171 | - * |
|
| 172 | - * @return bool|null |
|
| 173 | - */ |
|
| 174 | - public static function is_venue_private($VNU_ID = false) |
|
| 175 | - { |
|
| 176 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
|
| 177 | - if (! $venue instanceof EE_Venue) { |
|
| 178 | - return null; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return $venue->status() == 'private' ? true : false; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * returns true or false if a venue is password protected or not |
|
| 189 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
| 190 | - * @return bool |
|
| 191 | - */ |
|
| 192 | - public static function is_venue_password_protected($VNU_ID = false) |
|
| 193 | - { |
|
| 194 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
| 195 | - if ( |
|
| 196 | - $venue instanceof EE_Venue |
|
| 197 | - && post_password_required($venue->ID()) |
|
| 198 | - ) { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * If a venue is password protected, this will return the password form for gaining access |
|
| 208 | - * returns an empty string otherwise |
|
| 209 | - |
|
| 210 | - * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
| 211 | - * |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public static function password_protected_venue_form($VNU_ID = false) |
|
| 215 | - { |
|
| 216 | - $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
| 217 | - if ( |
|
| 218 | - $venue instanceof EE_Venue |
|
| 219 | - && post_password_required($venue->ID()) |
|
| 220 | - ) { |
|
| 221 | - return get_the_password_form($venue->ID()); |
|
| 222 | - } |
|
| 223 | - return ''; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * venue_description |
|
| 230 | - * |
|
| 231 | - * @access public |
|
| 232 | - * @param int $VNU_ID |
|
| 233 | - * @return string |
|
| 234 | - */ |
|
| 235 | - public static function venue_description($VNU_ID = 0) |
|
| 236 | - { |
|
| 237 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 238 | - if ($venue instanceof EE_Venue) { |
|
| 239 | - return $venue->get_pretty('VNU_desc'); |
|
| 240 | - } |
|
| 241 | - return ''; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * venue_excerpt |
|
| 248 | - * |
|
| 249 | - * @access public |
|
| 250 | - * @param int $VNU_ID |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public static function venue_excerpt($VNU_ID = 0) |
|
| 254 | - { |
|
| 255 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 256 | - if ($venue instanceof EE_Venue) { |
|
| 257 | - $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
|
| 258 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '…'); |
|
| 259 | - return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
| 260 | - } |
|
| 261 | - return ''; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * venue_categories |
|
| 268 | - * |
|
| 269 | - * @access public |
|
| 270 | - * @param int $VNU_ID |
|
| 271 | - * @param bool $hide_uncategorized |
|
| 272 | - * @return string |
|
| 273 | - */ |
|
| 274 | - public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true) |
|
| 275 | - { |
|
| 276 | - $category_links = array(); |
|
| 277 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 278 | - if ($venue instanceof EE_Venue) { |
|
| 279 | - // get category terms |
|
| 280 | - if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
| 281 | - // loop thru terms and create links |
|
| 282 | - foreach ($venue_categories as $term) { |
|
| 283 | - $url = get_term_link($term, 'espresso_venue_categories'); |
|
| 284 | - if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) { |
|
| 285 | - $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - return implode(', ', $category_links); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * venue_address |
|
| 297 | - * |
|
| 298 | - * @access public |
|
| 299 | - * @param string $type |
|
| 300 | - * @param int $VNU_ID |
|
| 301 | - * @param bool $use_schema |
|
| 302 | - * @param bool $add_wrapper |
|
| 303 | - * @return string |
|
| 304 | - */ |
|
| 305 | - public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) |
|
| 306 | - { |
|
| 307 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 308 | - if ($venue instanceof EE_Venue) { |
|
| 309 | - return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
| 310 | - } |
|
| 311 | - return ''; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * venue_has_address |
|
| 318 | - * |
|
| 319 | - * @access public |
|
| 320 | - * @param int $VNU_ID |
|
| 321 | - * @return bool|string |
|
| 322 | - */ |
|
| 323 | - public static function venue_has_address($VNU_ID = 0) |
|
| 324 | - { |
|
| 325 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 326 | - if ($venue instanceof EE_Venue) { |
|
| 327 | - return EEH_Address::format($venue, 'inline', false, false); |
|
| 328 | - } |
|
| 329 | - return false; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * venue_name |
|
| 336 | - * |
|
| 337 | - * @access public |
|
| 338 | - * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website |
|
| 339 | - * @param int $VNU_ID |
|
| 340 | - * @return string |
|
| 341 | - */ |
|
| 342 | - public static function venue_name($link_to = 'details', $VNU_ID = 0) |
|
| 343 | - { |
|
| 344 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 345 | - if ($venue instanceof EE_Venue) { |
|
| 346 | - $venue_name = apply_filters( |
|
| 347 | - 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
|
| 348 | - EEH_Venue_View::is_venue_private() |
|
| 349 | - ? EEH_Venue_View::$_venue->name() . " " . __('(Private)', 'event_espresso') |
|
| 350 | - : EEH_Venue_View::$_venue->name(), |
|
| 351 | - EEH_Venue_View::$_venue |
|
| 352 | - ); |
|
| 353 | - $venue_name = EEH_Schema::name($venue_name); |
|
| 354 | - |
|
| 355 | - // if venue is trashed then ignore the "link to" setting because the venue is trashed. |
|
| 356 | - if ($venue->get('status') == 'trash') { |
|
| 357 | - $link_to = ''; |
|
| 358 | - } |
|
| 359 | - switch ($link_to) { |
|
| 360 | - case 'details': |
|
| 361 | - return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
| 362 | - break; |
|
| 363 | - |
|
| 364 | - case 'website': |
|
| 365 | - return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
| 366 | - break; |
|
| 367 | - |
|
| 368 | - default: |
|
| 369 | - return $venue_name; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - return ''; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * venue_details_link |
|
| 379 | - * |
|
| 380 | - * @access public |
|
| 381 | - * @param int $VNU_ID |
|
| 382 | - * @param string $text |
|
| 383 | - * @return string |
|
| 384 | - */ |
|
| 385 | - public static function venue_details_link($VNU_ID = 0, $text = '') |
|
| 386 | - { |
|
| 387 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 388 | - if ($venue instanceof EE_Venue) { |
|
| 389 | - return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
| 390 | - } |
|
| 391 | - return ''; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * venue_website_link |
|
| 398 | - * |
|
| 399 | - * @access public |
|
| 400 | - * @param int $VNU_ID |
|
| 401 | - * @param string $text |
|
| 402 | - * @return string |
|
| 403 | - */ |
|
| 404 | - public static function venue_website_link($VNU_ID = 0, $text = '') |
|
| 405 | - { |
|
| 406 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 407 | - if ($venue instanceof EE_Venue) { |
|
| 408 | - $url = $venue->venue_url(); |
|
| 409 | - $text = ! empty($text) ? $text : $url; |
|
| 410 | - return ! empty($url) ? EEH_Schema::url($url, $text) : ''; |
|
| 411 | - } |
|
| 412 | - return ''; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * venue_phone |
|
| 419 | - * |
|
| 420 | - * @access public |
|
| 421 | - * @param int $VNU_ID |
|
| 422 | - * @return string |
|
| 423 | - */ |
|
| 424 | - public static function venue_phone($VNU_ID = 0) |
|
| 425 | - { |
|
| 426 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 427 | - if ($venue instanceof EE_Venue) { |
|
| 428 | - return EEH_Schema::telephone($venue->phone()); |
|
| 429 | - } |
|
| 430 | - return ''; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * venue_gmap |
|
| 437 | - * |
|
| 438 | - * @access public |
|
| 439 | - * @param int $VNU_ID |
|
| 440 | - * @param bool|string $map_ID a unique identifier for this map |
|
| 441 | - * @param array $gmap map options |
|
| 442 | - * @return string |
|
| 443 | - */ |
|
| 444 | - public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = array()) |
|
| 445 | - { |
|
| 446 | - |
|
| 447 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 448 | - if ($venue instanceof EE_Venue) { |
|
| 449 | - // check for global espresso_events post and use it's ID if no map_ID is set |
|
| 450 | - global $post; |
|
| 451 | - $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
| 452 | - // grab map settings |
|
| 453 | - $map_cfg = EE_Registry::instance()->CFG->map_settings; |
|
| 454 | - // are maps enabled ? |
|
| 455 | - if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
| 456 | - $details_page = is_single(); |
|
| 457 | - $options = array(); |
|
| 458 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
| 459 | - |
|
| 460 | - $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
|
| 461 | - |
|
| 462 | - $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width; |
|
| 463 | - $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
| 464 | - |
|
| 465 | - $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height; |
|
| 466 | - $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
| 467 | - |
|
| 468 | - $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom; |
|
| 469 | - $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
| 470 | - |
|
| 471 | - $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav; |
|
| 472 | - $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display']; |
|
| 473 | - ; |
|
| 474 | - |
|
| 475 | - $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
|
| 476 | - $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
| 477 | - |
|
| 478 | - $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
|
| 479 | - $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
| 480 | - |
|
| 481 | - $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
|
| 482 | - $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
| 483 | - |
|
| 484 | - $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
| 485 | - |
|
| 486 | - return EEH_Maps::google_map($options); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - return ''; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Gets the HTML to display a static map of the venue |
|
| 495 | - * @param EE_Venue $venue |
|
| 496 | - * @param array $atts like EEH_Maps::google_map_link |
|
| 497 | - * @return string |
|
| 498 | - */ |
|
| 499 | - public static function espresso_google_static_map(EE_Venue $venue, $atts = array()) |
|
| 500 | - { |
|
| 501 | - $state = $venue->state_obj(); |
|
| 502 | - $country = $venue->country_obj(); |
|
| 503 | - $atts = shortcode_atts( |
|
| 504 | - array( |
|
| 505 | - 'id' => $venue->ID(), |
|
| 506 | - 'address' => $venue->get('VNU_address'), |
|
| 507 | - 'city' => $venue->get('VNU_city'), |
|
| 508 | - 'state' => $state instanceof EE_State ? $state->name() : '', |
|
| 509 | - 'zip' => $venue->get('VNU_zip'), |
|
| 510 | - 'country' => $country instanceof EE_Country ? $country->name() : '', |
|
| 511 | - 'type' => 'map', |
|
| 512 | - 'map_w' => 200, |
|
| 513 | - 'map_h' => 200 |
|
| 514 | - ), |
|
| 515 | - $atts |
|
| 516 | - ); |
|
| 517 | - return EEH_Maps::google_map_link($atts); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * edit_venue_link |
|
| 524 | - * |
|
| 525 | - * @access public |
|
| 526 | - * @param int $VNU_ID |
|
| 527 | - * @param string $link |
|
| 528 | - * @param string $before |
|
| 529 | - * @param string $after |
|
| 530 | - * @return string |
|
| 531 | - */ |
|
| 532 | - public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>') |
|
| 533 | - { |
|
| 534 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 535 | - if ($venue instanceof EE_Venue) { |
|
| 536 | - // can the user edit this post ? |
|
| 537 | - if (current_user_can('edit_post', $venue->ID())) { |
|
| 538 | - // set link text |
|
| 539 | - $link = ! empty($link) ? $link : __('edit this venue', 'event_espresso'); |
|
| 540 | - // generate nonce |
|
| 541 | - $nonce = wp_create_nonce('edit_nonce'); |
|
| 542 | - // generate url to venue editor for this venue |
|
| 543 | - $url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php')); |
|
| 544 | - // get edit CPT text |
|
| 545 | - $post_type_obj = get_post_type_object('espresso_venues'); |
|
| 546 | - // build final link html |
|
| 547 | - $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>'; |
|
| 548 | - // put it all together |
|
| 549 | - return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - return ''; |
|
| 553 | - } |
|
| 15 | + /** |
|
| 16 | + * @access private |
|
| 17 | + * @var EE_Venue |
|
| 18 | + */ |
|
| 19 | + private static $_venue = null; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * get_venue |
|
| 25 | + * attempts to retrieve an EE_Venue object any way it can |
|
| 26 | + * |
|
| 27 | + * @access public |
|
| 28 | + * @param int $VNU_ID |
|
| 29 | + * @param bool $look_in_event |
|
| 30 | + * @param bool $privacy_check Defaults to true. |
|
| 31 | + * When false, means even if the venue is private we return it regardless of access. |
|
| 32 | + * @param bool $password_check |
|
| 33 | + * @return \EE_Venue|null |
|
| 34 | + */ |
|
| 35 | + public static function get_venue($VNU_ID = 0, $look_in_event = true, $privacy_check = true, $password_check = true) |
|
| 36 | + { |
|
| 37 | + $VNU_ID = absint($VNU_ID); |
|
| 38 | + // do we already have the Venue you are looking for? |
|
| 39 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
| 40 | + // If the Venue ID matches $VNU_ID, return the venue. |
|
| 41 | + if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
| 42 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
| 43 | + } |
|
| 44 | + // If the Venue ID does not match, try pulling a venue using $VNU_ID. |
|
| 45 | + $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 46 | + if ($venue instanceof EE_Venue) { |
|
| 47 | + EEH_Venue_View::$_venue = $venue; |
|
| 48 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + // international newspaper? |
|
| 52 | + global $post; |
|
| 53 | + if ($post instanceof WP_Post) { |
|
| 54 | + switch ($post->post_type) { |
|
| 55 | + // if this is being called from an EE_Venue post, |
|
| 56 | + // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
|
| 57 | + // then we can try to just grab the attached EE_Venue object |
|
| 58 | + case 'espresso_venues': |
|
| 59 | + // the post already contains the related EE_Venue object AND one of the following is TRUE: |
|
| 60 | + // the requested Venue ID matches the post ID OR... |
|
| 61 | + // there was no specific Venue ID requested |
|
| 62 | + if (isset($post->EE_Venue) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
| 63 | + // use existing related EE_Venue object |
|
| 64 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
| 65 | + } elseif ($VNU_ID) { |
|
| 66 | + // there WAS a specific Venue ID requested, but it's NOT the current post object |
|
| 67 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 68 | + } else { |
|
| 69 | + // no specific Venue ID requested, so use post ID to generate EE_Venue object |
|
| 70 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
| 71 | + } |
|
| 72 | + break; |
|
| 73 | + |
|
| 74 | + case 'espresso_events': |
|
| 75 | + if ($look_in_event) { |
|
| 76 | + // grab the events related venues |
|
| 77 | + $venues = EEH_Venue_View::get_event_venues(); |
|
| 78 | + // make sure the result is an array |
|
| 79 | + $venues = is_array($venues) ? $venues : [$venues]; |
|
| 80 | + // do we have an ID for a specific venue? |
|
| 81 | + if ($VNU_ID) { |
|
| 82 | + // loop thru the related venues |
|
| 83 | + foreach ($venues as $venue) { |
|
| 84 | + if ($venue instanceof EE_Venue) { |
|
| 85 | + // until we find the venue we're looking for |
|
| 86 | + if ($venue->ID() == $VNU_ID) { |
|
| 87 | + EEH_Venue_View::$_venue = $venue; |
|
| 88 | + break; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + // no venue ID ? |
|
| 93 | + // then the global post is an events post and this function was called with no argument |
|
| 94 | + } else { |
|
| 95 | + // just grab the first related event venue |
|
| 96 | + EEH_Venue_View::$_venue = reset($venues); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + break; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
|
| 103 | + if (! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
| 104 | + // sigh... pull it from the db |
|
| 105 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 106 | + } |
|
| 107 | + return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * return a single venue |
|
| 114 | + * |
|
| 115 | + * @param bool $privacy_check Defaults to true. |
|
| 116 | + * When false, means even if the venue is private we return it regardless of access. |
|
| 117 | + * @param bool $password_check |
|
| 118 | + * @return EE_Venue |
|
| 119 | + */ |
|
| 120 | + protected static function _get_venue($privacy_check = true, $password_check = true) |
|
| 121 | + { |
|
| 122 | + // check for private venues. |
|
| 123 | + if ( |
|
| 124 | + EEH_Venue_View::$_venue instanceof EE_Venue |
|
| 125 | + && EEH_Venue_View::$_venue->status() == 'private' |
|
| 126 | + && $privacy_check |
|
| 127 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
| 128 | + ) { |
|
| 129 | + return null; |
|
| 130 | + } |
|
| 131 | + // check for password protected venues |
|
| 132 | + if ( |
|
| 133 | + EEH_Venue_View::$_venue instanceof EE_Venue |
|
| 134 | + && $password_check |
|
| 135 | + && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
| 136 | + ) { |
|
| 137 | + return null; |
|
| 138 | + } |
|
| 139 | + return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * get_event_venues |
|
| 146 | + * |
|
| 147 | + * @access public |
|
| 148 | + * @return EE_Venue[] |
|
| 149 | + */ |
|
| 150 | + public static function get_event_venues() |
|
| 151 | + { |
|
| 152 | + global $post; |
|
| 153 | + if ($post->post_type == 'espresso_events') { |
|
| 154 | + if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
| 155 | + return $post->EE_Event->venue(); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + return array(); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Simply checks whether a venue for the given ID (or the internally derived venue is private). |
|
| 166 | + * |
|
| 167 | + * Note: This will return true if its private, null if the venue doesn't exist, and false, if the venue exists but is not |
|
| 168 | + * private. So it is important to do explicit boolean checks when using this conditional. |
|
| 169 | + * |
|
| 170 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
| 171 | + * |
|
| 172 | + * @return bool|null |
|
| 173 | + */ |
|
| 174 | + public static function is_venue_private($VNU_ID = false) |
|
| 175 | + { |
|
| 176 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
|
| 177 | + if (! $venue instanceof EE_Venue) { |
|
| 178 | + return null; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return $venue->status() == 'private' ? true : false; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * returns true or false if a venue is password protected or not |
|
| 189 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
| 190 | + * @return bool |
|
| 191 | + */ |
|
| 192 | + public static function is_venue_password_protected($VNU_ID = false) |
|
| 193 | + { |
|
| 194 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
| 195 | + if ( |
|
| 196 | + $venue instanceof EE_Venue |
|
| 197 | + && post_password_required($venue->ID()) |
|
| 198 | + ) { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * If a venue is password protected, this will return the password form for gaining access |
|
| 208 | + * returns an empty string otherwise |
|
| 209 | + * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
|
| 210 | + * |
|
| 211 | + * @return string |
|
| 212 | + */ |
|
| 213 | + public static function password_protected_venue_form($VNU_ID = false) |
|
| 214 | + { |
|
| 215 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
| 216 | + if ( |
|
| 217 | + $venue instanceof EE_Venue |
|
| 218 | + && post_password_required($venue->ID()) |
|
| 219 | + ) { |
|
| 220 | + return get_the_password_form($venue->ID()); |
|
| 221 | + } |
|
| 222 | + return ''; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * venue_description |
|
| 229 | + * |
|
| 230 | + * @access public |
|
| 231 | + * @param int $VNU_ID |
|
| 232 | + * @return string |
|
| 233 | + */ |
|
| 234 | + public static function venue_description($VNU_ID = 0) |
|
| 235 | + { |
|
| 236 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 237 | + if ($venue instanceof EE_Venue) { |
|
| 238 | + return $venue->get_pretty('VNU_desc'); |
|
| 239 | + } |
|
| 240 | + return ''; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * venue_excerpt |
|
| 247 | + * |
|
| 248 | + * @access public |
|
| 249 | + * @param int $VNU_ID |
|
| 250 | + * @return string |
|
| 251 | + */ |
|
| 252 | + public static function venue_excerpt($VNU_ID = 0) |
|
| 253 | + { |
|
| 254 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 255 | + if ($venue instanceof EE_Venue) { |
|
| 256 | + $excerpt = $venue->excerpt() != null && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
|
| 257 | + $venue_link = ' ' . EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso') . '…'); |
|
| 258 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '') . $venue_link : ''; |
|
| 259 | + } |
|
| 260 | + return ''; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * venue_categories |
|
| 267 | + * |
|
| 268 | + * @access public |
|
| 269 | + * @param int $VNU_ID |
|
| 270 | + * @param bool $hide_uncategorized |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public static function venue_categories($VNU_ID = 0, $hide_uncategorized = true) |
|
| 274 | + { |
|
| 275 | + $category_links = array(); |
|
| 276 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 277 | + if ($venue instanceof EE_Venue) { |
|
| 278 | + // get category terms |
|
| 279 | + if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
| 280 | + // loop thru terms and create links |
|
| 281 | + foreach ($venue_categories as $term) { |
|
| 282 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
| 283 | + if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) { |
|
| 284 | + $category_links[] = '<a href="' . esc_url($url) . '" rel="tag">' . $term->name . '</a> '; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + return implode(', ', $category_links); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * venue_address |
|
| 296 | + * |
|
| 297 | + * @access public |
|
| 298 | + * @param string $type |
|
| 299 | + * @param int $VNU_ID |
|
| 300 | + * @param bool $use_schema |
|
| 301 | + * @param bool $add_wrapper |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) |
|
| 305 | + { |
|
| 306 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 307 | + if ($venue instanceof EE_Venue) { |
|
| 308 | + return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
| 309 | + } |
|
| 310 | + return ''; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * venue_has_address |
|
| 317 | + * |
|
| 318 | + * @access public |
|
| 319 | + * @param int $VNU_ID |
|
| 320 | + * @return bool|string |
|
| 321 | + */ |
|
| 322 | + public static function venue_has_address($VNU_ID = 0) |
|
| 323 | + { |
|
| 324 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 325 | + if ($venue instanceof EE_Venue) { |
|
| 326 | + return EEH_Address::format($venue, 'inline', false, false); |
|
| 327 | + } |
|
| 328 | + return false; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * venue_name |
|
| 335 | + * |
|
| 336 | + * @access public |
|
| 337 | + * @param string $link_to - options( details, website, none ) whether to turn Venue name into a clickable link to the Venue's details page or website |
|
| 338 | + * @param int $VNU_ID |
|
| 339 | + * @return string |
|
| 340 | + */ |
|
| 341 | + public static function venue_name($link_to = 'details', $VNU_ID = 0) |
|
| 342 | + { |
|
| 343 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 344 | + if ($venue instanceof EE_Venue) { |
|
| 345 | + $venue_name = apply_filters( |
|
| 346 | + 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
|
| 347 | + EEH_Venue_View::is_venue_private() |
|
| 348 | + ? EEH_Venue_View::$_venue->name() . " " . __('(Private)', 'event_espresso') |
|
| 349 | + : EEH_Venue_View::$_venue->name(), |
|
| 350 | + EEH_Venue_View::$_venue |
|
| 351 | + ); |
|
| 352 | + $venue_name = EEH_Schema::name($venue_name); |
|
| 353 | + |
|
| 354 | + // if venue is trashed then ignore the "link to" setting because the venue is trashed. |
|
| 355 | + if ($venue->get('status') == 'trash') { |
|
| 356 | + $link_to = ''; |
|
| 357 | + } |
|
| 358 | + switch ($link_to) { |
|
| 359 | + case 'details': |
|
| 360 | + return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
| 361 | + break; |
|
| 362 | + |
|
| 363 | + case 'website': |
|
| 364 | + return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
| 365 | + break; |
|
| 366 | + |
|
| 367 | + default: |
|
| 368 | + return $venue_name; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + return ''; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * venue_details_link |
|
| 378 | + * |
|
| 379 | + * @access public |
|
| 380 | + * @param int $VNU_ID |
|
| 381 | + * @param string $text |
|
| 382 | + * @return string |
|
| 383 | + */ |
|
| 384 | + public static function venue_details_link($VNU_ID = 0, $text = '') |
|
| 385 | + { |
|
| 386 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 387 | + if ($venue instanceof EE_Venue) { |
|
| 388 | + return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
| 389 | + } |
|
| 390 | + return ''; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * venue_website_link |
|
| 397 | + * |
|
| 398 | + * @access public |
|
| 399 | + * @param int $VNU_ID |
|
| 400 | + * @param string $text |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + public static function venue_website_link($VNU_ID = 0, $text = '') |
|
| 404 | + { |
|
| 405 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 406 | + if ($venue instanceof EE_Venue) { |
|
| 407 | + $url = $venue->venue_url(); |
|
| 408 | + $text = ! empty($text) ? $text : $url; |
|
| 409 | + return ! empty($url) ? EEH_Schema::url($url, $text) : ''; |
|
| 410 | + } |
|
| 411 | + return ''; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * venue_phone |
|
| 418 | + * |
|
| 419 | + * @access public |
|
| 420 | + * @param int $VNU_ID |
|
| 421 | + * @return string |
|
| 422 | + */ |
|
| 423 | + public static function venue_phone($VNU_ID = 0) |
|
| 424 | + { |
|
| 425 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 426 | + if ($venue instanceof EE_Venue) { |
|
| 427 | + return EEH_Schema::telephone($venue->phone()); |
|
| 428 | + } |
|
| 429 | + return ''; |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * venue_gmap |
|
| 436 | + * |
|
| 437 | + * @access public |
|
| 438 | + * @param int $VNU_ID |
|
| 439 | + * @param bool|string $map_ID a unique identifier for this map |
|
| 440 | + * @param array $gmap map options |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + public static function venue_gmap($VNU_ID = 0, $map_ID = false, $gmap = array()) |
|
| 444 | + { |
|
| 445 | + |
|
| 446 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 447 | + if ($venue instanceof EE_Venue) { |
|
| 448 | + // check for global espresso_events post and use it's ID if no map_ID is set |
|
| 449 | + global $post; |
|
| 450 | + $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
| 451 | + // grab map settings |
|
| 452 | + $map_cfg = EE_Registry::instance()->CFG->map_settings; |
|
| 453 | + // are maps enabled ? |
|
| 454 | + if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
| 455 | + $details_page = is_single(); |
|
| 456 | + $options = array(); |
|
| 457 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
| 458 | + |
|
| 459 | + $options['location'] = EEH_Address::format($venue, 'inline', false, false); |
|
| 460 | + |
|
| 461 | + $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width; |
|
| 462 | + $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
| 463 | + |
|
| 464 | + $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height; |
|
| 465 | + $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
| 466 | + |
|
| 467 | + $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom; |
|
| 468 | + $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
| 469 | + |
|
| 470 | + $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav; |
|
| 471 | + $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display']; |
|
| 472 | + ; |
|
| 473 | + |
|
| 474 | + $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
|
| 475 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
| 476 | + |
|
| 477 | + $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
|
| 478 | + $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
| 479 | + |
|
| 480 | + $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
|
| 481 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
| 482 | + |
|
| 483 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
| 484 | + |
|
| 485 | + return EEH_Maps::google_map($options); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + return ''; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Gets the HTML to display a static map of the venue |
|
| 494 | + * @param EE_Venue $venue |
|
| 495 | + * @param array $atts like EEH_Maps::google_map_link |
|
| 496 | + * @return string |
|
| 497 | + */ |
|
| 498 | + public static function espresso_google_static_map(EE_Venue $venue, $atts = array()) |
|
| 499 | + { |
|
| 500 | + $state = $venue->state_obj(); |
|
| 501 | + $country = $venue->country_obj(); |
|
| 502 | + $atts = shortcode_atts( |
|
| 503 | + array( |
|
| 504 | + 'id' => $venue->ID(), |
|
| 505 | + 'address' => $venue->get('VNU_address'), |
|
| 506 | + 'city' => $venue->get('VNU_city'), |
|
| 507 | + 'state' => $state instanceof EE_State ? $state->name() : '', |
|
| 508 | + 'zip' => $venue->get('VNU_zip'), |
|
| 509 | + 'country' => $country instanceof EE_Country ? $country->name() : '', |
|
| 510 | + 'type' => 'map', |
|
| 511 | + 'map_w' => 200, |
|
| 512 | + 'map_h' => 200 |
|
| 513 | + ), |
|
| 514 | + $atts |
|
| 515 | + ); |
|
| 516 | + return EEH_Maps::google_map_link($atts); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * edit_venue_link |
|
| 523 | + * |
|
| 524 | + * @access public |
|
| 525 | + * @param int $VNU_ID |
|
| 526 | + * @param string $link |
|
| 527 | + * @param string $before |
|
| 528 | + * @param string $after |
|
| 529 | + * @return string |
|
| 530 | + */ |
|
| 531 | + public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>') |
|
| 532 | + { |
|
| 533 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 534 | + if ($venue instanceof EE_Venue) { |
|
| 535 | + // can the user edit this post ? |
|
| 536 | + if (current_user_can('edit_post', $venue->ID())) { |
|
| 537 | + // set link text |
|
| 538 | + $link = ! empty($link) ? $link : __('edit this venue', 'event_espresso'); |
|
| 539 | + // generate nonce |
|
| 540 | + $nonce = wp_create_nonce('edit_nonce'); |
|
| 541 | + // generate url to venue editor for this venue |
|
| 542 | + $url = add_query_arg(array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url('admin.php')); |
|
| 543 | + // get edit CPT text |
|
| 544 | + $post_type_obj = get_post_type_object('espresso_venues'); |
|
| 545 | + // build final link html |
|
| 546 | + $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr($post_type_obj->labels->edit_item) . '">' . $link . '</a>'; |
|
| 547 | + // put it all together |
|
| 548 | + return $before . apply_filters('edit_post_link', $link, $venue->ID()) . $after; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + return ''; |
|
| 552 | + } |
|
| 554 | 553 | } |