@@ -28,749 +28,749 @@ |
||
| 28 | 28 | { |
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var EE_Datetime_Offset_Fix_Form |
|
| 33 | - */ |
|
| 34 | - protected $datetime_fix_offset_form; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - protected function _init_page_props() |
|
| 39 | - { |
|
| 40 | - $this->page_slug = EE_MAINTENANCE_PG_SLUG; |
|
| 41 | - $this->page_label = EE_MAINTENANCE_LABEL; |
|
| 42 | - $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL; |
|
| 43 | - $this->_admin_base_path = EE_MAINTENANCE_ADMIN; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - protected function _ajax_hooks() |
|
| 49 | - { |
|
| 50 | - add_action('wp_ajax_migration_step', array($this, 'migration_step')); |
|
| 51 | - add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran')); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - protected function _define_page_props() |
|
| 57 | - { |
|
| 58 | - $this->_admin_page_title = EE_MAINTENANCE_LABEL; |
|
| 59 | - $this->_labels = array( |
|
| 60 | - 'buttons' => array( |
|
| 61 | - 'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'), |
|
| 62 | - 'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'), |
|
| 63 | - ), |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - protected function _set_page_routes() |
|
| 70 | - { |
|
| 71 | - $this->_page_routes = array( |
|
| 72 | - 'default' => array( |
|
| 73 | - 'func' => '_maintenance', |
|
| 74 | - 'capability' => 'manage_options', |
|
| 75 | - ), |
|
| 76 | - 'change_maintenance_level' => array( |
|
| 77 | - 'func' => '_change_maintenance_level', |
|
| 78 | - 'capability' => 'manage_options', |
|
| 79 | - 'noheader' => true, |
|
| 80 | - ), |
|
| 81 | - 'system_status' => array( |
|
| 82 | - 'func' => '_system_status', |
|
| 83 | - 'capability' => 'manage_options', |
|
| 84 | - ), |
|
| 85 | - 'download_system_status' => array( |
|
| 86 | - 'func' => '_download_system_status', |
|
| 87 | - 'capability' => 'manage_options', |
|
| 88 | - 'noheader' => true, |
|
| 89 | - ), |
|
| 90 | - 'send_migration_crash_report' => array( |
|
| 91 | - 'func' => '_send_migration_crash_report', |
|
| 92 | - 'capability' => 'manage_options', |
|
| 93 | - 'noheader' => true, |
|
| 94 | - ), |
|
| 95 | - 'confirm_migration_crash_report_sent' => array( |
|
| 96 | - 'func' => '_confirm_migration_crash_report_sent', |
|
| 97 | - 'capability' => 'manage_options', |
|
| 98 | - ), |
|
| 99 | - 'data_reset' => array( |
|
| 100 | - 'func' => '_data_reset_and_delete', |
|
| 101 | - 'capability' => 'manage_options', |
|
| 102 | - ), |
|
| 103 | - 'reset_db' => array( |
|
| 104 | - 'func' => '_reset_db', |
|
| 105 | - 'capability' => 'manage_options', |
|
| 106 | - 'noheader' => true, |
|
| 107 | - 'args' => array('nuke_old_ee4_data' => true), |
|
| 108 | - ), |
|
| 109 | - 'start_with_fresh_ee4_db' => array( |
|
| 110 | - 'func' => '_reset_db', |
|
| 111 | - 'capability' => 'manage_options', |
|
| 112 | - 'noheader' => true, |
|
| 113 | - 'args' => array('nuke_old_ee4_data' => false), |
|
| 114 | - ), |
|
| 115 | - 'delete_db' => array( |
|
| 116 | - 'func' => '_delete_db', |
|
| 117 | - 'capability' => 'manage_options', |
|
| 118 | - 'noheader' => true, |
|
| 119 | - ), |
|
| 120 | - 'rerun_migration_from_ee3' => array( |
|
| 121 | - 'func' => '_rerun_migration_from_ee3', |
|
| 122 | - 'capability' => 'manage_options', |
|
| 123 | - 'noheader' => true, |
|
| 124 | - ), |
|
| 125 | - 'reset_reservations' => array( |
|
| 126 | - 'func' => '_reset_reservations', |
|
| 127 | - 'capability' => 'manage_options', |
|
| 128 | - 'noheader' => true, |
|
| 129 | - ), |
|
| 130 | - 'reset_capabilities' => array( |
|
| 131 | - 'func' => '_reset_capabilities', |
|
| 132 | - 'capability' => 'manage_options', |
|
| 133 | - 'noheader' => true, |
|
| 134 | - ), |
|
| 135 | - 'reattempt_migration' => array( |
|
| 136 | - 'func' => '_reattempt_migration', |
|
| 137 | - 'capability' => 'manage_options', |
|
| 138 | - 'noheader' => true, |
|
| 139 | - ), |
|
| 140 | - 'datetime_tools' => array( |
|
| 141 | - 'func' => '_datetime_tools', |
|
| 142 | - 'capability' => 'manage_options' |
|
| 143 | - ), |
|
| 144 | - 'run_datetime_offset_fix' => array( |
|
| 145 | - 'func' => '_apply_datetime_offset', |
|
| 146 | - 'noheader' => true, |
|
| 147 | - 'headers_sent_route' => 'datetime_tools', |
|
| 148 | - 'capability' => 'manage_options' |
|
| 149 | - ) |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - protected function _set_page_config() |
|
| 156 | - { |
|
| 157 | - $this->_page_config = array( |
|
| 158 | - 'default' => array( |
|
| 159 | - 'nav' => array( |
|
| 160 | - 'label' => esc_html__('Maintenance', 'event_espresso'), |
|
| 161 | - 'order' => 10, |
|
| 162 | - ), |
|
| 163 | - 'require_nonce' => false, |
|
| 164 | - ), |
|
| 165 | - 'data_reset' => array( |
|
| 166 | - 'nav' => array( |
|
| 167 | - 'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
|
| 168 | - 'order' => 20, |
|
| 169 | - ), |
|
| 170 | - 'require_nonce' => false, |
|
| 171 | - ), |
|
| 172 | - 'datetime_tools' => array( |
|
| 173 | - 'nav' => array( |
|
| 174 | - 'label' => esc_html__('Datetime Utilities', 'event_espresso'), |
|
| 175 | - 'order' => 25 |
|
| 176 | - ), |
|
| 177 | - 'require_nonce' => false, |
|
| 178 | - ), |
|
| 179 | - 'system_status' => array( |
|
| 180 | - 'nav' => array( |
|
| 181 | - 'label' => esc_html__("System Information", "event_espresso"), |
|
| 182 | - 'order' => 30, |
|
| 183 | - ), |
|
| 184 | - 'require_nonce' => false, |
|
| 185 | - ), |
|
| 186 | - ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * default maintenance page. If we're in maintenance mode level 2, then we need to show |
|
| 193 | - * the migration scripts and all that UI. |
|
| 194 | - */ |
|
| 195 | - public function _maintenance() |
|
| 196 | - { |
|
| 197 | - //it all depends if we're in maintenance model level 1 (frontend-only) or |
|
| 198 | - //level 2 (everything except maintenance page) |
|
| 199 | - try { |
|
| 200 | - //get the current maintenance level and check if |
|
| 201 | - //we are removed |
|
| 202 | - $mm = EE_Maintenance_Mode::instance()->level(); |
|
| 203 | - $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 204 | - if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) { |
|
| 205 | - //we just took the site out of maintenance mode, so notify the user. |
|
| 206 | - //unfortunately this message appears to be echoed on the NEXT page load... |
|
| 207 | - //oh well, we should really be checking for this on addon deactivation anyways |
|
| 208 | - EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required', |
|
| 209 | - 'event_espresso')); |
|
| 210 | - $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false); |
|
| 211 | - } |
|
| 212 | - //in case an exception is thrown while trying to handle migrations |
|
| 213 | - switch (EE_Maintenance_Mode::instance()->level()) { |
|
| 214 | - case EE_Maintenance_Mode::level_0_not_in_maintenance: |
|
| 215 | - case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
| 216 | - $show_maintenance_switch = true; |
|
| 217 | - $show_backup_db_text = false; |
|
| 218 | - $show_migration_progress = false; |
|
| 219 | - $script_names = array(); |
|
| 220 | - $addons_should_be_upgraded_first = false; |
|
| 221 | - break; |
|
| 222 | - case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
| 223 | - $show_maintenance_switch = false; |
|
| 224 | - $show_migration_progress = true; |
|
| 225 | - if (isset($this->_req_data['continue_migration'])) { |
|
| 226 | - $show_backup_db_text = false; |
|
| 227 | - } else { |
|
| 228 | - $show_backup_db_text = true; |
|
| 229 | - } |
|
| 230 | - $scripts_needing_to_run = EE_Data_Migration_Manager::instance() |
|
| 231 | - ->check_for_applicable_data_migration_scripts(); |
|
| 232 | - $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating(); |
|
| 233 | - $script_names = array(); |
|
| 234 | - $current_script = null; |
|
| 235 | - foreach ($scripts_needing_to_run as $script) { |
|
| 236 | - if ($script instanceof EE_Data_Migration_Script_Base) { |
|
| 237 | - if ( ! $current_script) { |
|
| 238 | - $current_script = $script; |
|
| 239 | - $current_script->migration_page_hooks(); |
|
| 240 | - } |
|
| 241 | - $script_names[] = $script->pretty_name(); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - break; |
|
| 245 | - } |
|
| 246 | - $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
| 247 | - $exception_thrown = false; |
|
| 248 | - } catch (EE_Error $e) { |
|
| 249 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
| 250 | - //now, just so we can display the page correctly, make a error migration script stage object |
|
| 251 | - //and also put the error on it. It only persists for the duration of this request |
|
| 252 | - $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
| 253 | - $most_recent_migration->add_error($e->getMessage()); |
|
| 254 | - $exception_thrown = true; |
|
| 255 | - } |
|
| 256 | - $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set(); |
|
| 257 | - $current_db_state = str_replace('.decaf', '', $current_db_state); |
|
| 258 | - if ($exception_thrown |
|
| 259 | - || ($most_recent_migration |
|
| 260 | - && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
| 261 | - && $most_recent_migration->is_broken() |
|
| 262 | - ) |
|
| 263 | - ) { |
|
| 264 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
| 265 | - $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
|
| 266 | - $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
|
| 267 | - 'success' => '0', |
|
| 268 | - ), EE_MAINTENANCE_ADMIN_URL); |
|
| 269 | - } elseif ($addons_should_be_upgraded_first) { |
|
| 270 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
| 271 | - } else { |
|
| 272 | - if ($most_recent_migration |
|
| 273 | - && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
| 274 | - && $most_recent_migration->can_continue() |
|
| 275 | - ) { |
|
| 276 | - $show_backup_db_text = false; |
|
| 277 | - $show_continue_current_migration_script = true; |
|
| 278 | - $show_most_recent_migration = true; |
|
| 279 | - } elseif (isset($this->_req_data['continue_migration'])) { |
|
| 280 | - $show_most_recent_migration = true; |
|
| 281 | - $show_continue_current_migration_script = false; |
|
| 282 | - } else { |
|
| 283 | - $show_most_recent_migration = false; |
|
| 284 | - $show_continue_current_migration_script = false; |
|
| 285 | - } |
|
| 286 | - if (isset($current_script)) { |
|
| 287 | - $migrates_to = $current_script->migrates_to_version(); |
|
| 288 | - $plugin_slug = $migrates_to['slug']; |
|
| 289 | - $new_version = $migrates_to['version']; |
|
| 290 | - $this->_template_args = array_merge($this->_template_args, array( |
|
| 291 | - 'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"), |
|
| 292 | - isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug), |
|
| 293 | - 'next_db_state' => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'), |
|
| 294 | - $new_version, $plugin_slug) : null, |
|
| 295 | - )); |
|
| 296 | - } else { |
|
| 297 | - $this->_template_args['current_db_state'] = null; |
|
| 298 | - $this->_template_args['next_db_state'] = null; |
|
| 299 | - } |
|
| 300 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
| 301 | - $this->_template_args = array_merge( |
|
| 302 | - $this->_template_args, |
|
| 303 | - array( |
|
| 304 | - 'show_most_recent_migration' => $show_most_recent_migration, |
|
| 305 | - //flag for showing the most recent migration's status and/or errors |
|
| 306 | - 'show_migration_progress' => $show_migration_progress, |
|
| 307 | - //flag for showing the option to run migrations and see their progress |
|
| 308 | - 'show_backup_db_text' => $show_backup_db_text, |
|
| 309 | - //flag for showing text telling the user to backup their DB |
|
| 310 | - 'show_maintenance_switch' => $show_maintenance_switch, |
|
| 311 | - //flag for showing the option to change maintenance mode between levels 0 and 1 |
|
| 312 | - 'script_names' => $script_names, |
|
| 313 | - //array of names of scripts that have run |
|
| 314 | - 'show_continue_current_migration_script' => $show_continue_current_migration_script, |
|
| 315 | - //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
|
| 316 | - 'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
| 317 | - EE_MAINTENANCE_ADMIN_URL), |
|
| 318 | - 'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
| 319 | - EE_MAINTENANCE_ADMIN_URL), |
|
| 320 | - 'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'), |
|
| 321 | - EE_MAINTENANCE_ADMIN_URL), |
|
| 322 | - 'ultimate_db_state' => sprintf(__("EE%s", 'event_espresso'), |
|
| 323 | - espresso_version()), |
|
| 324 | - ) |
|
| 325 | - ); |
|
| 326 | - //make sure we have the form fields helper available. It usually is, but sometimes it isn't |
|
| 327 | - //localize script stuff |
|
| 328 | - wp_localize_script('ee-maintenance', 'ee_maintenance', array( |
|
| 329 | - 'migrating' => esc_html__("Updating Database...", "event_espresso"), |
|
| 330 | - 'next' => esc_html__("Next", "event_espresso"), |
|
| 331 | - 'fatal_error' => esc_html__("A Fatal Error Has Occurred", "event_espresso"), |
|
| 332 | - 'click_next_when_ready' => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed", |
|
| 333 | - "event_espresso"), |
|
| 334 | - 'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
|
| 335 | - 'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
|
| 336 | - 'status_completed' => EE_Data_Migration_Manager::status_completed, |
|
| 337 | - )); |
|
| 338 | - } |
|
| 339 | - $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
|
| 340 | - //now render the migration options part, and put it in a variable |
|
| 341 | - $migration_options_template_file = apply_filters( |
|
| 342 | - 'FHEE__ee_migration_page__migration_options_template', |
|
| 343 | - EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
| 344 | - ); |
|
| 345 | - $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
|
| 346 | - $this->_template_args['migration_options_html'] = $migration_options_html; |
|
| 347 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 348 | - $this->_template_args, true); |
|
| 349 | - $this->display_admin_page_with_sidebar(); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * returns JSON and executes another step of the currently-executing data migration (called via ajax) |
|
| 356 | - */ |
|
| 357 | - public function migration_step() |
|
| 358 | - { |
|
| 359 | - $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request(); |
|
| 360 | - $this->_return_json(); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Can be used by js when it notices a response with HTML in it in order |
|
| 367 | - * to log the malformed response |
|
| 368 | - */ |
|
| 369 | - public function add_error_to_migrations_ran() |
|
| 370 | - { |
|
| 371 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']); |
|
| 372 | - $this->_template_args['data'] = array('ok' => true); |
|
| 373 | - $this->_return_json(); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * changes the maintenance level, provided there are still no migration scripts that should run |
|
| 380 | - */ |
|
| 381 | - public function _change_maintenance_level() |
|
| 382 | - { |
|
| 383 | - $new_level = absint($this->_req_data['maintenance_mode_level']); |
|
| 384 | - if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
| 385 | - EE_Maintenance_Mode::instance()->set_maintenance_level($new_level); |
|
| 386 | - $success = true; |
|
| 387 | - } else { |
|
| 388 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 389 | - $success = false; |
|
| 390 | - } |
|
| 391 | - $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * a tab with options for resetting and/or deleting EE data |
|
| 398 | - * |
|
| 399 | - * @throws \EE_Error |
|
| 400 | - * @throws \DomainException |
|
| 401 | - */ |
|
| 402 | - public function _data_reset_and_delete() |
|
| 403 | - { |
|
| 404 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
| 405 | - $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
|
| 406 | - 'reset_reservations', |
|
| 407 | - 'reset_reservations', |
|
| 408 | - array(), |
|
| 409 | - 'button button-primary', |
|
| 410 | - '', |
|
| 411 | - false |
|
| 412 | - ); |
|
| 413 | - $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
|
| 414 | - 'reset_capabilities', |
|
| 415 | - 'reset_capabilities', |
|
| 416 | - array(), |
|
| 417 | - 'button button-primary', |
|
| 418 | - '', |
|
| 419 | - false |
|
| 420 | - ); |
|
| 421 | - $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 422 | - array('action' => 'delete_db'), |
|
| 423 | - EE_MAINTENANCE_ADMIN_URL |
|
| 424 | - ); |
|
| 425 | - $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 426 | - array('action' => 'reset_db'), |
|
| 427 | - EE_MAINTENANCE_ADMIN_URL |
|
| 428 | - ); |
|
| 429 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 430 | - $this->_template_path, |
|
| 431 | - $this->_template_args, |
|
| 432 | - true |
|
| 433 | - ); |
|
| 434 | - $this->display_admin_page_with_sidebar(); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - protected function _reset_reservations() |
|
| 440 | - { |
|
| 441 | - if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
| 442 | - EE_Error::add_success( |
|
| 443 | - __( |
|
| 444 | - 'Ticket and datetime reserved counts have been successfully reset.', |
|
| 445 | - 'event_espresso' |
|
| 446 | - ) |
|
| 447 | - ); |
|
| 448 | - } else { |
|
| 449 | - EE_Error::add_success( |
|
| 450 | - __( |
|
| 451 | - 'Ticket and datetime reserved counts were correct and did not need resetting.', |
|
| 452 | - 'event_espresso' |
|
| 453 | - ) |
|
| 454 | - ); |
|
| 455 | - } |
|
| 456 | - $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - protected function _reset_capabilities() |
|
| 462 | - { |
|
| 463 | - EE_Registry::instance()->CAP->init_caps(true); |
|
| 464 | - EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.', |
|
| 465 | - 'event_espresso')); |
|
| 466 | - $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * resets the DMSs so we can attempt to continue migrating after a fatal error |
|
| 473 | - * (only a good idea when someone has somehow tried ot fix whatever caused |
|
| 474 | - * the fatal error in teh first place) |
|
| 475 | - */ |
|
| 476 | - protected function _reattempt_migration() |
|
| 477 | - { |
|
| 478 | - EE_Data_Migration_Manager::instance()->reattempt(); |
|
| 479 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), true); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * shows the big ol' System Information page |
|
| 486 | - */ |
|
| 487 | - public function _system_status() |
|
| 488 | - { |
|
| 489 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
| 490 | - $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
|
| 491 | - $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 492 | - array( |
|
| 493 | - 'action' => 'download_system_status', |
|
| 494 | - ), |
|
| 495 | - EE_MAINTENANCE_ADMIN_URL |
|
| 496 | - ); |
|
| 497 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 498 | - $this->_template_args, true); |
|
| 499 | - $this->display_admin_page_with_sidebar(); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Downloads an HTML file of the system status that can be easily stored or emailed |
|
| 504 | - */ |
|
| 505 | - public function _download_system_status() |
|
| 506 | - { |
|
| 507 | - $status_info = EEM_System_Status::instance()->get_system_stati(); |
|
| 508 | - header( 'Content-Disposition: attachment' ); |
|
| 509 | - header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
|
| 510 | - echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
|
| 511 | - echo "<h1>System Information for " . site_url() . "</h1>"; |
|
| 512 | - echo EEH_Template::layout_array_as_table( $status_info ); |
|
| 513 | - die; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - public function _send_migration_crash_report() |
|
| 519 | - { |
|
| 520 | - $from = $this->_req_data['from']; |
|
| 521 | - $from_name = $this->_req_data['from_name']; |
|
| 522 | - $body = $this->_req_data['body']; |
|
| 523 | - try { |
|
| 524 | - $success = wp_mail(EE_SUPPORT_EMAIL, |
|
| 525 | - 'Migration Crash Report', |
|
| 526 | - $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
| 527 | - array( |
|
| 528 | - "from:$from_name<$from>", |
|
| 529 | - // 'content-type:text/html charset=UTF-8' |
|
| 530 | - )); |
|
| 531 | - } catch (Exception $e) { |
|
| 532 | - $success = false; |
|
| 533 | - } |
|
| 534 | - $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"), |
|
| 535 | - esc_html__("sent", "event_espresso"), |
|
| 536 | - array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')); |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - public function _confirm_migration_crash_report_sent() |
|
| 542 | - { |
|
| 543 | - try { |
|
| 544 | - $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
| 545 | - } catch (EE_Error $e) { |
|
| 546 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
| 547 | - //now, just so we can display the page correctly, make a error migration script stage object |
|
| 548 | - //and also put the error on it. It only persists for the duration of this request |
|
| 549 | - $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
| 550 | - $most_recent_migration->add_error($e->getMessage()); |
|
| 551 | - } |
|
| 552 | - $success = $this->_req_data['success'] == '1' ? true : false; |
|
| 553 | - $this->_template_args['success'] = $success; |
|
| 554 | - $this->_template_args['most_recent_migration'] = $most_recent_migration; |
|
| 555 | - $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
| 556 | - EE_MAINTENANCE_ADMIN_URL); |
|
| 557 | - $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
| 558 | - EE_MAINTENANCE_ADMIN_URL); |
|
| 559 | - $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
|
| 560 | - EE_MAINTENANCE_ADMIN_URL); |
|
| 561 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
| 562 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 563 | - $this->_template_args, true); |
|
| 564 | - $this->display_admin_page_with_sidebar(); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Resets the entire EE4 database. |
|
| 571 | - * Currently basically only sets up ee4 database for a fresh install- doesn't |
|
| 572 | - * actually clean out the old wp options, or cpts (although does erase old ee table data) |
|
| 573 | - * |
|
| 574 | - * @param boolean $nuke_old_ee4_data controls whether or not we |
|
| 575 | - * destroy the old ee4 data, or just try initializing ee4 default data |
|
| 576 | - */ |
|
| 577 | - public function _reset_db($nuke_old_ee4_data = true) |
|
| 578 | - { |
|
| 579 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 580 | - if ($nuke_old_ee4_data) { |
|
| 581 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 582 | - EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
| 583 | - EEH_Activation::remove_cron_tasks(); |
|
| 584 | - } |
|
| 585 | - //make sure when we reset the registry's config that it |
|
| 586 | - //switches to using the new singleton |
|
| 587 | - EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
|
| 588 | - EE_System::instance()->initialize_db_if_no_migrations_required(true); |
|
| 589 | - EE_System::instance()->redirect_to_about_ee(); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Deletes ALL EE tables, Records, and Options from the database. |
|
| 596 | - */ |
|
| 597 | - public function _delete_db() |
|
| 598 | - { |
|
| 599 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 600 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 601 | - EEH_Activation::delete_all_espresso_tables_and_data(); |
|
| 602 | - EEH_Activation::remove_cron_tasks(); |
|
| 603 | - EEH_Activation::deactivate_event_espresso(); |
|
| 604 | - wp_safe_redirect(admin_url('plugins.php')); |
|
| 605 | - exit; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * sets up EE4 to rerun the migrations from ee3 to ee4 |
|
| 612 | - */ |
|
| 613 | - public function _rerun_migration_from_ee3() |
|
| 614 | - { |
|
| 615 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 616 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 617 | - EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
| 618 | - //set the db state to something that will require migrations |
|
| 619 | - update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
|
| 620 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance); |
|
| 621 | - $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso')); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - //none of the below group are currently used for Gateway Settings |
|
| 627 | - protected function _add_screen_options() |
|
| 628 | - { |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - protected function _add_feature_pointers() |
|
| 634 | - { |
|
| 635 | - } |
|
| 636 | - |
|
| 31 | + /** |
|
| 32 | + * @var EE_Datetime_Offset_Fix_Form |
|
| 33 | + */ |
|
| 34 | + protected $datetime_fix_offset_form; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + protected function _init_page_props() |
|
| 39 | + { |
|
| 40 | + $this->page_slug = EE_MAINTENANCE_PG_SLUG; |
|
| 41 | + $this->page_label = EE_MAINTENANCE_LABEL; |
|
| 42 | + $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL; |
|
| 43 | + $this->_admin_base_path = EE_MAINTENANCE_ADMIN; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + protected function _ajax_hooks() |
|
| 49 | + { |
|
| 50 | + add_action('wp_ajax_migration_step', array($this, 'migration_step')); |
|
| 51 | + add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran')); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + protected function _define_page_props() |
|
| 57 | + { |
|
| 58 | + $this->_admin_page_title = EE_MAINTENANCE_LABEL; |
|
| 59 | + $this->_labels = array( |
|
| 60 | + 'buttons' => array( |
|
| 61 | + 'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'), |
|
| 62 | + 'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'), |
|
| 63 | + ), |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + protected function _set_page_routes() |
|
| 70 | + { |
|
| 71 | + $this->_page_routes = array( |
|
| 72 | + 'default' => array( |
|
| 73 | + 'func' => '_maintenance', |
|
| 74 | + 'capability' => 'manage_options', |
|
| 75 | + ), |
|
| 76 | + 'change_maintenance_level' => array( |
|
| 77 | + 'func' => '_change_maintenance_level', |
|
| 78 | + 'capability' => 'manage_options', |
|
| 79 | + 'noheader' => true, |
|
| 80 | + ), |
|
| 81 | + 'system_status' => array( |
|
| 82 | + 'func' => '_system_status', |
|
| 83 | + 'capability' => 'manage_options', |
|
| 84 | + ), |
|
| 85 | + 'download_system_status' => array( |
|
| 86 | + 'func' => '_download_system_status', |
|
| 87 | + 'capability' => 'manage_options', |
|
| 88 | + 'noheader' => true, |
|
| 89 | + ), |
|
| 90 | + 'send_migration_crash_report' => array( |
|
| 91 | + 'func' => '_send_migration_crash_report', |
|
| 92 | + 'capability' => 'manage_options', |
|
| 93 | + 'noheader' => true, |
|
| 94 | + ), |
|
| 95 | + 'confirm_migration_crash_report_sent' => array( |
|
| 96 | + 'func' => '_confirm_migration_crash_report_sent', |
|
| 97 | + 'capability' => 'manage_options', |
|
| 98 | + ), |
|
| 99 | + 'data_reset' => array( |
|
| 100 | + 'func' => '_data_reset_and_delete', |
|
| 101 | + 'capability' => 'manage_options', |
|
| 102 | + ), |
|
| 103 | + 'reset_db' => array( |
|
| 104 | + 'func' => '_reset_db', |
|
| 105 | + 'capability' => 'manage_options', |
|
| 106 | + 'noheader' => true, |
|
| 107 | + 'args' => array('nuke_old_ee4_data' => true), |
|
| 108 | + ), |
|
| 109 | + 'start_with_fresh_ee4_db' => array( |
|
| 110 | + 'func' => '_reset_db', |
|
| 111 | + 'capability' => 'manage_options', |
|
| 112 | + 'noheader' => true, |
|
| 113 | + 'args' => array('nuke_old_ee4_data' => false), |
|
| 114 | + ), |
|
| 115 | + 'delete_db' => array( |
|
| 116 | + 'func' => '_delete_db', |
|
| 117 | + 'capability' => 'manage_options', |
|
| 118 | + 'noheader' => true, |
|
| 119 | + ), |
|
| 120 | + 'rerun_migration_from_ee3' => array( |
|
| 121 | + 'func' => '_rerun_migration_from_ee3', |
|
| 122 | + 'capability' => 'manage_options', |
|
| 123 | + 'noheader' => true, |
|
| 124 | + ), |
|
| 125 | + 'reset_reservations' => array( |
|
| 126 | + 'func' => '_reset_reservations', |
|
| 127 | + 'capability' => 'manage_options', |
|
| 128 | + 'noheader' => true, |
|
| 129 | + ), |
|
| 130 | + 'reset_capabilities' => array( |
|
| 131 | + 'func' => '_reset_capabilities', |
|
| 132 | + 'capability' => 'manage_options', |
|
| 133 | + 'noheader' => true, |
|
| 134 | + ), |
|
| 135 | + 'reattempt_migration' => array( |
|
| 136 | + 'func' => '_reattempt_migration', |
|
| 137 | + 'capability' => 'manage_options', |
|
| 138 | + 'noheader' => true, |
|
| 139 | + ), |
|
| 140 | + 'datetime_tools' => array( |
|
| 141 | + 'func' => '_datetime_tools', |
|
| 142 | + 'capability' => 'manage_options' |
|
| 143 | + ), |
|
| 144 | + 'run_datetime_offset_fix' => array( |
|
| 145 | + 'func' => '_apply_datetime_offset', |
|
| 146 | + 'noheader' => true, |
|
| 147 | + 'headers_sent_route' => 'datetime_tools', |
|
| 148 | + 'capability' => 'manage_options' |
|
| 149 | + ) |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + protected function _set_page_config() |
|
| 156 | + { |
|
| 157 | + $this->_page_config = array( |
|
| 158 | + 'default' => array( |
|
| 159 | + 'nav' => array( |
|
| 160 | + 'label' => esc_html__('Maintenance', 'event_espresso'), |
|
| 161 | + 'order' => 10, |
|
| 162 | + ), |
|
| 163 | + 'require_nonce' => false, |
|
| 164 | + ), |
|
| 165 | + 'data_reset' => array( |
|
| 166 | + 'nav' => array( |
|
| 167 | + 'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
|
| 168 | + 'order' => 20, |
|
| 169 | + ), |
|
| 170 | + 'require_nonce' => false, |
|
| 171 | + ), |
|
| 172 | + 'datetime_tools' => array( |
|
| 173 | + 'nav' => array( |
|
| 174 | + 'label' => esc_html__('Datetime Utilities', 'event_espresso'), |
|
| 175 | + 'order' => 25 |
|
| 176 | + ), |
|
| 177 | + 'require_nonce' => false, |
|
| 178 | + ), |
|
| 179 | + 'system_status' => array( |
|
| 180 | + 'nav' => array( |
|
| 181 | + 'label' => esc_html__("System Information", "event_espresso"), |
|
| 182 | + 'order' => 30, |
|
| 183 | + ), |
|
| 184 | + 'require_nonce' => false, |
|
| 185 | + ), |
|
| 186 | + ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * default maintenance page. If we're in maintenance mode level 2, then we need to show |
|
| 193 | + * the migration scripts and all that UI. |
|
| 194 | + */ |
|
| 195 | + public function _maintenance() |
|
| 196 | + { |
|
| 197 | + //it all depends if we're in maintenance model level 1 (frontend-only) or |
|
| 198 | + //level 2 (everything except maintenance page) |
|
| 199 | + try { |
|
| 200 | + //get the current maintenance level and check if |
|
| 201 | + //we are removed |
|
| 202 | + $mm = EE_Maintenance_Mode::instance()->level(); |
|
| 203 | + $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 204 | + if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) { |
|
| 205 | + //we just took the site out of maintenance mode, so notify the user. |
|
| 206 | + //unfortunately this message appears to be echoed on the NEXT page load... |
|
| 207 | + //oh well, we should really be checking for this on addon deactivation anyways |
|
| 208 | + EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required', |
|
| 209 | + 'event_espresso')); |
|
| 210 | + $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false); |
|
| 211 | + } |
|
| 212 | + //in case an exception is thrown while trying to handle migrations |
|
| 213 | + switch (EE_Maintenance_Mode::instance()->level()) { |
|
| 214 | + case EE_Maintenance_Mode::level_0_not_in_maintenance: |
|
| 215 | + case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
| 216 | + $show_maintenance_switch = true; |
|
| 217 | + $show_backup_db_text = false; |
|
| 218 | + $show_migration_progress = false; |
|
| 219 | + $script_names = array(); |
|
| 220 | + $addons_should_be_upgraded_first = false; |
|
| 221 | + break; |
|
| 222 | + case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
| 223 | + $show_maintenance_switch = false; |
|
| 224 | + $show_migration_progress = true; |
|
| 225 | + if (isset($this->_req_data['continue_migration'])) { |
|
| 226 | + $show_backup_db_text = false; |
|
| 227 | + } else { |
|
| 228 | + $show_backup_db_text = true; |
|
| 229 | + } |
|
| 230 | + $scripts_needing_to_run = EE_Data_Migration_Manager::instance() |
|
| 231 | + ->check_for_applicable_data_migration_scripts(); |
|
| 232 | + $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating(); |
|
| 233 | + $script_names = array(); |
|
| 234 | + $current_script = null; |
|
| 235 | + foreach ($scripts_needing_to_run as $script) { |
|
| 236 | + if ($script instanceof EE_Data_Migration_Script_Base) { |
|
| 237 | + if ( ! $current_script) { |
|
| 238 | + $current_script = $script; |
|
| 239 | + $current_script->migration_page_hooks(); |
|
| 240 | + } |
|
| 241 | + $script_names[] = $script->pretty_name(); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + break; |
|
| 245 | + } |
|
| 246 | + $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
| 247 | + $exception_thrown = false; |
|
| 248 | + } catch (EE_Error $e) { |
|
| 249 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
| 250 | + //now, just so we can display the page correctly, make a error migration script stage object |
|
| 251 | + //and also put the error on it. It only persists for the duration of this request |
|
| 252 | + $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
| 253 | + $most_recent_migration->add_error($e->getMessage()); |
|
| 254 | + $exception_thrown = true; |
|
| 255 | + } |
|
| 256 | + $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set(); |
|
| 257 | + $current_db_state = str_replace('.decaf', '', $current_db_state); |
|
| 258 | + if ($exception_thrown |
|
| 259 | + || ($most_recent_migration |
|
| 260 | + && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
| 261 | + && $most_recent_migration->is_broken() |
|
| 262 | + ) |
|
| 263 | + ) { |
|
| 264 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
| 265 | + $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
|
| 266 | + $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
|
| 267 | + 'success' => '0', |
|
| 268 | + ), EE_MAINTENANCE_ADMIN_URL); |
|
| 269 | + } elseif ($addons_should_be_upgraded_first) { |
|
| 270 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
| 271 | + } else { |
|
| 272 | + if ($most_recent_migration |
|
| 273 | + && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
| 274 | + && $most_recent_migration->can_continue() |
|
| 275 | + ) { |
|
| 276 | + $show_backup_db_text = false; |
|
| 277 | + $show_continue_current_migration_script = true; |
|
| 278 | + $show_most_recent_migration = true; |
|
| 279 | + } elseif (isset($this->_req_data['continue_migration'])) { |
|
| 280 | + $show_most_recent_migration = true; |
|
| 281 | + $show_continue_current_migration_script = false; |
|
| 282 | + } else { |
|
| 283 | + $show_most_recent_migration = false; |
|
| 284 | + $show_continue_current_migration_script = false; |
|
| 285 | + } |
|
| 286 | + if (isset($current_script)) { |
|
| 287 | + $migrates_to = $current_script->migrates_to_version(); |
|
| 288 | + $plugin_slug = $migrates_to['slug']; |
|
| 289 | + $new_version = $migrates_to['version']; |
|
| 290 | + $this->_template_args = array_merge($this->_template_args, array( |
|
| 291 | + 'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"), |
|
| 292 | + isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug), |
|
| 293 | + 'next_db_state' => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'), |
|
| 294 | + $new_version, $plugin_slug) : null, |
|
| 295 | + )); |
|
| 296 | + } else { |
|
| 297 | + $this->_template_args['current_db_state'] = null; |
|
| 298 | + $this->_template_args['next_db_state'] = null; |
|
| 299 | + } |
|
| 300 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
| 301 | + $this->_template_args = array_merge( |
|
| 302 | + $this->_template_args, |
|
| 303 | + array( |
|
| 304 | + 'show_most_recent_migration' => $show_most_recent_migration, |
|
| 305 | + //flag for showing the most recent migration's status and/or errors |
|
| 306 | + 'show_migration_progress' => $show_migration_progress, |
|
| 307 | + //flag for showing the option to run migrations and see their progress |
|
| 308 | + 'show_backup_db_text' => $show_backup_db_text, |
|
| 309 | + //flag for showing text telling the user to backup their DB |
|
| 310 | + 'show_maintenance_switch' => $show_maintenance_switch, |
|
| 311 | + //flag for showing the option to change maintenance mode between levels 0 and 1 |
|
| 312 | + 'script_names' => $script_names, |
|
| 313 | + //array of names of scripts that have run |
|
| 314 | + 'show_continue_current_migration_script' => $show_continue_current_migration_script, |
|
| 315 | + //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
|
| 316 | + 'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
| 317 | + EE_MAINTENANCE_ADMIN_URL), |
|
| 318 | + 'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
| 319 | + EE_MAINTENANCE_ADMIN_URL), |
|
| 320 | + 'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'), |
|
| 321 | + EE_MAINTENANCE_ADMIN_URL), |
|
| 322 | + 'ultimate_db_state' => sprintf(__("EE%s", 'event_espresso'), |
|
| 323 | + espresso_version()), |
|
| 324 | + ) |
|
| 325 | + ); |
|
| 326 | + //make sure we have the form fields helper available. It usually is, but sometimes it isn't |
|
| 327 | + //localize script stuff |
|
| 328 | + wp_localize_script('ee-maintenance', 'ee_maintenance', array( |
|
| 329 | + 'migrating' => esc_html__("Updating Database...", "event_espresso"), |
|
| 330 | + 'next' => esc_html__("Next", "event_espresso"), |
|
| 331 | + 'fatal_error' => esc_html__("A Fatal Error Has Occurred", "event_espresso"), |
|
| 332 | + 'click_next_when_ready' => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed", |
|
| 333 | + "event_espresso"), |
|
| 334 | + 'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
|
| 335 | + 'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
|
| 336 | + 'status_completed' => EE_Data_Migration_Manager::status_completed, |
|
| 337 | + )); |
|
| 338 | + } |
|
| 339 | + $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
|
| 340 | + //now render the migration options part, and put it in a variable |
|
| 341 | + $migration_options_template_file = apply_filters( |
|
| 342 | + 'FHEE__ee_migration_page__migration_options_template', |
|
| 343 | + EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
| 344 | + ); |
|
| 345 | + $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
|
| 346 | + $this->_template_args['migration_options_html'] = $migration_options_html; |
|
| 347 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 348 | + $this->_template_args, true); |
|
| 349 | + $this->display_admin_page_with_sidebar(); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * returns JSON and executes another step of the currently-executing data migration (called via ajax) |
|
| 356 | + */ |
|
| 357 | + public function migration_step() |
|
| 358 | + { |
|
| 359 | + $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request(); |
|
| 360 | + $this->_return_json(); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Can be used by js when it notices a response with HTML in it in order |
|
| 367 | + * to log the malformed response |
|
| 368 | + */ |
|
| 369 | + public function add_error_to_migrations_ran() |
|
| 370 | + { |
|
| 371 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']); |
|
| 372 | + $this->_template_args['data'] = array('ok' => true); |
|
| 373 | + $this->_return_json(); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * changes the maintenance level, provided there are still no migration scripts that should run |
|
| 380 | + */ |
|
| 381 | + public function _change_maintenance_level() |
|
| 382 | + { |
|
| 383 | + $new_level = absint($this->_req_data['maintenance_mode_level']); |
|
| 384 | + if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
| 385 | + EE_Maintenance_Mode::instance()->set_maintenance_level($new_level); |
|
| 386 | + $success = true; |
|
| 387 | + } else { |
|
| 388 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 389 | + $success = false; |
|
| 390 | + } |
|
| 391 | + $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * a tab with options for resetting and/or deleting EE data |
|
| 398 | + * |
|
| 399 | + * @throws \EE_Error |
|
| 400 | + * @throws \DomainException |
|
| 401 | + */ |
|
| 402 | + public function _data_reset_and_delete() |
|
| 403 | + { |
|
| 404 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
| 405 | + $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
|
| 406 | + 'reset_reservations', |
|
| 407 | + 'reset_reservations', |
|
| 408 | + array(), |
|
| 409 | + 'button button-primary', |
|
| 410 | + '', |
|
| 411 | + false |
|
| 412 | + ); |
|
| 413 | + $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
|
| 414 | + 'reset_capabilities', |
|
| 415 | + 'reset_capabilities', |
|
| 416 | + array(), |
|
| 417 | + 'button button-primary', |
|
| 418 | + '', |
|
| 419 | + false |
|
| 420 | + ); |
|
| 421 | + $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 422 | + array('action' => 'delete_db'), |
|
| 423 | + EE_MAINTENANCE_ADMIN_URL |
|
| 424 | + ); |
|
| 425 | + $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 426 | + array('action' => 'reset_db'), |
|
| 427 | + EE_MAINTENANCE_ADMIN_URL |
|
| 428 | + ); |
|
| 429 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 430 | + $this->_template_path, |
|
| 431 | + $this->_template_args, |
|
| 432 | + true |
|
| 433 | + ); |
|
| 434 | + $this->display_admin_page_with_sidebar(); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + protected function _reset_reservations() |
|
| 440 | + { |
|
| 441 | + if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
| 442 | + EE_Error::add_success( |
|
| 443 | + __( |
|
| 444 | + 'Ticket and datetime reserved counts have been successfully reset.', |
|
| 445 | + 'event_espresso' |
|
| 446 | + ) |
|
| 447 | + ); |
|
| 448 | + } else { |
|
| 449 | + EE_Error::add_success( |
|
| 450 | + __( |
|
| 451 | + 'Ticket and datetime reserved counts were correct and did not need resetting.', |
|
| 452 | + 'event_espresso' |
|
| 453 | + ) |
|
| 454 | + ); |
|
| 455 | + } |
|
| 456 | + $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + protected function _reset_capabilities() |
|
| 462 | + { |
|
| 463 | + EE_Registry::instance()->CAP->init_caps(true); |
|
| 464 | + EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.', |
|
| 465 | + 'event_espresso')); |
|
| 466 | + $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * resets the DMSs so we can attempt to continue migrating after a fatal error |
|
| 473 | + * (only a good idea when someone has somehow tried ot fix whatever caused |
|
| 474 | + * the fatal error in teh first place) |
|
| 475 | + */ |
|
| 476 | + protected function _reattempt_migration() |
|
| 477 | + { |
|
| 478 | + EE_Data_Migration_Manager::instance()->reattempt(); |
|
| 479 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), true); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * shows the big ol' System Information page |
|
| 486 | + */ |
|
| 487 | + public function _system_status() |
|
| 488 | + { |
|
| 489 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
| 490 | + $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
|
| 491 | + $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 492 | + array( |
|
| 493 | + 'action' => 'download_system_status', |
|
| 494 | + ), |
|
| 495 | + EE_MAINTENANCE_ADMIN_URL |
|
| 496 | + ); |
|
| 497 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 498 | + $this->_template_args, true); |
|
| 499 | + $this->display_admin_page_with_sidebar(); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Downloads an HTML file of the system status that can be easily stored or emailed |
|
| 504 | + */ |
|
| 505 | + public function _download_system_status() |
|
| 506 | + { |
|
| 507 | + $status_info = EEM_System_Status::instance()->get_system_stati(); |
|
| 508 | + header( 'Content-Disposition: attachment' ); |
|
| 509 | + header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
|
| 510 | + echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
|
| 511 | + echo "<h1>System Information for " . site_url() . "</h1>"; |
|
| 512 | + echo EEH_Template::layout_array_as_table( $status_info ); |
|
| 513 | + die; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + public function _send_migration_crash_report() |
|
| 519 | + { |
|
| 520 | + $from = $this->_req_data['from']; |
|
| 521 | + $from_name = $this->_req_data['from_name']; |
|
| 522 | + $body = $this->_req_data['body']; |
|
| 523 | + try { |
|
| 524 | + $success = wp_mail(EE_SUPPORT_EMAIL, |
|
| 525 | + 'Migration Crash Report', |
|
| 526 | + $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
| 527 | + array( |
|
| 528 | + "from:$from_name<$from>", |
|
| 529 | + // 'content-type:text/html charset=UTF-8' |
|
| 530 | + )); |
|
| 531 | + } catch (Exception $e) { |
|
| 532 | + $success = false; |
|
| 533 | + } |
|
| 534 | + $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"), |
|
| 535 | + esc_html__("sent", "event_espresso"), |
|
| 536 | + array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + public function _confirm_migration_crash_report_sent() |
|
| 542 | + { |
|
| 543 | + try { |
|
| 544 | + $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
| 545 | + } catch (EE_Error $e) { |
|
| 546 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
| 547 | + //now, just so we can display the page correctly, make a error migration script stage object |
|
| 548 | + //and also put the error on it. It only persists for the duration of this request |
|
| 549 | + $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
| 550 | + $most_recent_migration->add_error($e->getMessage()); |
|
| 551 | + } |
|
| 552 | + $success = $this->_req_data['success'] == '1' ? true : false; |
|
| 553 | + $this->_template_args['success'] = $success; |
|
| 554 | + $this->_template_args['most_recent_migration'] = $most_recent_migration; |
|
| 555 | + $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
| 556 | + EE_MAINTENANCE_ADMIN_URL); |
|
| 557 | + $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
| 558 | + EE_MAINTENANCE_ADMIN_URL); |
|
| 559 | + $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
|
| 560 | + EE_MAINTENANCE_ADMIN_URL); |
|
| 561 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
| 562 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
| 563 | + $this->_template_args, true); |
|
| 564 | + $this->display_admin_page_with_sidebar(); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Resets the entire EE4 database. |
|
| 571 | + * Currently basically only sets up ee4 database for a fresh install- doesn't |
|
| 572 | + * actually clean out the old wp options, or cpts (although does erase old ee table data) |
|
| 573 | + * |
|
| 574 | + * @param boolean $nuke_old_ee4_data controls whether or not we |
|
| 575 | + * destroy the old ee4 data, or just try initializing ee4 default data |
|
| 576 | + */ |
|
| 577 | + public function _reset_db($nuke_old_ee4_data = true) |
|
| 578 | + { |
|
| 579 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 580 | + if ($nuke_old_ee4_data) { |
|
| 581 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 582 | + EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
| 583 | + EEH_Activation::remove_cron_tasks(); |
|
| 584 | + } |
|
| 585 | + //make sure when we reset the registry's config that it |
|
| 586 | + //switches to using the new singleton |
|
| 587 | + EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
|
| 588 | + EE_System::instance()->initialize_db_if_no_migrations_required(true); |
|
| 589 | + EE_System::instance()->redirect_to_about_ee(); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Deletes ALL EE tables, Records, and Options from the database. |
|
| 596 | + */ |
|
| 597 | + public function _delete_db() |
|
| 598 | + { |
|
| 599 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 600 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 601 | + EEH_Activation::delete_all_espresso_tables_and_data(); |
|
| 602 | + EEH_Activation::remove_cron_tasks(); |
|
| 603 | + EEH_Activation::deactivate_event_espresso(); |
|
| 604 | + wp_safe_redirect(admin_url('plugins.php')); |
|
| 605 | + exit; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * sets up EE4 to rerun the migrations from ee3 to ee4 |
|
| 612 | + */ |
|
| 613 | + public function _rerun_migration_from_ee3() |
|
| 614 | + { |
|
| 615 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
| 616 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
| 617 | + EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
| 618 | + //set the db state to something that will require migrations |
|
| 619 | + update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
|
| 620 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance); |
|
| 621 | + $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso')); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + //none of the below group are currently used for Gateway Settings |
|
| 627 | + protected function _add_screen_options() |
|
| 628 | + { |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + protected function _add_feature_pointers() |
|
| 634 | + { |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | 637 | |
| 638 | 638 | |
| 639 | - public function admin_init() |
|
| 640 | - { |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - public function admin_notices() |
|
| 646 | - { |
|
| 647 | - } |
|
| 648 | - |
|
| 639 | + public function admin_init() |
|
| 640 | + { |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + public function admin_notices() |
|
| 646 | + { |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | 649 | |
| 650 | 650 | |
| 651 | - public function admin_footer_scripts() |
|
| 652 | - { |
|
| 653 | - } |
|
| 651 | + public function admin_footer_scripts() |
|
| 652 | + { |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | 655 | |
| 656 | 656 | |
| 657 | - public function load_scripts_styles() |
|
| 658 | - { |
|
| 659 | - wp_enqueue_script('ee_admin_js'); |
|
| 657 | + public function load_scripts_styles() |
|
| 658 | + { |
|
| 659 | + wp_enqueue_script('ee_admin_js'); |
|
| 660 | 660 | // wp_enqueue_media(); |
| 661 | 661 | // wp_enqueue_script('media-upload'); |
| 662 | - wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
|
| 663 | - EVENT_ESPRESSO_VERSION, true); |
|
| 664 | - wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
|
| 665 | - EVENT_ESPRESSO_VERSION); |
|
| 666 | - wp_enqueue_style('espresso_maintenance'); |
|
| 667 | - } |
|
| 662 | + wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
|
| 663 | + EVENT_ESPRESSO_VERSION, true); |
|
| 664 | + wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
|
| 665 | + EVENT_ESPRESSO_VERSION); |
|
| 666 | + wp_enqueue_style('espresso_maintenance'); |
|
| 667 | + } |
|
| 668 | 668 | |
| 669 | 669 | |
| 670 | 670 | |
| 671 | - public function load_scripts_styles_default() |
|
| 672 | - { |
|
| 673 | - //styles |
|
| 671 | + public function load_scripts_styles_default() |
|
| 672 | + { |
|
| 673 | + //styles |
|
| 674 | 674 | // wp_enqueue_style('ee-text-links'); |
| 675 | 675 | // //scripts |
| 676 | 676 | // wp_enqueue_script('ee-text-links'); |
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - protected function _datetime_tools() |
|
| 681 | - { |
|
| 682 | - $form_action = EE_Admin_Page::add_query_args_and_nonce( |
|
| 683 | - array( |
|
| 684 | - 'action' => 'run_datetime_offset_fix', |
|
| 685 | - 'return_action' => $this->_req_action |
|
| 686 | - ), |
|
| 687 | - EE_MAINTENANCE_ADMIN_URL |
|
| 688 | - ); |
|
| 689 | - $form = $this->_get_datetime_offset_fix_form(); |
|
| 690 | - $this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso'); |
|
| 691 | - $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post') |
|
| 692 | - . $form->get_html_and_js() |
|
| 693 | - . $form->form_close(); |
|
| 694 | - $this->display_admin_page_with_no_sidebar(); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - protected function _get_datetime_offset_fix_form() |
|
| 700 | - { |
|
| 701 | - if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) { |
|
| 702 | - $this->datetime_fix_offset_form = new EE_Form_Section_Proper( |
|
| 703 | - array( |
|
| 704 | - 'name' => 'datetime_offset_fix_option', |
|
| 705 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 706 | - 'subsections' => array( |
|
| 707 | - 'title' => new EE_Form_Section_HTML( |
|
| 708 | - EEH_HTML::h2( |
|
| 709 | - esc_html__('Datetime Offset Tool', 'event_espresso') |
|
| 710 | - ) |
|
| 711 | - ), |
|
| 712 | - 'explanation' => new EE_Form_Section_HTML( |
|
| 713 | - EEH_HTML::p( |
|
| 714 | - esc_html__( |
|
| 715 | - 'Use this tool to automatically apply the given offset to all EE_Datetime records in your database', |
|
| 716 | - 'event_espresso' |
|
| 717 | - ) |
|
| 718 | - ) |
|
| 719 | - ), |
|
| 720 | - 'offset_input' => new EE_Float_Input( |
|
| 721 | - array( |
|
| 722 | - 'html_name' => 'offset_for_datetimes', |
|
| 723 | - 'html_label_text' => esc_html__( |
|
| 724 | - 'Offset to apply (in hours):', |
|
| 725 | - 'event_espresso' |
|
| 726 | - ), |
|
| 727 | - 'min_value' => '-12', |
|
| 728 | - 'max_value' => '14', |
|
| 729 | - 'step_value' => '.25', |
|
| 730 | - 'default' => DatetimeOffsetFix::getOffset() |
|
| 731 | - ) |
|
| 732 | - ), |
|
| 733 | - 'submit' => new EE_Submit_Input( |
|
| 734 | - array( |
|
| 735 | - 'html_label_text' => '', |
|
| 736 | - 'default' => esc_html__('Apply Offset', 'event_espresso') |
|
| 737 | - ) |
|
| 738 | - ) |
|
| 739 | - ) |
|
| 740 | - ) |
|
| 741 | - ); |
|
| 742 | - } |
|
| 743 | - return $this->datetime_fix_offset_form; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Callback for the run_datetime_offset_fix route. |
|
| 749 | - * @throws EE_Error |
|
| 750 | - */ |
|
| 751 | - protected function _apply_datetime_offset() |
|
| 752 | - { |
|
| 753 | - if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 754 | - $form = $this->_get_datetime_offset_fix_form(); |
|
| 755 | - $form->receive_form_submission($this->_req_data); |
|
| 756 | - if ($form->is_valid()) { |
|
| 757 | - //save offset so batch processor can get it. |
|
| 758 | - DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input')); |
|
| 759 | - //redirect to batch tool |
|
| 760 | - wp_redirect( |
|
| 761 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 762 | - array( |
|
| 763 | - 'page' => 'espresso_batch', |
|
| 764 | - 'batch' => 'job', |
|
| 765 | - 'label' => esc_html__('Applying Offset', 'event_espresso'), |
|
| 766 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'), |
|
| 767 | - 'return_url' => urlencode(home_url(add_query_arg(null, null))), |
|
| 768 | - ), |
|
| 769 | - admin_url() |
|
| 770 | - ) |
|
| 771 | - ); |
|
| 772 | - exit; |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + protected function _datetime_tools() |
|
| 681 | + { |
|
| 682 | + $form_action = EE_Admin_Page::add_query_args_and_nonce( |
|
| 683 | + array( |
|
| 684 | + 'action' => 'run_datetime_offset_fix', |
|
| 685 | + 'return_action' => $this->_req_action |
|
| 686 | + ), |
|
| 687 | + EE_MAINTENANCE_ADMIN_URL |
|
| 688 | + ); |
|
| 689 | + $form = $this->_get_datetime_offset_fix_form(); |
|
| 690 | + $this->_admin_page_title = esc_html__('Datetime Utilities', 'event_espresso'); |
|
| 691 | + $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post') |
|
| 692 | + . $form->get_html_and_js() |
|
| 693 | + . $form->form_close(); |
|
| 694 | + $this->display_admin_page_with_no_sidebar(); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + protected function _get_datetime_offset_fix_form() |
|
| 700 | + { |
|
| 701 | + if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) { |
|
| 702 | + $this->datetime_fix_offset_form = new EE_Form_Section_Proper( |
|
| 703 | + array( |
|
| 704 | + 'name' => 'datetime_offset_fix_option', |
|
| 705 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 706 | + 'subsections' => array( |
|
| 707 | + 'title' => new EE_Form_Section_HTML( |
|
| 708 | + EEH_HTML::h2( |
|
| 709 | + esc_html__('Datetime Offset Tool', 'event_espresso') |
|
| 710 | + ) |
|
| 711 | + ), |
|
| 712 | + 'explanation' => new EE_Form_Section_HTML( |
|
| 713 | + EEH_HTML::p( |
|
| 714 | + esc_html__( |
|
| 715 | + 'Use this tool to automatically apply the given offset to all EE_Datetime records in your database', |
|
| 716 | + 'event_espresso' |
|
| 717 | + ) |
|
| 718 | + ) |
|
| 719 | + ), |
|
| 720 | + 'offset_input' => new EE_Float_Input( |
|
| 721 | + array( |
|
| 722 | + 'html_name' => 'offset_for_datetimes', |
|
| 723 | + 'html_label_text' => esc_html__( |
|
| 724 | + 'Offset to apply (in hours):', |
|
| 725 | + 'event_espresso' |
|
| 726 | + ), |
|
| 727 | + 'min_value' => '-12', |
|
| 728 | + 'max_value' => '14', |
|
| 729 | + 'step_value' => '.25', |
|
| 730 | + 'default' => DatetimeOffsetFix::getOffset() |
|
| 731 | + ) |
|
| 732 | + ), |
|
| 733 | + 'submit' => new EE_Submit_Input( |
|
| 734 | + array( |
|
| 735 | + 'html_label_text' => '', |
|
| 736 | + 'default' => esc_html__('Apply Offset', 'event_espresso') |
|
| 737 | + ) |
|
| 738 | + ) |
|
| 739 | + ) |
|
| 740 | + ) |
|
| 741 | + ); |
|
| 742 | + } |
|
| 743 | + return $this->datetime_fix_offset_form; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Callback for the run_datetime_offset_fix route. |
|
| 749 | + * @throws EE_Error |
|
| 750 | + */ |
|
| 751 | + protected function _apply_datetime_offset() |
|
| 752 | + { |
|
| 753 | + if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 754 | + $form = $this->_get_datetime_offset_fix_form(); |
|
| 755 | + $form->receive_form_submission($this->_req_data); |
|
| 756 | + if ($form->is_valid()) { |
|
| 757 | + //save offset so batch processor can get it. |
|
| 758 | + DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input')); |
|
| 759 | + //redirect to batch tool |
|
| 760 | + wp_redirect( |
|
| 761 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 762 | + array( |
|
| 763 | + 'page' => 'espresso_batch', |
|
| 764 | + 'batch' => 'job', |
|
| 765 | + 'label' => esc_html__('Applying Offset', 'event_espresso'), |
|
| 766 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'), |
|
| 767 | + 'return_url' => urlencode(home_url(add_query_arg(null, null))), |
|
| 768 | + ), |
|
| 769 | + admin_url() |
|
| 770 | + ) |
|
| 771 | + ); |
|
| 772 | + exit; |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | 776 | } //end Maintenance_Admin_Page class |
@@ -15,395 +15,395 @@ discard block |
||
| 15 | 15 | final class EE_Admin implements InterminableInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @access private |
|
| 20 | - * @var EE_Admin $_instance |
|
| 21 | - */ |
|
| 22 | - private static $_instance; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - *@ singleton method used to instantiate class object |
|
| 27 | - *@ access public |
|
| 28 | - *@ return class instance |
|
| 29 | - * |
|
| 30 | - * @throws \EE_Error |
|
| 31 | - */ |
|
| 32 | - public static function instance() |
|
| 33 | - { |
|
| 34 | - // check if class object is instantiated |
|
| 35 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 36 | - self::$_instance = new self(); |
|
| 37 | - } |
|
| 38 | - return self::$_instance; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return EE_Admin |
|
| 44 | - * @throws EE_Error |
|
| 45 | - */ |
|
| 46 | - public static function reset() |
|
| 47 | - { |
|
| 48 | - self::$_instance = null; |
|
| 49 | - return self::instance(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * class constructor |
|
| 55 | - * |
|
| 56 | - * @throws \EE_Error |
|
| 57 | - */ |
|
| 58 | - protected function __construct() |
|
| 59 | - { |
|
| 60 | - // define global EE_Admin constants |
|
| 61 | - $this->_define_all_constants(); |
|
| 62 | - // set autoloaders for our admin page classes based on included path information |
|
| 63 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 64 | - // admin hooks |
|
| 65 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 66 | - // load EE_Request_Handler early |
|
| 67 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 68 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 69 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 70 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 71 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 72 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 73 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 74 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 75 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 76 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 77 | - |
|
| 78 | - //reset Environment config (we only do this on admin page loads); |
|
| 79 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 80 | - |
|
| 81 | - do_action('AHEE__EE_Admin__loaded'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * _define_all_constants |
|
| 87 | - * define constants that are set globally for all admin pages |
|
| 88 | - * |
|
| 89 | - * @access private |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - private function _define_all_constants() |
|
| 93 | - { |
|
| 94 | - if (! defined('EE_ADMIN_URL')) { |
|
| 95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 99 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
| 106 | - * |
|
| 107 | - * @access public |
|
| 108 | - * @param array $links |
|
| 109 | - * @param string $plugin |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function filter_plugin_actions($links, $plugin) |
|
| 113 | - { |
|
| 114 | - // set $main_file in stone |
|
| 115 | - static $main_file; |
|
| 116 | - // if $main_file is not set yet |
|
| 117 | - if (! $main_file) { |
|
| 118 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 119 | - } |
|
| 120 | - if ($plugin === $main_file) { |
|
| 121 | - // compare current plugin to this one |
|
| 122 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 123 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 124 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 125 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 126 | - . '</a>'; |
|
| 127 | - array_unshift($links, $maintenance_link); |
|
| 128 | - } else { |
|
| 129 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 130 | - . esc_html__('Settings', 'event_espresso') |
|
| 131 | - . '</a>'; |
|
| 132 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 133 | - . esc_html__('Events', 'event_espresso') |
|
| 134 | - . '</a>'; |
|
| 135 | - // add before other links |
|
| 136 | - array_unshift($links, $org_settings_link, $events_link); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - return $links; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * _get_request |
|
| 145 | - * |
|
| 146 | - * @access public |
|
| 147 | - * @return void |
|
| 148 | - * @throws EE_Error |
|
| 149 | - * @throws ReflectionException |
|
| 150 | - */ |
|
| 151 | - public function get_request() |
|
| 152 | - { |
|
| 153 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 154 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * hide_admin_pages_except_maintenance_mode |
|
| 160 | - * |
|
| 161 | - * @access public |
|
| 162 | - * @param array $admin_page_folder_names |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 166 | - { |
|
| 167 | - return array( |
|
| 168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 177 | - * EE_Front_Controller's init phases have run |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @return void |
|
| 181 | - * @throws EE_Error |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - */ |
|
| 184 | - public function init() |
|
| 185 | - { |
|
| 186 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 187 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 188 | - //ok so we want to enable the entire admin |
|
| 189 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 190 | - add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 191 | - add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 192 | - //at a glance dashboard widget |
|
| 193 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 194 | - //filter for get_edit_post_link used on comments for custom post types |
|
| 195 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 196 | - } |
|
| 197 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | - try { |
|
| 200 | - //this loads the controller for the admin pages which will setup routing etc |
|
| 201 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 202 | - } catch (EE_Error $e) { |
|
| 203 | - $e->get_error(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 207 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 208 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 209 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 210 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 211 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 217 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 218 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 219 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 220 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 221 | - * |
|
| 222 | - * @param object $post_type WP post type object |
|
| 223 | - * @return object WP post type object |
|
| 224 | - */ |
|
| 225 | - public function remove_pages_from_nav_menu($post_type) |
|
| 226 | - { |
|
| 227 | - //if this isn't the "pages" post type let's get out |
|
| 228 | - if ($post_type->name !== 'page') { |
|
| 229 | - return $post_type; |
|
| 230 | - } |
|
| 231 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 232 | - |
|
| 233 | - $post_type->_default_query = array( |
|
| 234 | - 'post__not_in' => $critical_pages, |
|
| 235 | - ); |
|
| 236 | - return $post_type; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 242 | - * metaboxes get shown as well |
|
| 243 | - * |
|
| 244 | - * @access public |
|
| 245 | - * @return void |
|
| 246 | - */ |
|
| 247 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 248 | - { |
|
| 249 | - global $wp_meta_boxes, $pagenow; |
|
| 250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | - return; |
|
| 252 | - } |
|
| 253 | - $user = wp_get_current_user(); |
|
| 254 | - //has this been done yet? |
|
| 255 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 256 | - return; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 260 | - $initial_meta_boxes = apply_filters( |
|
| 261 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 262 | - array( |
|
| 263 | - 'nav-menu-theme-locations', |
|
| 264 | - 'add-page', |
|
| 265 | - 'add-custom-links', |
|
| 266 | - 'add-category', |
|
| 267 | - 'add-espresso_events', |
|
| 268 | - 'add-espresso_venues', |
|
| 269 | - 'add-espresso_event_categories', |
|
| 270 | - 'add-espresso_venue_categories', |
|
| 271 | - 'add-post-type-post', |
|
| 272 | - 'add-post-type-page', |
|
| 273 | - ) |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - if (is_array($hidden_meta_boxes)) { |
|
| 277 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | - if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | - unset($hidden_meta_boxes[$key]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | - * |
|
| 293 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | - * addons etc. |
|
| 295 | - * @access public |
|
| 296 | - * @return void |
|
| 297 | - */ |
|
| 298 | - public function register_custom_nav_menu_boxes() |
|
| 299 | - { |
|
| 300 | - add_meta_box( |
|
| 301 | - 'add-extra-nav-menu-pages', |
|
| 302 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 303 | - array($this, 'ee_cpt_archive_pages'), |
|
| 304 | - 'nav-menus', |
|
| 305 | - 'side', |
|
| 306 | - 'core' |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 313 | - * |
|
| 314 | - * @since 4.3.0 |
|
| 315 | - * @param string $link the original link generated by wp |
|
| 316 | - * @param int $id post id |
|
| 317 | - * @return string the (maybe) modified link |
|
| 318 | - */ |
|
| 319 | - public function modify_edit_post_link($link, $id) |
|
| 320 | - { |
|
| 321 | - if (! $post = get_post($id)) { |
|
| 322 | - return $link; |
|
| 323 | - } |
|
| 324 | - if ($post->post_type === 'espresso_attendees') { |
|
| 325 | - $query_args = array( |
|
| 326 | - 'action' => 'edit_attendee', |
|
| 327 | - 'post' => $id, |
|
| 328 | - ); |
|
| 329 | - return EEH_URL::add_query_args_and_nonce( |
|
| 330 | - $query_args, |
|
| 331 | - admin_url('admin.php?page=espresso_registrations') |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - return $link; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - public function ee_cpt_archive_pages() |
|
| 339 | - { |
|
| 340 | - global $nav_menu_selected_id; |
|
| 341 | - |
|
| 342 | - $db_fields = false; |
|
| 343 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 344 | - $current_tab = 'event-archives'; |
|
| 345 | - |
|
| 346 | - /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 18 | + /** |
|
| 19 | + * @access private |
|
| 20 | + * @var EE_Admin $_instance |
|
| 21 | + */ |
|
| 22 | + private static $_instance; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + *@ singleton method used to instantiate class object |
|
| 27 | + *@ access public |
|
| 28 | + *@ return class instance |
|
| 29 | + * |
|
| 30 | + * @throws \EE_Error |
|
| 31 | + */ |
|
| 32 | + public static function instance() |
|
| 33 | + { |
|
| 34 | + // check if class object is instantiated |
|
| 35 | + if (! self::$_instance instanceof EE_Admin) { |
|
| 36 | + self::$_instance = new self(); |
|
| 37 | + } |
|
| 38 | + return self::$_instance; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return EE_Admin |
|
| 44 | + * @throws EE_Error |
|
| 45 | + */ |
|
| 46 | + public static function reset() |
|
| 47 | + { |
|
| 48 | + self::$_instance = null; |
|
| 49 | + return self::instance(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * class constructor |
|
| 55 | + * |
|
| 56 | + * @throws \EE_Error |
|
| 57 | + */ |
|
| 58 | + protected function __construct() |
|
| 59 | + { |
|
| 60 | + // define global EE_Admin constants |
|
| 61 | + $this->_define_all_constants(); |
|
| 62 | + // set autoloaders for our admin page classes based on included path information |
|
| 63 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 64 | + // admin hooks |
|
| 65 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 66 | + // load EE_Request_Handler early |
|
| 67 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 68 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 69 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 70 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 71 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 72 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 73 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 74 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 75 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 76 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 77 | + |
|
| 78 | + //reset Environment config (we only do this on admin page loads); |
|
| 79 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 80 | + |
|
| 81 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * _define_all_constants |
|
| 87 | + * define constants that are set globally for all admin pages |
|
| 88 | + * |
|
| 89 | + * @access private |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + private function _define_all_constants() |
|
| 93 | + { |
|
| 94 | + if (! defined('EE_ADMIN_URL')) { |
|
| 95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 99 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
| 106 | + * |
|
| 107 | + * @access public |
|
| 108 | + * @param array $links |
|
| 109 | + * @param string $plugin |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function filter_plugin_actions($links, $plugin) |
|
| 113 | + { |
|
| 114 | + // set $main_file in stone |
|
| 115 | + static $main_file; |
|
| 116 | + // if $main_file is not set yet |
|
| 117 | + if (! $main_file) { |
|
| 118 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 119 | + } |
|
| 120 | + if ($plugin === $main_file) { |
|
| 121 | + // compare current plugin to this one |
|
| 122 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 123 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 124 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 125 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 126 | + . '</a>'; |
|
| 127 | + array_unshift($links, $maintenance_link); |
|
| 128 | + } else { |
|
| 129 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 130 | + . esc_html__('Settings', 'event_espresso') |
|
| 131 | + . '</a>'; |
|
| 132 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 133 | + . esc_html__('Events', 'event_espresso') |
|
| 134 | + . '</a>'; |
|
| 135 | + // add before other links |
|
| 136 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + return $links; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * _get_request |
|
| 145 | + * |
|
| 146 | + * @access public |
|
| 147 | + * @return void |
|
| 148 | + * @throws EE_Error |
|
| 149 | + * @throws ReflectionException |
|
| 150 | + */ |
|
| 151 | + public function get_request() |
|
| 152 | + { |
|
| 153 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 154 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * hide_admin_pages_except_maintenance_mode |
|
| 160 | + * |
|
| 161 | + * @access public |
|
| 162 | + * @param array $admin_page_folder_names |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 166 | + { |
|
| 167 | + return array( |
|
| 168 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 177 | + * EE_Front_Controller's init phases have run |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @return void |
|
| 181 | + * @throws EE_Error |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + */ |
|
| 184 | + public function init() |
|
| 185 | + { |
|
| 186 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 187 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 188 | + //ok so we want to enable the entire admin |
|
| 189 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 190 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 191 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 192 | + //at a glance dashboard widget |
|
| 193 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 194 | + //filter for get_edit_post_link used on comments for custom post types |
|
| 195 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 196 | + } |
|
| 197 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 198 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | + try { |
|
| 200 | + //this loads the controller for the admin pages which will setup routing etc |
|
| 201 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 202 | + } catch (EE_Error $e) { |
|
| 203 | + $e->get_error(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 207 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 208 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 209 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 210 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 211 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 217 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 218 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 219 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 220 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 221 | + * |
|
| 222 | + * @param object $post_type WP post type object |
|
| 223 | + * @return object WP post type object |
|
| 224 | + */ |
|
| 225 | + public function remove_pages_from_nav_menu($post_type) |
|
| 226 | + { |
|
| 227 | + //if this isn't the "pages" post type let's get out |
|
| 228 | + if ($post_type->name !== 'page') { |
|
| 229 | + return $post_type; |
|
| 230 | + } |
|
| 231 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 232 | + |
|
| 233 | + $post_type->_default_query = array( |
|
| 234 | + 'post__not_in' => $critical_pages, |
|
| 235 | + ); |
|
| 236 | + return $post_type; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 242 | + * metaboxes get shown as well |
|
| 243 | + * |
|
| 244 | + * @access public |
|
| 245 | + * @return void |
|
| 246 | + */ |
|
| 247 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 248 | + { |
|
| 249 | + global $wp_meta_boxes, $pagenow; |
|
| 250 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | + return; |
|
| 252 | + } |
|
| 253 | + $user = wp_get_current_user(); |
|
| 254 | + //has this been done yet? |
|
| 255 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 256 | + return; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 260 | + $initial_meta_boxes = apply_filters( |
|
| 261 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 262 | + array( |
|
| 263 | + 'nav-menu-theme-locations', |
|
| 264 | + 'add-page', |
|
| 265 | + 'add-custom-links', |
|
| 266 | + 'add-category', |
|
| 267 | + 'add-espresso_events', |
|
| 268 | + 'add-espresso_venues', |
|
| 269 | + 'add-espresso_event_categories', |
|
| 270 | + 'add-espresso_venue_categories', |
|
| 271 | + 'add-post-type-post', |
|
| 272 | + 'add-post-type-page', |
|
| 273 | + ) |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + if (is_array($hidden_meta_boxes)) { |
|
| 277 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | + unset($hidden_meta_boxes[$key]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | + * |
|
| 293 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | + * addons etc. |
|
| 295 | + * @access public |
|
| 296 | + * @return void |
|
| 297 | + */ |
|
| 298 | + public function register_custom_nav_menu_boxes() |
|
| 299 | + { |
|
| 300 | + add_meta_box( |
|
| 301 | + 'add-extra-nav-menu-pages', |
|
| 302 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 303 | + array($this, 'ee_cpt_archive_pages'), |
|
| 304 | + 'nav-menus', |
|
| 305 | + 'side', |
|
| 306 | + 'core' |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 313 | + * |
|
| 314 | + * @since 4.3.0 |
|
| 315 | + * @param string $link the original link generated by wp |
|
| 316 | + * @param int $id post id |
|
| 317 | + * @return string the (maybe) modified link |
|
| 318 | + */ |
|
| 319 | + public function modify_edit_post_link($link, $id) |
|
| 320 | + { |
|
| 321 | + if (! $post = get_post($id)) { |
|
| 322 | + return $link; |
|
| 323 | + } |
|
| 324 | + if ($post->post_type === 'espresso_attendees') { |
|
| 325 | + $query_args = array( |
|
| 326 | + 'action' => 'edit_attendee', |
|
| 327 | + 'post' => $id, |
|
| 328 | + ); |
|
| 329 | + return EEH_URL::add_query_args_and_nonce( |
|
| 330 | + $query_args, |
|
| 331 | + admin_url('admin.php?page=espresso_registrations') |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + return $link; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + public function ee_cpt_archive_pages() |
|
| 339 | + { |
|
| 340 | + global $nav_menu_selected_id; |
|
| 341 | + |
|
| 342 | + $db_fields = false; |
|
| 343 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 344 | + $current_tab = 'event-archives'; |
|
| 345 | + |
|
| 346 | + /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 347 | 347 | $current_tab = 'search'; |
| 348 | 348 | }/**/ |
| 349 | 349 | |
| 350 | - $removed_args = array( |
|
| 351 | - 'action', |
|
| 352 | - 'customlink-tab', |
|
| 353 | - 'edit-menu-item', |
|
| 354 | - 'menu-item', |
|
| 355 | - 'page-tab', |
|
| 356 | - '_wpnonce', |
|
| 357 | - ); |
|
| 350 | + $removed_args = array( |
|
| 351 | + 'action', |
|
| 352 | + 'customlink-tab', |
|
| 353 | + 'edit-menu-item', |
|
| 354 | + 'menu-item', |
|
| 355 | + 'page-tab', |
|
| 356 | + '_wpnonce', |
|
| 357 | + ); |
|
| 358 | 358 | |
| 359 | - ?> |
|
| 359 | + ?> |
|
| 360 | 360 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
| 361 | 361 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 362 | 362 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
| 363 | 363 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
| 364 | 364 | href="<?php if ($nav_menu_selected_id) { |
| 365 | - echo esc_url( |
|
| 366 | - add_query_arg( |
|
| 367 | - 'extra-nav-menu-pages-tab', |
|
| 368 | - 'event-archives', |
|
| 369 | - remove_query_arg($removed_args) |
|
| 370 | - ) |
|
| 371 | - ); |
|
| 372 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 365 | + echo esc_url( |
|
| 366 | + add_query_arg( |
|
| 367 | + 'extra-nav-menu-pages-tab', |
|
| 368 | + 'event-archives', |
|
| 369 | + remove_query_arg($removed_args) |
|
| 370 | + ) |
|
| 371 | + ); |
|
| 372 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 373 | 373 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
| 374 | 374 | </a> |
| 375 | 375 | </li> |
| 376 | 376 | |
| 377 | 377 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
| 378 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 379 | - ?>"> |
|
| 378 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 379 | + ?>"> |
|
| 380 | 380 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
| 381 | 381 | <?php |
| 382 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 383 | - $args['walker'] = $walker; |
|
| 384 | - echo walk_nav_menu_tree( |
|
| 385 | - array_map( |
|
| 386 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 387 | - $pages |
|
| 388 | - ), |
|
| 389 | - 0, |
|
| 390 | - (object) $args |
|
| 391 | - ); |
|
| 392 | - ?> |
|
| 382 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 383 | + $args['walker'] = $walker; |
|
| 384 | + echo walk_nav_menu_tree( |
|
| 385 | + array_map( |
|
| 386 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 387 | + $pages |
|
| 388 | + ), |
|
| 389 | + 0, |
|
| 390 | + (object) $args |
|
| 391 | + ); |
|
| 392 | + ?> |
|
| 393 | 393 | </ul> |
| 394 | 394 | </div><!-- /.tabs-panel --> |
| 395 | 395 | |
| 396 | 396 | <p class="button-controls"> |
| 397 | 397 | <span class="list-controls"> |
| 398 | 398 | <a href="<?php |
| 399 | - echo esc_url(add_query_arg( |
|
| 400 | - array( |
|
| 401 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 402 | - 'selectall' => 1, |
|
| 403 | - ), |
|
| 404 | - remove_query_arg($removed_args) |
|
| 405 | - )); |
|
| 406 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 399 | + echo esc_url(add_query_arg( |
|
| 400 | + array( |
|
| 401 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 402 | + 'selectall' => 1, |
|
| 403 | + ), |
|
| 404 | + remove_query_arg($removed_args) |
|
| 405 | + )); |
|
| 406 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 407 | 407 | </span> |
| 408 | 408 | <span class="add-to-menu"> |
| 409 | 409 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -416,491 +416,491 @@ discard block |
||
| 416 | 416 | |
| 417 | 417 | </div><!-- /.posttypediv --> |
| 418 | 418 | <?php |
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Returns an array of event archive nav items. |
|
| 424 | - * |
|
| 425 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 426 | - * method we use for getting the extra nav menu items |
|
| 427 | - * @return array |
|
| 428 | - */ |
|
| 429 | - private function _get_extra_nav_menu_pages_items() |
|
| 430 | - { |
|
| 431 | - $menuitems[] = array( |
|
| 432 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 433 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
| 434 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 435 | - ); |
|
| 436 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 442 | - * the properties and converts it to the menu item object. |
|
| 443 | - * |
|
| 444 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 445 | - * @param $menu_item_values |
|
| 446 | - * @return stdClass |
|
| 447 | - */ |
|
| 448 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 449 | - { |
|
| 450 | - $menu_item = new stdClass(); |
|
| 451 | - $keys = array( |
|
| 452 | - 'ID' => 0, |
|
| 453 | - 'db_id' => 0, |
|
| 454 | - 'menu_item_parent' => 0, |
|
| 455 | - 'object_id' => -1, |
|
| 456 | - 'post_parent' => 0, |
|
| 457 | - 'type' => 'custom', |
|
| 458 | - 'object' => '', |
|
| 459 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 460 | - 'title' => '', |
|
| 461 | - 'url' => '', |
|
| 462 | - 'target' => '', |
|
| 463 | - 'attr_title' => '', |
|
| 464 | - 'description' => '', |
|
| 465 | - 'classes' => array(), |
|
| 466 | - 'xfn' => '', |
|
| 467 | - ); |
|
| 468 | - |
|
| 469 | - foreach ($keys as $key => $value) { |
|
| 470 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 471 | - } |
|
| 472 | - return $menu_item; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 478 | - * EE_Admin_Page route is called. |
|
| 479 | - * |
|
| 480 | - * @return void |
|
| 481 | - */ |
|
| 482 | - public function route_admin_request() |
|
| 483 | - { |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 489 | - * |
|
| 490 | - * @return void |
|
| 491 | - */ |
|
| 492 | - public function wp_loaded() |
|
| 493 | - { |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * admin_init |
|
| 499 | - * |
|
| 500 | - * @access public |
|
| 501 | - * @return void |
|
| 502 | - * @throws EE_Error |
|
| 503 | - * @throws ReflectionException |
|
| 504 | - */ |
|
| 505 | - public function admin_init() |
|
| 506 | - { |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 510 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 511 | - * - check if doing post processing. |
|
| 512 | - * - check if doing post processing of one of EE CPTs |
|
| 513 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 514 | - */ |
|
| 515 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 516 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 517 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 523 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 524 | - * Pages" tab in the EE General Settings Admin page. |
|
| 525 | - * This is for user-proofing. |
|
| 526 | - */ |
|
| 527 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 533 | - * |
|
| 534 | - * @param string $output Current output. |
|
| 535 | - * @return string |
|
| 536 | - */ |
|
| 537 | - public function modify_dropdown_pages($output) |
|
| 538 | - { |
|
| 539 | - //get critical pages |
|
| 540 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 541 | - |
|
| 542 | - //split current output by line break for easier parsing. |
|
| 543 | - $split_output = explode("\n", $output); |
|
| 544 | - |
|
| 545 | - //loop through to remove any critical pages from the array. |
|
| 546 | - foreach ($critical_pages as $page_id) { |
|
| 547 | - $needle = 'value="' . $page_id . '"'; |
|
| 548 | - foreach ($split_output as $key => $haystack) { |
|
| 549 | - if (strpos($haystack, $needle) !== false) { |
|
| 550 | - unset($split_output[$key]); |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - //replace output with the new contents |
|
| 556 | - return implode("\n", $split_output); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * enqueue all admin scripts that need loaded for admin pages |
|
| 562 | - * |
|
| 563 | - * @access public |
|
| 564 | - * @return void |
|
| 565 | - */ |
|
| 566 | - public function enqueue_admin_scripts() |
|
| 567 | - { |
|
| 568 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 569 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 570 | - // calls. |
|
| 571 | - wp_enqueue_script( |
|
| 572 | - 'ee-inject-wp', |
|
| 573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 574 | - array('jquery'), |
|
| 575 | - EVENT_ESPRESSO_VERSION, |
|
| 576 | - true |
|
| 577 | - ); |
|
| 578 | - // register cookie script for future dependencies |
|
| 579 | - wp_register_script( |
|
| 580 | - 'jquery-cookie', |
|
| 581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 582 | - array('jquery'), |
|
| 583 | - '2.1', |
|
| 584 | - true |
|
| 585 | - ); |
|
| 586 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 587 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 588 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
| 589 | - //joyride style |
|
| 590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | - wp_register_style( |
|
| 592 | - 'ee-joyride-css', |
|
| 593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 594 | - array('joyride-css'), |
|
| 595 | - EVENT_ESPRESSO_VERSION |
|
| 596 | - ); |
|
| 597 | - wp_register_script( |
|
| 598 | - 'joyride-modernizr', |
|
| 599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 600 | - array(), |
|
| 601 | - '2.1', |
|
| 602 | - true |
|
| 603 | - ); |
|
| 604 | - //joyride JS |
|
| 605 | - wp_register_script( |
|
| 606 | - 'jquery-joyride', |
|
| 607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 608 | - array('jquery-cookie', 'joyride-modernizr'), |
|
| 609 | - '2.1', |
|
| 610 | - true |
|
| 611 | - ); |
|
| 612 | - // wanna go for a joyride? |
|
| 613 | - wp_enqueue_style('ee-joyride-css'); |
|
| 614 | - wp_enqueue_script('jquery-joyride'); |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * display_admin_notices |
|
| 621 | - * |
|
| 622 | - * @access public |
|
| 623 | - * @return string |
|
| 624 | - */ |
|
| 625 | - public function display_admin_notices() |
|
| 626 | - { |
|
| 627 | - echo EE_Error::get_notices(); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * get_persistent_admin_notices |
|
| 633 | - * |
|
| 634 | - * @access public |
|
| 635 | - * @return void |
|
| 636 | - */ |
|
| 637 | - public function get_persistent_admin_notices() |
|
| 638 | - { |
|
| 639 | - // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 640 | - $args = array( |
|
| 641 | - 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
| 642 | - ? EE_Registry::instance()->REQ->get('page') |
|
| 643 | - : '', |
|
| 644 | - 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
| 645 | - ? EE_Registry::instance()->REQ->get('action') |
|
| 646 | - : '', |
|
| 647 | - ); |
|
| 648 | - $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php')); |
|
| 649 | - //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 650 | - //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 651 | - //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 652 | - //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 653 | - if (! get_option('timezone_string')) { |
|
| 654 | - EE_Error::add_persistent_admin_notice( |
|
| 655 | - 'datetime_fix_notice', |
|
| 656 | - sprintf( |
|
| 657 | - esc_html__( |
|
| 658 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 659 | - 'event_espresso' |
|
| 660 | - ), |
|
| 661 | - '<strong>', |
|
| 662 | - '</strong>', |
|
| 663 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 664 | - '</a>', |
|
| 665 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | - array( |
|
| 667 | - 'page' => 'espresso_maintenance_settings', |
|
| 668 | - 'action' => 'datetime_tools' |
|
| 669 | - ), |
|
| 670 | - admin_url('admin.php') |
|
| 671 | - ) . '">' |
|
| 672 | - ) |
|
| 673 | - ); |
|
| 674 | - } |
|
| 675 | - echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * dismiss_persistent_admin_notice |
|
| 681 | - * |
|
| 682 | - * @access public |
|
| 683 | - * @return void |
|
| 684 | - */ |
|
| 685 | - public function dismiss_ee_nag_notice_callback() |
|
| 686 | - { |
|
| 687 | - EE_Error::dismiss_persistent_admin_notice(); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * @param array $elements |
|
| 693 | - * @return array |
|
| 694 | - * @throws \EE_Error |
|
| 695 | - */ |
|
| 696 | - public function dashboard_glance_items($elements) |
|
| 697 | - { |
|
| 698 | - $elements = is_array($elements) ? $elements : array($elements); |
|
| 699 | - $events = EEM_Event::instance()->count(); |
|
| 700 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 701 | - array('page' => 'espresso_events'), |
|
| 702 | - admin_url('admin.php') |
|
| 703 | - ); |
|
| 704 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 705 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 706 | - $registrations = EEM_Registration::instance()->count( |
|
| 707 | - array( |
|
| 708 | - array( |
|
| 709 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 710 | - ), |
|
| 711 | - ) |
|
| 712 | - ); |
|
| 713 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | - array('page' => 'espresso_registrations'), |
|
| 715 | - admin_url('admin.php') |
|
| 716 | - ); |
|
| 717 | - $items['registrations']['text'] = sprintf( |
|
| 718 | - _n('%s Registration', '%s Registrations', $registrations), |
|
| 719 | - number_format_i18n($registrations) |
|
| 720 | - ); |
|
| 721 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 722 | - |
|
| 723 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | - |
|
| 725 | - foreach ($items as $type => $item_properties) { |
|
| 726 | - $elements[] = sprintf( |
|
| 727 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 728 | - $item_properties['url'], |
|
| 729 | - $item_properties['title'], |
|
| 730 | - $item_properties['text'] |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - return $elements; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * check_for_invalid_datetime_formats |
|
| 739 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 740 | - * their selected format can be parsed by PHP |
|
| 741 | - * |
|
| 742 | - * @access public |
|
| 743 | - * @param $value |
|
| 744 | - * @param $option |
|
| 745 | - * @throws EE_Error |
|
| 746 | - * @return string |
|
| 747 | - */ |
|
| 748 | - public function check_for_invalid_datetime_formats($value, $option) |
|
| 749 | - { |
|
| 750 | - // check for date_format or time_format |
|
| 751 | - switch ($option) { |
|
| 752 | - case 'date_format': |
|
| 753 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 754 | - break; |
|
| 755 | - case 'time_format': |
|
| 756 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 757 | - break; |
|
| 758 | - default: |
|
| 759 | - $date_time_format = false; |
|
| 760 | - } |
|
| 761 | - // do we have a date_time format to check ? |
|
| 762 | - if ($date_time_format) { |
|
| 763 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 764 | - |
|
| 765 | - if (is_array($error_msg)) { |
|
| 766 | - $msg = '<p>' |
|
| 767 | - . sprintf( |
|
| 768 | - esc_html__( |
|
| 769 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 770 | - 'event_espresso' |
|
| 771 | - ), |
|
| 772 | - date($date_time_format), |
|
| 773 | - $date_time_format |
|
| 774 | - ) |
|
| 775 | - . '</p><p><ul>'; |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - foreach ($error_msg as $error) { |
|
| 779 | - $msg .= '<li>' . $error . '</li>'; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - $msg .= '</ul></p><p>' |
|
| 783 | - . sprintf( |
|
| 784 | - esc_html__( |
|
| 785 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 786 | - 'event_espresso' |
|
| 787 | - ), |
|
| 788 | - '<span style="color:#D54E21;">', |
|
| 789 | - '</span>' |
|
| 790 | - ) |
|
| 791 | - . '</p>'; |
|
| 792 | - |
|
| 793 | - // trigger WP settings error |
|
| 794 | - add_settings_error( |
|
| 795 | - 'date_format', |
|
| 796 | - 'date_format', |
|
| 797 | - $msg |
|
| 798 | - ); |
|
| 799 | - |
|
| 800 | - // set format to something valid |
|
| 801 | - switch ($option) { |
|
| 802 | - case 'date_format': |
|
| 803 | - $value = 'F j, Y'; |
|
| 804 | - break; |
|
| 805 | - case 'time_format': |
|
| 806 | - $value = 'g:i a'; |
|
| 807 | - break; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - return $value; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 817 | - * |
|
| 818 | - * @access public |
|
| 819 | - * @param $content |
|
| 820 | - * @return string |
|
| 821 | - */ |
|
| 822 | - public function its_eSpresso($content) |
|
| 823 | - { |
|
| 824 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * espresso_admin_footer |
|
| 830 | - * |
|
| 831 | - * @access public |
|
| 832 | - * @return string |
|
| 833 | - */ |
|
| 834 | - public function espresso_admin_footer() |
|
| 835 | - { |
|
| 836 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * static method for registering ee admin page. |
|
| 842 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 843 | - * |
|
| 844 | - * @since 4.3.0 |
|
| 845 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 846 | - * @see EE_Register_Admin_Page::register() |
|
| 847 | - * @param $page_basename |
|
| 848 | - * @param $page_path |
|
| 849 | - * @param array $config |
|
| 850 | - * @return void |
|
| 851 | - * @throws EE_Error |
|
| 852 | - */ |
|
| 853 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 854 | - { |
|
| 855 | - EE_Error::doing_it_wrong( |
|
| 856 | - __METHOD__, |
|
| 857 | - sprintf( |
|
| 858 | - esc_html__( |
|
| 859 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 860 | - 'event_espresso' |
|
| 861 | - ), |
|
| 862 | - $page_basename |
|
| 863 | - ), |
|
| 864 | - '4.3' |
|
| 865 | - ); |
|
| 866 | - if (class_exists('EE_Register_Admin_Page')) { |
|
| 867 | - $config['page_path'] = $page_path; |
|
| 868 | - } |
|
| 869 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * @deprecated 4.8.41 |
|
| 875 | - * @access public |
|
| 876 | - * @param int $post_ID |
|
| 877 | - * @param \WP_Post $post |
|
| 878 | - * @return void |
|
| 879 | - */ |
|
| 880 | - public static function parse_post_content_on_save($post_ID, $post) |
|
| 881 | - { |
|
| 882 | - EE_Error::doing_it_wrong( |
|
| 883 | - __METHOD__, |
|
| 884 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 885 | - '4.8.41' |
|
| 886 | - ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * @deprecated 4.8.41 |
|
| 892 | - * @access public |
|
| 893 | - * @param $option |
|
| 894 | - * @param $old_value |
|
| 895 | - * @param $value |
|
| 896 | - * @return void |
|
| 897 | - */ |
|
| 898 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 899 | - { |
|
| 900 | - EE_Error::doing_it_wrong( |
|
| 901 | - __METHOD__, |
|
| 902 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 903 | - '4.8.41' |
|
| 904 | - ); |
|
| 905 | - } |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Returns an array of event archive nav items. |
|
| 424 | + * |
|
| 425 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 426 | + * method we use for getting the extra nav menu items |
|
| 427 | + * @return array |
|
| 428 | + */ |
|
| 429 | + private function _get_extra_nav_menu_pages_items() |
|
| 430 | + { |
|
| 431 | + $menuitems[] = array( |
|
| 432 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 433 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
| 434 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 435 | + ); |
|
| 436 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 442 | + * the properties and converts it to the menu item object. |
|
| 443 | + * |
|
| 444 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 445 | + * @param $menu_item_values |
|
| 446 | + * @return stdClass |
|
| 447 | + */ |
|
| 448 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 449 | + { |
|
| 450 | + $menu_item = new stdClass(); |
|
| 451 | + $keys = array( |
|
| 452 | + 'ID' => 0, |
|
| 453 | + 'db_id' => 0, |
|
| 454 | + 'menu_item_parent' => 0, |
|
| 455 | + 'object_id' => -1, |
|
| 456 | + 'post_parent' => 0, |
|
| 457 | + 'type' => 'custom', |
|
| 458 | + 'object' => '', |
|
| 459 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 460 | + 'title' => '', |
|
| 461 | + 'url' => '', |
|
| 462 | + 'target' => '', |
|
| 463 | + 'attr_title' => '', |
|
| 464 | + 'description' => '', |
|
| 465 | + 'classes' => array(), |
|
| 466 | + 'xfn' => '', |
|
| 467 | + ); |
|
| 468 | + |
|
| 469 | + foreach ($keys as $key => $value) { |
|
| 470 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 471 | + } |
|
| 472 | + return $menu_item; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 478 | + * EE_Admin_Page route is called. |
|
| 479 | + * |
|
| 480 | + * @return void |
|
| 481 | + */ |
|
| 482 | + public function route_admin_request() |
|
| 483 | + { |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 489 | + * |
|
| 490 | + * @return void |
|
| 491 | + */ |
|
| 492 | + public function wp_loaded() |
|
| 493 | + { |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * admin_init |
|
| 499 | + * |
|
| 500 | + * @access public |
|
| 501 | + * @return void |
|
| 502 | + * @throws EE_Error |
|
| 503 | + * @throws ReflectionException |
|
| 504 | + */ |
|
| 505 | + public function admin_init() |
|
| 506 | + { |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 510 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 511 | + * - check if doing post processing. |
|
| 512 | + * - check if doing post processing of one of EE CPTs |
|
| 513 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 514 | + */ |
|
| 515 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 516 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 517 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 523 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 524 | + * Pages" tab in the EE General Settings Admin page. |
|
| 525 | + * This is for user-proofing. |
|
| 526 | + */ |
|
| 527 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 533 | + * |
|
| 534 | + * @param string $output Current output. |
|
| 535 | + * @return string |
|
| 536 | + */ |
|
| 537 | + public function modify_dropdown_pages($output) |
|
| 538 | + { |
|
| 539 | + //get critical pages |
|
| 540 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 541 | + |
|
| 542 | + //split current output by line break for easier parsing. |
|
| 543 | + $split_output = explode("\n", $output); |
|
| 544 | + |
|
| 545 | + //loop through to remove any critical pages from the array. |
|
| 546 | + foreach ($critical_pages as $page_id) { |
|
| 547 | + $needle = 'value="' . $page_id . '"'; |
|
| 548 | + foreach ($split_output as $key => $haystack) { |
|
| 549 | + if (strpos($haystack, $needle) !== false) { |
|
| 550 | + unset($split_output[$key]); |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + //replace output with the new contents |
|
| 556 | + return implode("\n", $split_output); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * enqueue all admin scripts that need loaded for admin pages |
|
| 562 | + * |
|
| 563 | + * @access public |
|
| 564 | + * @return void |
|
| 565 | + */ |
|
| 566 | + public function enqueue_admin_scripts() |
|
| 567 | + { |
|
| 568 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 569 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 570 | + // calls. |
|
| 571 | + wp_enqueue_script( |
|
| 572 | + 'ee-inject-wp', |
|
| 573 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 574 | + array('jquery'), |
|
| 575 | + EVENT_ESPRESSO_VERSION, |
|
| 576 | + true |
|
| 577 | + ); |
|
| 578 | + // register cookie script for future dependencies |
|
| 579 | + wp_register_script( |
|
| 580 | + 'jquery-cookie', |
|
| 581 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 582 | + array('jquery'), |
|
| 583 | + '2.1', |
|
| 584 | + true |
|
| 585 | + ); |
|
| 586 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 587 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 588 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
| 589 | + //joyride style |
|
| 590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | + wp_register_style( |
|
| 592 | + 'ee-joyride-css', |
|
| 593 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 594 | + array('joyride-css'), |
|
| 595 | + EVENT_ESPRESSO_VERSION |
|
| 596 | + ); |
|
| 597 | + wp_register_script( |
|
| 598 | + 'joyride-modernizr', |
|
| 599 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 600 | + array(), |
|
| 601 | + '2.1', |
|
| 602 | + true |
|
| 603 | + ); |
|
| 604 | + //joyride JS |
|
| 605 | + wp_register_script( |
|
| 606 | + 'jquery-joyride', |
|
| 607 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 608 | + array('jquery-cookie', 'joyride-modernizr'), |
|
| 609 | + '2.1', |
|
| 610 | + true |
|
| 611 | + ); |
|
| 612 | + // wanna go for a joyride? |
|
| 613 | + wp_enqueue_style('ee-joyride-css'); |
|
| 614 | + wp_enqueue_script('jquery-joyride'); |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * display_admin_notices |
|
| 621 | + * |
|
| 622 | + * @access public |
|
| 623 | + * @return string |
|
| 624 | + */ |
|
| 625 | + public function display_admin_notices() |
|
| 626 | + { |
|
| 627 | + echo EE_Error::get_notices(); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * get_persistent_admin_notices |
|
| 633 | + * |
|
| 634 | + * @access public |
|
| 635 | + * @return void |
|
| 636 | + */ |
|
| 637 | + public function get_persistent_admin_notices() |
|
| 638 | + { |
|
| 639 | + // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 640 | + $args = array( |
|
| 641 | + 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
| 642 | + ? EE_Registry::instance()->REQ->get('page') |
|
| 643 | + : '', |
|
| 644 | + 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
| 645 | + ? EE_Registry::instance()->REQ->get('action') |
|
| 646 | + : '', |
|
| 647 | + ); |
|
| 648 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php')); |
|
| 649 | + //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 650 | + //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 651 | + //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 652 | + //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 653 | + if (! get_option('timezone_string')) { |
|
| 654 | + EE_Error::add_persistent_admin_notice( |
|
| 655 | + 'datetime_fix_notice', |
|
| 656 | + sprintf( |
|
| 657 | + esc_html__( |
|
| 658 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 659 | + 'event_espresso' |
|
| 660 | + ), |
|
| 661 | + '<strong>', |
|
| 662 | + '</strong>', |
|
| 663 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 664 | + '</a>', |
|
| 665 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | + array( |
|
| 667 | + 'page' => 'espresso_maintenance_settings', |
|
| 668 | + 'action' => 'datetime_tools' |
|
| 669 | + ), |
|
| 670 | + admin_url('admin.php') |
|
| 671 | + ) . '">' |
|
| 672 | + ) |
|
| 673 | + ); |
|
| 674 | + } |
|
| 675 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * dismiss_persistent_admin_notice |
|
| 681 | + * |
|
| 682 | + * @access public |
|
| 683 | + * @return void |
|
| 684 | + */ |
|
| 685 | + public function dismiss_ee_nag_notice_callback() |
|
| 686 | + { |
|
| 687 | + EE_Error::dismiss_persistent_admin_notice(); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * @param array $elements |
|
| 693 | + * @return array |
|
| 694 | + * @throws \EE_Error |
|
| 695 | + */ |
|
| 696 | + public function dashboard_glance_items($elements) |
|
| 697 | + { |
|
| 698 | + $elements = is_array($elements) ? $elements : array($elements); |
|
| 699 | + $events = EEM_Event::instance()->count(); |
|
| 700 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 701 | + array('page' => 'espresso_events'), |
|
| 702 | + admin_url('admin.php') |
|
| 703 | + ); |
|
| 704 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 705 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 706 | + $registrations = EEM_Registration::instance()->count( |
|
| 707 | + array( |
|
| 708 | + array( |
|
| 709 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 710 | + ), |
|
| 711 | + ) |
|
| 712 | + ); |
|
| 713 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | + array('page' => 'espresso_registrations'), |
|
| 715 | + admin_url('admin.php') |
|
| 716 | + ); |
|
| 717 | + $items['registrations']['text'] = sprintf( |
|
| 718 | + _n('%s Registration', '%s Registrations', $registrations), |
|
| 719 | + number_format_i18n($registrations) |
|
| 720 | + ); |
|
| 721 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 722 | + |
|
| 723 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | + |
|
| 725 | + foreach ($items as $type => $item_properties) { |
|
| 726 | + $elements[] = sprintf( |
|
| 727 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 728 | + $item_properties['url'], |
|
| 729 | + $item_properties['title'], |
|
| 730 | + $item_properties['text'] |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + return $elements; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * check_for_invalid_datetime_formats |
|
| 739 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 740 | + * their selected format can be parsed by PHP |
|
| 741 | + * |
|
| 742 | + * @access public |
|
| 743 | + * @param $value |
|
| 744 | + * @param $option |
|
| 745 | + * @throws EE_Error |
|
| 746 | + * @return string |
|
| 747 | + */ |
|
| 748 | + public function check_for_invalid_datetime_formats($value, $option) |
|
| 749 | + { |
|
| 750 | + // check for date_format or time_format |
|
| 751 | + switch ($option) { |
|
| 752 | + case 'date_format': |
|
| 753 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 754 | + break; |
|
| 755 | + case 'time_format': |
|
| 756 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 757 | + break; |
|
| 758 | + default: |
|
| 759 | + $date_time_format = false; |
|
| 760 | + } |
|
| 761 | + // do we have a date_time format to check ? |
|
| 762 | + if ($date_time_format) { |
|
| 763 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 764 | + |
|
| 765 | + if (is_array($error_msg)) { |
|
| 766 | + $msg = '<p>' |
|
| 767 | + . sprintf( |
|
| 768 | + esc_html__( |
|
| 769 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 770 | + 'event_espresso' |
|
| 771 | + ), |
|
| 772 | + date($date_time_format), |
|
| 773 | + $date_time_format |
|
| 774 | + ) |
|
| 775 | + . '</p><p><ul>'; |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + foreach ($error_msg as $error) { |
|
| 779 | + $msg .= '<li>' . $error . '</li>'; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + $msg .= '</ul></p><p>' |
|
| 783 | + . sprintf( |
|
| 784 | + esc_html__( |
|
| 785 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 786 | + 'event_espresso' |
|
| 787 | + ), |
|
| 788 | + '<span style="color:#D54E21;">', |
|
| 789 | + '</span>' |
|
| 790 | + ) |
|
| 791 | + . '</p>'; |
|
| 792 | + |
|
| 793 | + // trigger WP settings error |
|
| 794 | + add_settings_error( |
|
| 795 | + 'date_format', |
|
| 796 | + 'date_format', |
|
| 797 | + $msg |
|
| 798 | + ); |
|
| 799 | + |
|
| 800 | + // set format to something valid |
|
| 801 | + switch ($option) { |
|
| 802 | + case 'date_format': |
|
| 803 | + $value = 'F j, Y'; |
|
| 804 | + break; |
|
| 805 | + case 'time_format': |
|
| 806 | + $value = 'g:i a'; |
|
| 807 | + break; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + return $value; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 817 | + * |
|
| 818 | + * @access public |
|
| 819 | + * @param $content |
|
| 820 | + * @return string |
|
| 821 | + */ |
|
| 822 | + public function its_eSpresso($content) |
|
| 823 | + { |
|
| 824 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * espresso_admin_footer |
|
| 830 | + * |
|
| 831 | + * @access public |
|
| 832 | + * @return string |
|
| 833 | + */ |
|
| 834 | + public function espresso_admin_footer() |
|
| 835 | + { |
|
| 836 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * static method for registering ee admin page. |
|
| 842 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 843 | + * |
|
| 844 | + * @since 4.3.0 |
|
| 845 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 846 | + * @see EE_Register_Admin_Page::register() |
|
| 847 | + * @param $page_basename |
|
| 848 | + * @param $page_path |
|
| 849 | + * @param array $config |
|
| 850 | + * @return void |
|
| 851 | + * @throws EE_Error |
|
| 852 | + */ |
|
| 853 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 854 | + { |
|
| 855 | + EE_Error::doing_it_wrong( |
|
| 856 | + __METHOD__, |
|
| 857 | + sprintf( |
|
| 858 | + esc_html__( |
|
| 859 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 860 | + 'event_espresso' |
|
| 861 | + ), |
|
| 862 | + $page_basename |
|
| 863 | + ), |
|
| 864 | + '4.3' |
|
| 865 | + ); |
|
| 866 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 867 | + $config['page_path'] = $page_path; |
|
| 868 | + } |
|
| 869 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * @deprecated 4.8.41 |
|
| 875 | + * @access public |
|
| 876 | + * @param int $post_ID |
|
| 877 | + * @param \WP_Post $post |
|
| 878 | + * @return void |
|
| 879 | + */ |
|
| 880 | + public static function parse_post_content_on_save($post_ID, $post) |
|
| 881 | + { |
|
| 882 | + EE_Error::doing_it_wrong( |
|
| 883 | + __METHOD__, |
|
| 884 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 885 | + '4.8.41' |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * @deprecated 4.8.41 |
|
| 892 | + * @access public |
|
| 893 | + * @param $option |
|
| 894 | + * @param $old_value |
|
| 895 | + * @param $value |
|
| 896 | + * @return void |
|
| 897 | + */ |
|
| 898 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 899 | + { |
|
| 900 | + EE_Error::doing_it_wrong( |
|
| 901 | + __METHOD__, |
|
| 902 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 903 | + '4.8.41' |
|
| 904 | + ); |
|
| 905 | + } |
|
| 906 | 906 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public static function instance() |
| 33 | 33 | { |
| 34 | 34 | // check if class object is instantiated |
| 35 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 35 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
| 36 | 36 | self::$_instance = new self(); |
| 37 | 37 | } |
| 38 | 38 | return self::$_instance; |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | private function _define_all_constants() |
| 93 | 93 | { |
| 94 | - if (! defined('EE_ADMIN_URL')) { |
|
| 95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 94 | + if ( ! defined('EE_ADMIN_URL')) { |
|
| 95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
| 96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
| 97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
| 98 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
| 99 | 99 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | // set $main_file in stone |
| 115 | 115 | static $main_file; |
| 116 | 116 | // if $main_file is not set yet |
| 117 | - if (! $main_file) { |
|
| 117 | + if ( ! $main_file) { |
|
| 118 | 118 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
| 119 | 119 | } |
| 120 | 120 | if ($plugin === $main_file) { |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
| 166 | 166 | { |
| 167 | 167 | return array( |
| 168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 168 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
| 169 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
| 170 | + 'support' => EE_ADMIN_PAGES.'support'.DS, |
|
| 171 | 171 | ); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
| 196 | 196 | } |
| 197 | 197 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
| 198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 198 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | 199 | try { |
| 200 | 200 | //this loads the controller for the admin pages which will setup routing etc |
| 201 | 201 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | public function enable_hidden_ee_nav_menu_metaboxes() |
| 248 | 248 | { |
| 249 | 249 | global $wp_meta_boxes, $pagenow; |
| 250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 250 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | 251 | return; |
| 252 | 252 | } |
| 253 | 253 | $user = wp_get_current_user(); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | public function modify_edit_post_link($link, $id) |
| 320 | 320 | { |
| 321 | - if (! $post = get_post($id)) { |
|
| 321 | + if ( ! $post = get_post($id)) { |
|
| 322 | 322 | return $link; |
| 323 | 323 | } |
| 324 | 324 | if ($post->post_type === 'espresso_attendees') { |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | //loop through to remove any critical pages from the array. |
| 546 | 546 | foreach ($critical_pages as $page_id) { |
| 547 | - $needle = 'value="' . $page_id . '"'; |
|
| 547 | + $needle = 'value="'.$page_id.'"'; |
|
| 548 | 548 | foreach ($split_output as $key => $haystack) { |
| 549 | 549 | if (strpos($haystack, $needle) !== false) { |
| 550 | 550 | unset($split_output[$key]); |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | // calls. |
| 571 | 571 | wp_enqueue_script( |
| 572 | 572 | 'ee-inject-wp', |
| 573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 573 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
| 574 | 574 | array('jquery'), |
| 575 | 575 | EVENT_ESPRESSO_VERSION, |
| 576 | 576 | true |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | // register cookie script for future dependencies |
| 579 | 579 | wp_register_script( |
| 580 | 580 | 'jquery-cookie', |
| 581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 581 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
| 582 | 582 | array('jquery'), |
| 583 | 583 | '2.1', |
| 584 | 584 | true |
@@ -587,16 +587,16 @@ discard block |
||
| 587 | 587 | // via: add_filter('FHEE_load_joyride', '__return_true' ); |
| 588 | 588 | if (apply_filters('FHEE_load_joyride', false)) { |
| 589 | 589 | //joyride style |
| 590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | 591 | wp_register_style( |
| 592 | 592 | 'ee-joyride-css', |
| 593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 593 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
| 594 | 594 | array('joyride-css'), |
| 595 | 595 | EVENT_ESPRESSO_VERSION |
| 596 | 596 | ); |
| 597 | 597 | wp_register_script( |
| 598 | 598 | 'joyride-modernizr', |
| 599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 599 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
| 600 | 600 | array(), |
| 601 | 601 | '2.1', |
| 602 | 602 | true |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | //joyride JS |
| 605 | 605 | wp_register_script( |
| 606 | 606 | 'jquery-joyride', |
| 607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 607 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
| 608 | 608 | array('jquery-cookie', 'joyride-modernizr'), |
| 609 | 609 | '2.1', |
| 610 | 610 | true |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | public function get_persistent_admin_notices() |
| 638 | 638 | { |
| 639 | 639 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
| 640 | - $args = array( |
|
| 640 | + $args = array( |
|
| 641 | 641 | 'page' => EE_Registry::instance()->REQ->is_set('page') |
| 642 | 642 | ? EE_Registry::instance()->REQ->get('page') |
| 643 | 643 | : '', |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
| 651 | 651 | //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
| 652 | 652 | //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
| 653 | - if (! get_option('timezone_string')) { |
|
| 653 | + if ( ! get_option('timezone_string')) { |
|
| 654 | 654 | EE_Error::add_persistent_admin_notice( |
| 655 | 655 | 'datetime_fix_notice', |
| 656 | 656 | sprintf( |
@@ -662,13 +662,13 @@ discard block |
||
| 662 | 662 | '</strong>', |
| 663 | 663 | '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
| 664 | 664 | '</a>', |
| 665 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 665 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | 666 | array( |
| 667 | 667 | 'page' => 'espresso_maintenance_settings', |
| 668 | 668 | 'action' => 'datetime_tools' |
| 669 | 669 | ), |
| 670 | 670 | admin_url('admin.php') |
| 671 | - ) . '">' |
|
| 671 | + ).'">' |
|
| 672 | 672 | ) |
| 673 | 673 | ); |
| 674 | 674 | } |
@@ -710,21 +710,21 @@ discard block |
||
| 710 | 710 | ), |
| 711 | 711 | ) |
| 712 | 712 | ); |
| 713 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 713 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | 714 | array('page' => 'espresso_registrations'), |
| 715 | 715 | admin_url('admin.php') |
| 716 | 716 | ); |
| 717 | - $items['registrations']['text'] = sprintf( |
|
| 717 | + $items['registrations']['text'] = sprintf( |
|
| 718 | 718 | _n('%s Registration', '%s Registrations', $registrations), |
| 719 | 719 | number_format_i18n($registrations) |
| 720 | 720 | ); |
| 721 | 721 | $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
| 722 | 722 | |
| 723 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 723 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | 724 | |
| 725 | 725 | foreach ($items as $type => $item_properties) { |
| 726 | 726 | $elements[] = sprintf( |
| 727 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 727 | + '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
| 728 | 728 | $item_properties['url'], |
| 729 | 729 | $item_properties['title'], |
| 730 | 730 | $item_properties['text'] |
@@ -750,10 +750,10 @@ discard block |
||
| 750 | 750 | // check for date_format or time_format |
| 751 | 751 | switch ($option) { |
| 752 | 752 | case 'date_format': |
| 753 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 753 | + $date_time_format = $value.' '.get_option('time_format'); |
|
| 754 | 754 | break; |
| 755 | 755 | case 'time_format': |
| 756 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 756 | + $date_time_format = get_option('date_format').' '.$value; |
|
| 757 | 757 | break; |
| 758 | 758 | default: |
| 759 | 759 | $date_time_format = false; |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | |
| 777 | 777 | |
| 778 | 778 | foreach ($error_msg as $error) { |
| 779 | - $msg .= '<li>' . $error . '</li>'; |
|
| 779 | + $msg .= '<li>'.$error.'</li>'; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | $msg .= '</ul></p><p>' |
@@ -18,305 +18,305 @@ |
||
| 18 | 18 | class DatetimeOffsetFix extends JobHandler |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Key for the option used to track which models have been processed when doing the batches. |
|
| 23 | - */ |
|
| 24 | - const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix'; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Key for the option used to track what the current offset is that will be applied when this tool is executed. |
|
| 31 | - */ |
|
| 32 | - const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply'; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * String labelling the datetime offset fix type for change-log entries. |
|
| 37 | - */ |
|
| 38 | - const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix'; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * String labelling a datetime offset fix error for change-log entries. |
|
| 43 | - */ |
|
| 44 | - const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EEM_Base[] |
|
| 48 | - */ |
|
| 49 | - protected $models_with_datetime_fields = array(); |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Performs any necessary setup for starting the job. This is also a good |
|
| 54 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 55 | - * when continue_job will be called |
|
| 56 | - * |
|
| 57 | - * @param JobParameters $job_parameters |
|
| 58 | - * @throws BatchRequestException |
|
| 59 | - * @return JobStepResponse |
|
| 60 | - */ |
|
| 61 | - public function create_job(JobParameters $job_parameters) |
|
| 62 | - { |
|
| 63 | - $models_with_datetime_fields = $this->getModelsWithDatetimeFields(); |
|
| 64 | - //we'll be doing each model as a batch. |
|
| 65 | - $job_parameters->set_job_size(count($models_with_datetime_fields)); |
|
| 66 | - return new JobStepResponse( |
|
| 67 | - $job_parameters, |
|
| 68 | - esc_html__('Starting Datetime Offset Fix', 'event_espresso') |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Performs another step of the job |
|
| 74 | - * |
|
| 75 | - * @param JobParameters $job_parameters |
|
| 76 | - * @param int $batch_size |
|
| 77 | - * @return JobStepResponse |
|
| 78 | - * @throws \EE_Error |
|
| 79 | - */ |
|
| 80 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 81 | - { |
|
| 82 | - $models_to_process = $this->getModelsWithDatetimeFields(); |
|
| 83 | - //let's pop off the a model and do the query to apply the offset. |
|
| 84 | - $model_to_process = array_pop($models_to_process); |
|
| 85 | - //update our record |
|
| 86 | - $this->setModelsToProcess($models_to_process); |
|
| 87 | - $this->processModel($model_to_process); |
|
| 88 | - $this->updateCountOfModelsProcessed(); |
|
| 89 | - $job_parameters->set_units_processed($this->getCountOfModelsProcessed()); |
|
| 90 | - if (count($models_to_process) > 0) { |
|
| 91 | - $job_parameters->set_status(JobParameters::status_continue); |
|
| 92 | - } else { |
|
| 93 | - $job_parameters->set_status(JobParameters::status_complete); |
|
| 94 | - } |
|
| 95 | - return new JobStepResponse( |
|
| 96 | - $job_parameters, |
|
| 97 | - sprintf( |
|
| 98 | - esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'), |
|
| 99 | - $model_to_process |
|
| 100 | - ) |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Performs any clean-up logic when we know the job is completed |
|
| 106 | - * |
|
| 107 | - * @param JobParameters $job_parameters |
|
| 108 | - * @return JobStepResponse |
|
| 109 | - * @throws BatchRequestException |
|
| 110 | - */ |
|
| 111 | - public function cleanup_job(JobParameters $job_parameters) |
|
| 112 | - { |
|
| 113 | - //delete important saved options. |
|
| 114 | - delete_option(self::MODELS_TO_PROCESS_OPTION_KEY); |
|
| 115 | - delete_option(self::COUNT_OF_MODELS_PROCESSED); |
|
| 116 | - return new JobStepResponse($job_parameters, esc_html__( |
|
| 117 | - 'Offset has been applied to all affected fields.', |
|
| 118 | - 'event_espresso' |
|
| 119 | - )); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Contains the logic for processing a model and applying the datetime offset to affected fields on that model. |
|
| 125 | - * @param string $model_class_name |
|
| 126 | - * @throws \EE_Error |
|
| 127 | - */ |
|
| 128 | - protected function processModel($model_class_name) |
|
| 129 | - { |
|
| 130 | - global $wpdb; |
|
| 131 | - /** @var EEM_Base $model */ |
|
| 132 | - $model = $model_class_name::instance(); |
|
| 133 | - $original_offset = self::getOffset(); |
|
| 134 | - $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB'; |
|
| 135 | - $offset = abs($original_offset); |
|
| 136 | - //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
|
| 137 | - foreach ($model->get_tables() as $table) { |
|
| 138 | - $query = 'UPDATE ' . $table->get_table_name(); |
|
| 139 | - $fields_affected = array(); |
|
| 140 | - $inner_query = array(); |
|
| 141 | - foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
|
| 142 | - if ($model_field instanceof EE_Datetime_Field) { |
|
| 143 | - $inner_query[] = $model_field->get_table_column() . ' = ' |
|
| 144 | - . $sql_date_function . '(' |
|
| 145 | - . $model_field->get_table_column() |
|
| 146 | - . ", INTERVAL $offset HOUR)"; |
|
| 147 | - $fields_affected[] = $model_field; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - if (! $fields_affected) { |
|
| 151 | - continue; |
|
| 152 | - } |
|
| 153 | - //k convert innerquery to string |
|
| 154 | - $query .= ' SET ' . implode(',', $inner_query); |
|
| 155 | - //execute query |
|
| 156 | - $result = $wpdb->query($query); |
|
| 157 | - //record log |
|
| 158 | - if ($result !== false) { |
|
| 159 | - $this->recordChangeLog($model, $original_offset, $table, $fields_affected); |
|
| 160 | - } else { |
|
| 161 | - //record error. |
|
| 162 | - $error_message = $wpdb->last_error; |
|
| 163 | - //handle the edgecases where last_error might be empty. |
|
| 164 | - if (! $error_message) { |
|
| 165 | - $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
|
| 166 | - } |
|
| 167 | - $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Records a changelog entry using the given information. |
|
| 175 | - * |
|
| 176 | - * @param EEM_Base $model |
|
| 177 | - * @param float $offset |
|
| 178 | - * @param EE_Table_Base $table |
|
| 179 | - * @param EE_Model_Field_Base[] $model_fields_affected |
|
| 180 | - * @param string $error_message If present then there was an error so let's record that instead. |
|
| 181 | - * @throws \EE_Error |
|
| 182 | - */ |
|
| 183 | - private function recordChangeLog( |
|
| 184 | - EEM_Base $model, |
|
| 185 | - $offset, |
|
| 186 | - EE_Table_Base $table, |
|
| 187 | - $model_fields_affected, |
|
| 188 | - $error_message = '' |
|
| 189 | - ) { |
|
| 190 | - //setup $fields list. |
|
| 191 | - $fields = array(); |
|
| 192 | - /** @var EE_Datetime_Field $model_field */ |
|
| 193 | - foreach ($model_fields_affected as $model_field) { |
|
| 194 | - if (! $model_field instanceof EE_Datetime_Field) { |
|
| 195 | - continue; |
|
| 196 | - } |
|
| 197 | - $fields[] = $model_field->get_name(); |
|
| 198 | - } |
|
| 199 | - //setup the message for the changelog entry. |
|
| 200 | - $message = $error_message |
|
| 201 | - ? sprintf( |
|
| 202 | - esc_html__( |
|
| 203 | - 'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ), |
|
| 206 | - $table->get_table_name(), |
|
| 207 | - $model->get_this_model_name(), |
|
| 208 | - $offset, |
|
| 209 | - implode(',', $fields), |
|
| 210 | - $error_message |
|
| 211 | - ) |
|
| 212 | - : sprintf( |
|
| 213 | - esc_html__( |
|
| 214 | - 'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s', |
|
| 215 | - 'event_espresso' |
|
| 216 | - ), |
|
| 217 | - $table->get_table_name(), |
|
| 218 | - $model->get_this_model_name(), |
|
| 219 | - $offset, |
|
| 220 | - implode(',', $fields) |
|
| 221 | - ); |
|
| 222 | - //write to the log |
|
| 223 | - $changelog = EE_Change_Log::new_instance(array( |
|
| 224 | - 'LOG_type' => $error_message |
|
| 225 | - ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE |
|
| 226 | - : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE, |
|
| 227 | - 'LOG_message' => $message |
|
| 228 | - )); |
|
| 229 | - $changelog->save(); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Returns an array of models that have datetime fields. |
|
| 235 | - * This array is added to a short lived transient cache to keep having to build this list to a minimum. |
|
| 236 | - * @return array an array of model class names. |
|
| 237 | - */ |
|
| 238 | - private function getModelsWithDatetimeFields() |
|
| 239 | - { |
|
| 240 | - $this->getModelsToProcess(); |
|
| 241 | - if (! empty($this->models_with_datetime_fields)) { |
|
| 242 | - return $this->models_with_datetime_fields; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models; |
|
| 246 | - foreach ($all_non_abstract_models as $non_abstract_model) { |
|
| 247 | - //get model instance |
|
| 248 | - /** @var EEM_Base $non_abstract_model */ |
|
| 249 | - $non_abstract_model = $non_abstract_model::instance(); |
|
| 250 | - if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) { |
|
| 251 | - $this->models_with_datetime_fields[] = get_class($non_abstract_model); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - $this->setModelsToProcess($this->models_with_datetime_fields); |
|
| 255 | - return $this->models_with_datetime_fields; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * This simply records the models that have been processed with our tracking option. |
|
| 261 | - * @param array $models_to_set array of model class names. |
|
| 262 | - */ |
|
| 263 | - private function setModelsToProcess($models_to_set) |
|
| 264 | - { |
|
| 265 | - update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Used to keep track of how many models have been processed for the batch |
|
| 271 | - * @param $count |
|
| 272 | - */ |
|
| 273 | - private function updateCountOfModelsProcessed($count = 1) |
|
| 274 | - { |
|
| 275 | - $count = $this->getCountOfModelsProcessed() + (int) $count; |
|
| 276 | - update_option(self::COUNT_OF_MODELS_PROCESSED, $count); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Retrieve the tracked number of models processed between requests. |
|
| 282 | - * @return int |
|
| 283 | - */ |
|
| 284 | - private function getCountOfModelsProcessed() |
|
| 285 | - { |
|
| 286 | - return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Returns the models that are left to process. |
|
| 292 | - * @return array an array of model class names. |
|
| 293 | - */ |
|
| 294 | - private function getModelsToProcess() |
|
| 295 | - { |
|
| 296 | - if (empty($this->models_with_datetime_fields)) { |
|
| 297 | - $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array()); |
|
| 298 | - } |
|
| 299 | - return $this->models_with_datetime_fields; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
| 305 | - * @param float $offset |
|
| 306 | - */ |
|
| 307 | - public static function updateOffset($offset) |
|
| 308 | - { |
|
| 309 | - update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
| 315 | - * |
|
| 316 | - * @return float |
|
| 317 | - */ |
|
| 318 | - public static function getOffset() |
|
| 319 | - { |
|
| 320 | - return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0); |
|
| 321 | - } |
|
| 21 | + /** |
|
| 22 | + * Key for the option used to track which models have been processed when doing the batches. |
|
| 23 | + */ |
|
| 24 | + const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix'; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Key for the option used to track what the current offset is that will be applied when this tool is executed. |
|
| 31 | + */ |
|
| 32 | + const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply'; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * String labelling the datetime offset fix type for change-log entries. |
|
| 37 | + */ |
|
| 38 | + const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix'; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * String labelling a datetime offset fix error for change-log entries. |
|
| 43 | + */ |
|
| 44 | + const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EEM_Base[] |
|
| 48 | + */ |
|
| 49 | + protected $models_with_datetime_fields = array(); |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Performs any necessary setup for starting the job. This is also a good |
|
| 54 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 55 | + * when continue_job will be called |
|
| 56 | + * |
|
| 57 | + * @param JobParameters $job_parameters |
|
| 58 | + * @throws BatchRequestException |
|
| 59 | + * @return JobStepResponse |
|
| 60 | + */ |
|
| 61 | + public function create_job(JobParameters $job_parameters) |
|
| 62 | + { |
|
| 63 | + $models_with_datetime_fields = $this->getModelsWithDatetimeFields(); |
|
| 64 | + //we'll be doing each model as a batch. |
|
| 65 | + $job_parameters->set_job_size(count($models_with_datetime_fields)); |
|
| 66 | + return new JobStepResponse( |
|
| 67 | + $job_parameters, |
|
| 68 | + esc_html__('Starting Datetime Offset Fix', 'event_espresso') |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Performs another step of the job |
|
| 74 | + * |
|
| 75 | + * @param JobParameters $job_parameters |
|
| 76 | + * @param int $batch_size |
|
| 77 | + * @return JobStepResponse |
|
| 78 | + * @throws \EE_Error |
|
| 79 | + */ |
|
| 80 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 81 | + { |
|
| 82 | + $models_to_process = $this->getModelsWithDatetimeFields(); |
|
| 83 | + //let's pop off the a model and do the query to apply the offset. |
|
| 84 | + $model_to_process = array_pop($models_to_process); |
|
| 85 | + //update our record |
|
| 86 | + $this->setModelsToProcess($models_to_process); |
|
| 87 | + $this->processModel($model_to_process); |
|
| 88 | + $this->updateCountOfModelsProcessed(); |
|
| 89 | + $job_parameters->set_units_processed($this->getCountOfModelsProcessed()); |
|
| 90 | + if (count($models_to_process) > 0) { |
|
| 91 | + $job_parameters->set_status(JobParameters::status_continue); |
|
| 92 | + } else { |
|
| 93 | + $job_parameters->set_status(JobParameters::status_complete); |
|
| 94 | + } |
|
| 95 | + return new JobStepResponse( |
|
| 96 | + $job_parameters, |
|
| 97 | + sprintf( |
|
| 98 | + esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'), |
|
| 99 | + $model_to_process |
|
| 100 | + ) |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Performs any clean-up logic when we know the job is completed |
|
| 106 | + * |
|
| 107 | + * @param JobParameters $job_parameters |
|
| 108 | + * @return JobStepResponse |
|
| 109 | + * @throws BatchRequestException |
|
| 110 | + */ |
|
| 111 | + public function cleanup_job(JobParameters $job_parameters) |
|
| 112 | + { |
|
| 113 | + //delete important saved options. |
|
| 114 | + delete_option(self::MODELS_TO_PROCESS_OPTION_KEY); |
|
| 115 | + delete_option(self::COUNT_OF_MODELS_PROCESSED); |
|
| 116 | + return new JobStepResponse($job_parameters, esc_html__( |
|
| 117 | + 'Offset has been applied to all affected fields.', |
|
| 118 | + 'event_espresso' |
|
| 119 | + )); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Contains the logic for processing a model and applying the datetime offset to affected fields on that model. |
|
| 125 | + * @param string $model_class_name |
|
| 126 | + * @throws \EE_Error |
|
| 127 | + */ |
|
| 128 | + protected function processModel($model_class_name) |
|
| 129 | + { |
|
| 130 | + global $wpdb; |
|
| 131 | + /** @var EEM_Base $model */ |
|
| 132 | + $model = $model_class_name::instance(); |
|
| 133 | + $original_offset = self::getOffset(); |
|
| 134 | + $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB'; |
|
| 135 | + $offset = abs($original_offset); |
|
| 136 | + //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
|
| 137 | + foreach ($model->get_tables() as $table) { |
|
| 138 | + $query = 'UPDATE ' . $table->get_table_name(); |
|
| 139 | + $fields_affected = array(); |
|
| 140 | + $inner_query = array(); |
|
| 141 | + foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
|
| 142 | + if ($model_field instanceof EE_Datetime_Field) { |
|
| 143 | + $inner_query[] = $model_field->get_table_column() . ' = ' |
|
| 144 | + . $sql_date_function . '(' |
|
| 145 | + . $model_field->get_table_column() |
|
| 146 | + . ", INTERVAL $offset HOUR)"; |
|
| 147 | + $fields_affected[] = $model_field; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + if (! $fields_affected) { |
|
| 151 | + continue; |
|
| 152 | + } |
|
| 153 | + //k convert innerquery to string |
|
| 154 | + $query .= ' SET ' . implode(',', $inner_query); |
|
| 155 | + //execute query |
|
| 156 | + $result = $wpdb->query($query); |
|
| 157 | + //record log |
|
| 158 | + if ($result !== false) { |
|
| 159 | + $this->recordChangeLog($model, $original_offset, $table, $fields_affected); |
|
| 160 | + } else { |
|
| 161 | + //record error. |
|
| 162 | + $error_message = $wpdb->last_error; |
|
| 163 | + //handle the edgecases where last_error might be empty. |
|
| 164 | + if (! $error_message) { |
|
| 165 | + $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
|
| 166 | + } |
|
| 167 | + $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Records a changelog entry using the given information. |
|
| 175 | + * |
|
| 176 | + * @param EEM_Base $model |
|
| 177 | + * @param float $offset |
|
| 178 | + * @param EE_Table_Base $table |
|
| 179 | + * @param EE_Model_Field_Base[] $model_fields_affected |
|
| 180 | + * @param string $error_message If present then there was an error so let's record that instead. |
|
| 181 | + * @throws \EE_Error |
|
| 182 | + */ |
|
| 183 | + private function recordChangeLog( |
|
| 184 | + EEM_Base $model, |
|
| 185 | + $offset, |
|
| 186 | + EE_Table_Base $table, |
|
| 187 | + $model_fields_affected, |
|
| 188 | + $error_message = '' |
|
| 189 | + ) { |
|
| 190 | + //setup $fields list. |
|
| 191 | + $fields = array(); |
|
| 192 | + /** @var EE_Datetime_Field $model_field */ |
|
| 193 | + foreach ($model_fields_affected as $model_field) { |
|
| 194 | + if (! $model_field instanceof EE_Datetime_Field) { |
|
| 195 | + continue; |
|
| 196 | + } |
|
| 197 | + $fields[] = $model_field->get_name(); |
|
| 198 | + } |
|
| 199 | + //setup the message for the changelog entry. |
|
| 200 | + $message = $error_message |
|
| 201 | + ? sprintf( |
|
| 202 | + esc_html__( |
|
| 203 | + 'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ), |
|
| 206 | + $table->get_table_name(), |
|
| 207 | + $model->get_this_model_name(), |
|
| 208 | + $offset, |
|
| 209 | + implode(',', $fields), |
|
| 210 | + $error_message |
|
| 211 | + ) |
|
| 212 | + : sprintf( |
|
| 213 | + esc_html__( |
|
| 214 | + 'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s', |
|
| 215 | + 'event_espresso' |
|
| 216 | + ), |
|
| 217 | + $table->get_table_name(), |
|
| 218 | + $model->get_this_model_name(), |
|
| 219 | + $offset, |
|
| 220 | + implode(',', $fields) |
|
| 221 | + ); |
|
| 222 | + //write to the log |
|
| 223 | + $changelog = EE_Change_Log::new_instance(array( |
|
| 224 | + 'LOG_type' => $error_message |
|
| 225 | + ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE |
|
| 226 | + : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE, |
|
| 227 | + 'LOG_message' => $message |
|
| 228 | + )); |
|
| 229 | + $changelog->save(); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Returns an array of models that have datetime fields. |
|
| 235 | + * This array is added to a short lived transient cache to keep having to build this list to a minimum. |
|
| 236 | + * @return array an array of model class names. |
|
| 237 | + */ |
|
| 238 | + private function getModelsWithDatetimeFields() |
|
| 239 | + { |
|
| 240 | + $this->getModelsToProcess(); |
|
| 241 | + if (! empty($this->models_with_datetime_fields)) { |
|
| 242 | + return $this->models_with_datetime_fields; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models; |
|
| 246 | + foreach ($all_non_abstract_models as $non_abstract_model) { |
|
| 247 | + //get model instance |
|
| 248 | + /** @var EEM_Base $non_abstract_model */ |
|
| 249 | + $non_abstract_model = $non_abstract_model::instance(); |
|
| 250 | + if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) { |
|
| 251 | + $this->models_with_datetime_fields[] = get_class($non_abstract_model); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + $this->setModelsToProcess($this->models_with_datetime_fields); |
|
| 255 | + return $this->models_with_datetime_fields; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * This simply records the models that have been processed with our tracking option. |
|
| 261 | + * @param array $models_to_set array of model class names. |
|
| 262 | + */ |
|
| 263 | + private function setModelsToProcess($models_to_set) |
|
| 264 | + { |
|
| 265 | + update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Used to keep track of how many models have been processed for the batch |
|
| 271 | + * @param $count |
|
| 272 | + */ |
|
| 273 | + private function updateCountOfModelsProcessed($count = 1) |
|
| 274 | + { |
|
| 275 | + $count = $this->getCountOfModelsProcessed() + (int) $count; |
|
| 276 | + update_option(self::COUNT_OF_MODELS_PROCESSED, $count); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Retrieve the tracked number of models processed between requests. |
|
| 282 | + * @return int |
|
| 283 | + */ |
|
| 284 | + private function getCountOfModelsProcessed() |
|
| 285 | + { |
|
| 286 | + return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Returns the models that are left to process. |
|
| 292 | + * @return array an array of model class names. |
|
| 293 | + */ |
|
| 294 | + private function getModelsToProcess() |
|
| 295 | + { |
|
| 296 | + if (empty($this->models_with_datetime_fields)) { |
|
| 297 | + $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array()); |
|
| 298 | + } |
|
| 299 | + return $this->models_with_datetime_fields; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
| 305 | + * @param float $offset |
|
| 306 | + */ |
|
| 307 | + public static function updateOffset($offset) |
|
| 308 | + { |
|
| 309 | + update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
| 315 | + * |
|
| 316 | + * @return float |
|
| 317 | + */ |
|
| 318 | + public static function getOffset() |
|
| 319 | + { |
|
| 320 | + return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0); |
|
| 321 | + } |
|
| 322 | 322 | } |
@@ -135,23 +135,23 @@ discard block |
||
| 135 | 135 | $offset = abs($original_offset); |
| 136 | 136 | //since some affected models might have two tables, we have to get our tables and set up a query for each table. |
| 137 | 137 | foreach ($model->get_tables() as $table) { |
| 138 | - $query = 'UPDATE ' . $table->get_table_name(); |
|
| 138 | + $query = 'UPDATE '.$table->get_table_name(); |
|
| 139 | 139 | $fields_affected = array(); |
| 140 | 140 | $inner_query = array(); |
| 141 | 141 | foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
| 142 | 142 | if ($model_field instanceof EE_Datetime_Field) { |
| 143 | - $inner_query[] = $model_field->get_table_column() . ' = ' |
|
| 144 | - . $sql_date_function . '(' |
|
| 143 | + $inner_query[] = $model_field->get_table_column().' = ' |
|
| 144 | + . $sql_date_function.'(' |
|
| 145 | 145 | . $model_field->get_table_column() |
| 146 | 146 | . ", INTERVAL $offset HOUR)"; |
| 147 | 147 | $fields_affected[] = $model_field; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | - if (! $fields_affected) { |
|
| 150 | + if ( ! $fields_affected) { |
|
| 151 | 151 | continue; |
| 152 | 152 | } |
| 153 | 153 | //k convert innerquery to string |
| 154 | - $query .= ' SET ' . implode(',', $inner_query); |
|
| 154 | + $query .= ' SET '.implode(',', $inner_query); |
|
| 155 | 155 | //execute query |
| 156 | 156 | $result = $wpdb->query($query); |
| 157 | 157 | //record log |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | //record error. |
| 162 | 162 | $error_message = $wpdb->last_error; |
| 163 | 163 | //handle the edgecases where last_error might be empty. |
| 164 | - if (! $error_message) { |
|
| 164 | + if ( ! $error_message) { |
|
| 165 | 165 | $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
| 166 | 166 | } |
| 167 | 167 | $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | $fields = array(); |
| 192 | 192 | /** @var EE_Datetime_Field $model_field */ |
| 193 | 193 | foreach ($model_fields_affected as $model_field) { |
| 194 | - if (! $model_field instanceof EE_Datetime_Field) { |
|
| 194 | + if ( ! $model_field instanceof EE_Datetime_Field) { |
|
| 195 | 195 | continue; |
| 196 | 196 | } |
| 197 | 197 | $fields[] = $model_field->get_name(); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | private function getModelsWithDatetimeFields() |
| 239 | 239 | { |
| 240 | 240 | $this->getModelsToProcess(); |
| 241 | - if (! empty($this->models_with_datetime_fields)) { |
|
| 241 | + if ( ! empty($this->models_with_datetime_fields)) { |
|
| 242 | 242 | return $this->models_with_datetime_fields; |
| 243 | 243 | } |
| 244 | 244 | |