Completed
Branch BUG-10626-dst-unit-test (0025a0)
by
unknown
105:00 queued 94:16
created
admin_pages/maintenance/Maintenance_Admin_Page.core.php 2 patches
Indentation   +730 added lines, -730 removed lines patch added patch discarded remove patch
@@ -28,749 +28,749 @@
 block discarded – undo
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("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
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("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
768
+						),
769
+						admin_url()
770
+					)
771
+				);
772
+				exit;
773
+			}
774
+		}
775
+	}
776 776
 } //end Maintenance_Admin_Page class
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -261,13 +261,13 @@  discard block
 block discarded – undo
261 261
                 && $most_recent_migration->is_broken()
262 262
             )
263 263
         ) {
264
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
264
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php';
265 265
             $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
266 266
             $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
267 267
                                                                                         'success' => '0',
268 268
             ), EE_MAINTENANCE_ADMIN_URL);
269 269
         } elseif ($addons_should_be_upgraded_first) {
270
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
270
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php';
271 271
         } else {
272 272
             if ($most_recent_migration
273 273
                 && $most_recent_migration instanceof EE_Data_Migration_Script_Base
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                 $this->_template_args['current_db_state'] = null;
298 298
                 $this->_template_args['next_db_state'] = null;
299 299
             }
300
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
300
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php';
301 301
             $this->_template_args = array_merge(
302 302
                 $this->_template_args,
303 303
                 array(
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
                 'status_completed'                 => EE_Data_Migration_Manager::status_completed,
337 337
             ));
338 338
         }
339
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
339
+        $this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration
340 340
         //now render the migration options part, and put it in a variable
341 341
         $migration_options_template_file = apply_filters(
342 342
             'FHEE__ee_migration_page__migration_options_template',
343
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
343
+            EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php'
344 344
         );
345
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
345
+        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args, true);
346 346
         $this->_template_args['migration_options_html'] = $migration_options_html;
347 347
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
348 348
             $this->_template_args, true);
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
      */
402 402
     public function _data_reset_and_delete()
403 403
     {
404
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
404
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php';
405 405
         $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
406 406
             'reset_reservations',
407 407
             'reset_reservations',
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 
439 439
     protected function _reset_reservations()
440 440
     {
441
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
441
+        if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
442 442
             EE_Error::add_success(
443 443
                 __(
444 444
                     'Ticket and datetime reserved counts have been successfully reset.',
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
      */
487 487
     public function _system_status()
488 488
     {
489
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
489
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php';
490 490
         $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
491 491
         $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
492 492
             array(
@@ -505,11 +505,11 @@  discard block
 block discarded – undo
505 505
     public function _download_system_status()
506 506
     {
507 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" );
508
+        header('Content-Disposition: attachment');
509
+        header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html");
510 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 );
511
+        echo "<h1>System Information for ".site_url()."</h1>";
512
+        echo EEH_Template::layout_array_as_table($status_info);
513 513
         die;
514 514
     }
515 515
 
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         try {
524 524
             $success = wp_mail(EE_SUPPORT_EMAIL,
525 525
                 'Migration Crash Report',
526
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
526
+                $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true),
527 527
                 array(
528 528
                     "from:$from_name<$from>",
529 529
                     //					'content-type:text/html charset=UTF-8'
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
             EE_MAINTENANCE_ADMIN_URL);
559 559
         $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
560 560
             EE_MAINTENANCE_ADMIN_URL);
561
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
561
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php';
562 562
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
563 563
             $this->_template_args, true);
564 564
         $this->display_admin_page_with_sidebar();
@@ -659,9 +659,9 @@  discard block
 block discarded – undo
659 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'),
662
+        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js', array('jquery'),
663 663
             EVENT_ESPRESSO_VERSION, true);
664
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
664
+        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(),
665 665
             EVENT_ESPRESSO_VERSION);
666 666
         wp_enqueue_style('espresso_maintenance');
667 667
     }
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
 
699 699
     protected function _get_datetime_offset_fix_form()
700 700
     {
701
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
-            $this->datetime_fix_offset_form =  new EE_Form_Section_Proper(
701
+        if ( ! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
702
+            $this->datetime_fix_offset_form = new EE_Form_Section_Proper(
703 703
                 array(
704 704
                     'name' => 'datetime_offset_fix_option',
705 705
                     'layout_strategy' => new EE_Admin_Two_Column_Layout(),
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 2 patches
Indentation   +851 added lines, -851 removed lines patch added patch discarded remove patch
@@ -15,395 +15,395 @@  discard block
 block discarded – undo
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,488 +416,488 @@  discard block
 block discarded – undo
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
-        if (! get_option('timezone_string')) {
651
-            EE_Error::add_persistent_admin_notice(
652
-                'datetime_fix_notice',
653
-                sprintf(
654
-                    esc_html__(
655
-                        '%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.',
656
-                        'event_espresso'
657
-                    ),
658
-                    '<strong>',
659
-                    '</strong>',
660
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-to-dates-and-times-in-ee">',
661
-                    '</a>',
662
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
663
-                        array(
664
-                            'page' => 'espresso_maintenance_settings',
665
-                            'action' => 'datetime_tools'
666
-                        ),
667
-                        admin_url('admin.php')
668
-                    ) . '">'
669
-                )
670
-            );
671
-        }
672
-        echo EE_Error::get_persistent_admin_notices($return_url);
673
-    }
674
-
675
-
676
-    /**
677
-     *    dismiss_persistent_admin_notice
678
-     *
679
-     * @access    public
680
-     * @return        void
681
-     */
682
-    public function dismiss_ee_nag_notice_callback()
683
-    {
684
-        EE_Error::dismiss_persistent_admin_notice();
685
-    }
686
-
687
-
688
-    /**
689
-     * @param array $elements
690
-     * @return array
691
-     * @throws \EE_Error
692
-     */
693
-    public function dashboard_glance_items($elements)
694
-    {
695
-        $elements                        = is_array($elements) ? $elements : array($elements);
696
-        $events                          = EEM_Event::instance()->count();
697
-        $items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
698
-            array('page' => 'espresso_events'),
699
-            admin_url('admin.php')
700
-        );
701
-        $items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
702
-        $items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
703
-        $registrations                   = EEM_Registration::instance()->count(
704
-            array(
705
-                array(
706
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
707
-                ),
708
-            )
709
-        );
710
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
711
-            array('page' => 'espresso_registrations'),
712
-            admin_url('admin.php')
713
-        );
714
-        $items['registrations']['text']  = sprintf(
715
-            _n('%s Registration', '%s Registrations', $registrations),
716
-            number_format_i18n($registrations)
717
-        );
718
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
719
-
720
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
721
-
722
-        foreach ($items as $type => $item_properties) {
723
-            $elements[] = sprintf(
724
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
725
-                $item_properties['url'],
726
-                $item_properties['title'],
727
-                $item_properties['text']
728
-            );
729
-        }
730
-        return $elements;
731
-    }
732
-
733
-
734
-    /**
735
-     *    check_for_invalid_datetime_formats
736
-     *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that
737
-     *    their selected format can be parsed by PHP
738
-     *
739
-     * @access    public
740
-     * @param    $value
741
-     * @param    $option
742
-     * @throws EE_Error
743
-     * @return    string
744
-     */
745
-    public function check_for_invalid_datetime_formats($value, $option)
746
-    {
747
-        // check for date_format or time_format
748
-        switch ($option) {
749
-            case 'date_format':
750
-                $date_time_format = $value . ' ' . get_option('time_format');
751
-                break;
752
-            case 'time_format':
753
-                $date_time_format = get_option('date_format') . ' ' . $value;
754
-                break;
755
-            default:
756
-                $date_time_format = false;
757
-        }
758
-        // do we have a date_time format to check ?
759
-        if ($date_time_format) {
760
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
761
-
762
-            if (is_array($error_msg)) {
763
-                $msg = '<p>'
764
-                       . sprintf(
765
-                           esc_html__(
766
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
767
-                               'event_espresso'
768
-                           ),
769
-                           date($date_time_format),
770
-                           $date_time_format
771
-                       )
772
-                       . '</p><p><ul>';
773
-
774
-
775
-                foreach ($error_msg as $error) {
776
-                    $msg .= '<li>' . $error . '</li>';
777
-                }
778
-
779
-                $msg .= '</ul></p><p>'
780
-                        . sprintf(
781
-                            esc_html__(
782
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
783
-                                'event_espresso'
784
-                            ),
785
-                            '<span style="color:#D54E21;">',
786
-                            '</span>'
787
-                        )
788
-                        . '</p>';
789
-
790
-                // trigger WP settings error
791
-                add_settings_error(
792
-                    'date_format',
793
-                    'date_format',
794
-                    $msg
795
-                );
796
-
797
-                // set format to something valid
798
-                switch ($option) {
799
-                    case 'date_format':
800
-                        $value = 'F j, Y';
801
-                        break;
802
-                    case 'time_format':
803
-                        $value = 'g:i a';
804
-                        break;
805
-                }
806
-            }
807
-        }
808
-        return $value;
809
-    }
810
-
811
-
812
-    /**
813
-     *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
814
-     *
815
-     * @access    public
816
-     * @param $content
817
-     * @return    string
818
-     */
819
-    public function its_eSpresso($content)
820
-    {
821
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
822
-    }
823
-
824
-
825
-    /**
826
-     *    espresso_admin_footer
827
-     *
828
-     * @access    public
829
-     * @return    string
830
-     */
831
-    public function espresso_admin_footer()
832
-    {
833
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
834
-    }
835
-
836
-
837
-    /**
838
-     * static method for registering ee admin page.
839
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
840
-     *
841
-     * @since      4.3.0
842
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
843
-     * @see        EE_Register_Admin_Page::register()
844
-     * @param       $page_basename
845
-     * @param       $page_path
846
-     * @param array $config
847
-     * @return void
848
-     * @throws EE_Error
849
-     */
850
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
851
-    {
852
-        EE_Error::doing_it_wrong(
853
-            __METHOD__,
854
-            sprintf(
855
-                esc_html__(
856
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
857
-                    'event_espresso'
858
-                ),
859
-                $page_basename
860
-            ),
861
-            '4.3'
862
-        );
863
-        if (class_exists('EE_Register_Admin_Page')) {
864
-            $config['page_path'] = $page_path;
865
-        }
866
-        EE_Register_Admin_Page::register($page_basename, $config);
867
-    }
868
-
869
-
870
-    /**
871
-     * @deprecated 4.8.41
872
-     * @access     public
873
-     * @param  int      $post_ID
874
-     * @param  \WP_Post $post
875
-     * @return void
876
-     */
877
-    public static function parse_post_content_on_save($post_ID, $post)
878
-    {
879
-        EE_Error::doing_it_wrong(
880
-            __METHOD__,
881
-            esc_html__('Usage is deprecated', 'event_espresso'),
882
-            '4.8.41'
883
-        );
884
-    }
885
-
886
-
887
-    /**
888
-     * @deprecated 4.8.41
889
-     * @access     public
890
-     * @param  $option
891
-     * @param  $old_value
892
-     * @param  $value
893
-     * @return void
894
-     */
895
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
896
-    {
897
-        EE_Error::doing_it_wrong(
898
-            __METHOD__,
899
-            esc_html__('Usage is deprecated', 'event_espresso'),
900
-            '4.8.41'
901
-        );
902
-    }
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
+		if (! get_option('timezone_string')) {
651
+			EE_Error::add_persistent_admin_notice(
652
+				'datetime_fix_notice',
653
+				sprintf(
654
+					esc_html__(
655
+						'%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.',
656
+						'event_espresso'
657
+					),
658
+					'<strong>',
659
+					'</strong>',
660
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-to-dates-and-times-in-ee">',
661
+					'</a>',
662
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
663
+						array(
664
+							'page' => 'espresso_maintenance_settings',
665
+							'action' => 'datetime_tools'
666
+						),
667
+						admin_url('admin.php')
668
+					) . '">'
669
+				)
670
+			);
671
+		}
672
+		echo EE_Error::get_persistent_admin_notices($return_url);
673
+	}
674
+
675
+
676
+	/**
677
+	 *    dismiss_persistent_admin_notice
678
+	 *
679
+	 * @access    public
680
+	 * @return        void
681
+	 */
682
+	public function dismiss_ee_nag_notice_callback()
683
+	{
684
+		EE_Error::dismiss_persistent_admin_notice();
685
+	}
686
+
687
+
688
+	/**
689
+	 * @param array $elements
690
+	 * @return array
691
+	 * @throws \EE_Error
692
+	 */
693
+	public function dashboard_glance_items($elements)
694
+	{
695
+		$elements                        = is_array($elements) ? $elements : array($elements);
696
+		$events                          = EEM_Event::instance()->count();
697
+		$items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
698
+			array('page' => 'espresso_events'),
699
+			admin_url('admin.php')
700
+		);
701
+		$items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
702
+		$items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
703
+		$registrations                   = EEM_Registration::instance()->count(
704
+			array(
705
+				array(
706
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
707
+				),
708
+			)
709
+		);
710
+		$items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
711
+			array('page' => 'espresso_registrations'),
712
+			admin_url('admin.php')
713
+		);
714
+		$items['registrations']['text']  = sprintf(
715
+			_n('%s Registration', '%s Registrations', $registrations),
716
+			number_format_i18n($registrations)
717
+		);
718
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
719
+
720
+		$items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
721
+
722
+		foreach ($items as $type => $item_properties) {
723
+			$elements[] = sprintf(
724
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
725
+				$item_properties['url'],
726
+				$item_properties['title'],
727
+				$item_properties['text']
728
+			);
729
+		}
730
+		return $elements;
731
+	}
732
+
733
+
734
+	/**
735
+	 *    check_for_invalid_datetime_formats
736
+	 *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that
737
+	 *    their selected format can be parsed by PHP
738
+	 *
739
+	 * @access    public
740
+	 * @param    $value
741
+	 * @param    $option
742
+	 * @throws EE_Error
743
+	 * @return    string
744
+	 */
745
+	public function check_for_invalid_datetime_formats($value, $option)
746
+	{
747
+		// check for date_format or time_format
748
+		switch ($option) {
749
+			case 'date_format':
750
+				$date_time_format = $value . ' ' . get_option('time_format');
751
+				break;
752
+			case 'time_format':
753
+				$date_time_format = get_option('date_format') . ' ' . $value;
754
+				break;
755
+			default:
756
+				$date_time_format = false;
757
+		}
758
+		// do we have a date_time format to check ?
759
+		if ($date_time_format) {
760
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
761
+
762
+			if (is_array($error_msg)) {
763
+				$msg = '<p>'
764
+					   . sprintf(
765
+						   esc_html__(
766
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
767
+							   'event_espresso'
768
+						   ),
769
+						   date($date_time_format),
770
+						   $date_time_format
771
+					   )
772
+					   . '</p><p><ul>';
773
+
774
+
775
+				foreach ($error_msg as $error) {
776
+					$msg .= '<li>' . $error . '</li>';
777
+				}
778
+
779
+				$msg .= '</ul></p><p>'
780
+						. sprintf(
781
+							esc_html__(
782
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
783
+								'event_espresso'
784
+							),
785
+							'<span style="color:#D54E21;">',
786
+							'</span>'
787
+						)
788
+						. '</p>';
789
+
790
+				// trigger WP settings error
791
+				add_settings_error(
792
+					'date_format',
793
+					'date_format',
794
+					$msg
795
+				);
796
+
797
+				// set format to something valid
798
+				switch ($option) {
799
+					case 'date_format':
800
+						$value = 'F j, Y';
801
+						break;
802
+					case 'time_format':
803
+						$value = 'g:i a';
804
+						break;
805
+				}
806
+			}
807
+		}
808
+		return $value;
809
+	}
810
+
811
+
812
+	/**
813
+	 *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
814
+	 *
815
+	 * @access    public
816
+	 * @param $content
817
+	 * @return    string
818
+	 */
819
+	public function its_eSpresso($content)
820
+	{
821
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
822
+	}
823
+
824
+
825
+	/**
826
+	 *    espresso_admin_footer
827
+	 *
828
+	 * @access    public
829
+	 * @return    string
830
+	 */
831
+	public function espresso_admin_footer()
832
+	{
833
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
834
+	}
835
+
836
+
837
+	/**
838
+	 * static method for registering ee admin page.
839
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
840
+	 *
841
+	 * @since      4.3.0
842
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
843
+	 * @see        EE_Register_Admin_Page::register()
844
+	 * @param       $page_basename
845
+	 * @param       $page_path
846
+	 * @param array $config
847
+	 * @return void
848
+	 * @throws EE_Error
849
+	 */
850
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
851
+	{
852
+		EE_Error::doing_it_wrong(
853
+			__METHOD__,
854
+			sprintf(
855
+				esc_html__(
856
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
857
+					'event_espresso'
858
+				),
859
+				$page_basename
860
+			),
861
+			'4.3'
862
+		);
863
+		if (class_exists('EE_Register_Admin_Page')) {
864
+			$config['page_path'] = $page_path;
865
+		}
866
+		EE_Register_Admin_Page::register($page_basename, $config);
867
+	}
868
+
869
+
870
+	/**
871
+	 * @deprecated 4.8.41
872
+	 * @access     public
873
+	 * @param  int      $post_ID
874
+	 * @param  \WP_Post $post
875
+	 * @return void
876
+	 */
877
+	public static function parse_post_content_on_save($post_ID, $post)
878
+	{
879
+		EE_Error::doing_it_wrong(
880
+			__METHOD__,
881
+			esc_html__('Usage is deprecated', 'event_espresso'),
882
+			'4.8.41'
883
+		);
884
+	}
885
+
886
+
887
+	/**
888
+	 * @deprecated 4.8.41
889
+	 * @access     public
890
+	 * @param  $option
891
+	 * @param  $old_value
892
+	 * @param  $value
893
+	 * @return void
894
+	 */
895
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
896
+	{
897
+		EE_Error::doing_it_wrong(
898
+			__METHOD__,
899
+			esc_html__('Usage is deprecated', 'event_espresso'),
900
+			'4.8.41'
901
+		);
902
+	}
903 903
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
                 : '',
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
         );
648 648
         $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php'));
649 649
         //add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
650
-        if (! get_option('timezone_string')) {
650
+        if ( ! get_option('timezone_string')) {
651 651
             EE_Error::add_persistent_admin_notice(
652 652
                 'datetime_fix_notice',
653 653
                 sprintf(
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
                     '</strong>',
660 660
                     '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-to-dates-and-times-in-ee">',
661 661
                     '</a>',
662
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
662
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
663 663
                         array(
664 664
                             'page' => 'espresso_maintenance_settings',
665 665
                             'action' => 'datetime_tools'
666 666
                         ),
667 667
                         admin_url('admin.php')
668
-                    ) . '">'
668
+                    ).'">'
669 669
                 )
670 670
             );
671 671
         }
@@ -707,21 +707,21 @@  discard block
 block discarded – undo
707 707
                 ),
708 708
             )
709 709
         );
710
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
710
+        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
711 711
             array('page' => 'espresso_registrations'),
712 712
             admin_url('admin.php')
713 713
         );
714
-        $items['registrations']['text']  = sprintf(
714
+        $items['registrations']['text'] = sprintf(
715 715
             _n('%s Registration', '%s Registrations', $registrations),
716 716
             number_format_i18n($registrations)
717 717
         );
718 718
         $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
719 719
 
720
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
720
+        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
721 721
 
722 722
         foreach ($items as $type => $item_properties) {
723 723
             $elements[] = sprintf(
724
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
724
+                '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>',
725 725
                 $item_properties['url'],
726 726
                 $item_properties['title'],
727 727
                 $item_properties['text']
@@ -747,10 +747,10 @@  discard block
 block discarded – undo
747 747
         // check for date_format or time_format
748 748
         switch ($option) {
749 749
             case 'date_format':
750
-                $date_time_format = $value . ' ' . get_option('time_format');
750
+                $date_time_format = $value.' '.get_option('time_format');
751 751
                 break;
752 752
             case 'time_format':
753
-                $date_time_format = get_option('date_format') . ' ' . $value;
753
+                $date_time_format = get_option('date_format').' '.$value;
754 754
                 break;
755 755
             default:
756 756
                 $date_time_format = false;
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 
774 774
 
775 775
                 foreach ($error_msg as $error) {
776
-                    $msg .= '<li>' . $error . '</li>';
776
+                    $msg .= '<li>'.$error.'</li>';
777 777
                 }
778 778
 
779 779
                 $msg .= '</ul></p><p>'
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/DatetimeOffsetFix.php 2 patches
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -18,242 +18,242 @@
 block discarded – undo
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';
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 25
 
26
-    /**
27
-     * Key for the option used to track what the current offset is that will be applied when this tool is executed.
28
-     */
29
-    const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply';
26
+	/**
27
+	 * Key for the option used to track what the current offset is that will be applied when this tool is executed.
28
+	 */
29
+	const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply';
30 30
 
31 31
 
32
-    /**
33
-     * String labelling the datetime offset fix type for changelog entries.
34
-     */
35
-    const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix';
32
+	/**
33
+	 * String labelling the datetime offset fix type for changelog entries.
34
+	 */
35
+	const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix';
36 36
 
37
-    /**
38
-     * @var EEM_Base[]
39
-     */
40
-    protected $models_with_datetime_fields = array();
37
+	/**
38
+	 * @var EEM_Base[]
39
+	 */
40
+	protected $models_with_datetime_fields = array();
41 41
 
42 42
 
43
-    /**
44
-     * Performs any necessary setup for starting the job. This is also a good
45
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
46
-     * when continue_job will be called
47
-     *
48
-     * @param JobParameters $job_parameters
49
-     * @throws BatchRequestException
50
-     * @return JobStepResponse
51
-     */
52
-    public function create_job(JobParameters $job_parameters)
53
-    {
54
-        $models_with_datetime_fields = $this->getModelsWithDatetimeFields();
55
-        //we'll be doing each model as a batch.
56
-        $job_parameters->set_job_size(count($models_with_datetime_fields));
57
-        return new JobStepResponse(
58
-            $job_parameters,
59
-            esc_html__('Starting Datetime Offset Fix', 'event_espresso')
60
-        );
61
-    }
43
+	/**
44
+	 * Performs any necessary setup for starting the job. This is also a good
45
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
46
+	 * when continue_job will be called
47
+	 *
48
+	 * @param JobParameters $job_parameters
49
+	 * @throws BatchRequestException
50
+	 * @return JobStepResponse
51
+	 */
52
+	public function create_job(JobParameters $job_parameters)
53
+	{
54
+		$models_with_datetime_fields = $this->getModelsWithDatetimeFields();
55
+		//we'll be doing each model as a batch.
56
+		$job_parameters->set_job_size(count($models_with_datetime_fields));
57
+		return new JobStepResponse(
58
+			$job_parameters,
59
+			esc_html__('Starting Datetime Offset Fix', 'event_espresso')
60
+		);
61
+	}
62 62
 
63
-    /**
64
-     * Performs another step of the job
65
-     *
66
-     * @param JobParameters $job_parameters
67
-     * @param int           $batch_size
68
-     * @return JobStepResponse
69
-     * @throws \EE_Error
70
-     */
71
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
72
-    {
73
-        $models_to_process = $this->getModelsWithDatetimeFields();
74
-        //let's pop off the a model and do the query to apply the offset.
75
-        $model_to_process = array_pop($models_to_process);
76
-        //update our record
77
-        $this->setModelsToProcess($models_to_process);
78
-        $this->processModel($model_to_process);
79
-        $job_parameters->set_units_processed(1);
80
-        if (count($models_to_process) > 0) {
81
-            $job_parameters->set_status(JobParameters::status_continue);
82
-        } else {
83
-            $job_parameters->set_status(JobParameters::status_complete);
84
-        }
85
-        return new JobStepResponse(
86
-            $job_parameters,
87
-            sprintf(
88
-                esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'),
89
-                $model_to_process
90
-            )
91
-        );
92
-    }
63
+	/**
64
+	 * Performs another step of the job
65
+	 *
66
+	 * @param JobParameters $job_parameters
67
+	 * @param int           $batch_size
68
+	 * @return JobStepResponse
69
+	 * @throws \EE_Error
70
+	 */
71
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
72
+	{
73
+		$models_to_process = $this->getModelsWithDatetimeFields();
74
+		//let's pop off the a model and do the query to apply the offset.
75
+		$model_to_process = array_pop($models_to_process);
76
+		//update our record
77
+		$this->setModelsToProcess($models_to_process);
78
+		$this->processModel($model_to_process);
79
+		$job_parameters->set_units_processed(1);
80
+		if (count($models_to_process) > 0) {
81
+			$job_parameters->set_status(JobParameters::status_continue);
82
+		} else {
83
+			$job_parameters->set_status(JobParameters::status_complete);
84
+		}
85
+		return new JobStepResponse(
86
+			$job_parameters,
87
+			sprintf(
88
+				esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'),
89
+				$model_to_process
90
+			)
91
+		);
92
+	}
93 93
 
94
-    /**
95
-     * Performs any clean-up logic when we know the job is completed
96
-     *
97
-     * @param JobParameters $job_parameters
98
-     * @return JobStepResponse
99
-     * @throws BatchRequestException
100
-     */
101
-    public function cleanup_job(JobParameters $job_parameters)
102
-    {
103
-        //delete important saved options.
104
-        delete_option(self::MODELS_TO_PROCESS_OPTION_KEY);
105
-        return new JobStepResponse($job_parameters, esc_html__(
106
-            'Offset has been applied to all affected fields.',
107
-            'event_espresso'
108
-        ));
109
-    }
94
+	/**
95
+	 * Performs any clean-up logic when we know the job is completed
96
+	 *
97
+	 * @param JobParameters $job_parameters
98
+	 * @return JobStepResponse
99
+	 * @throws BatchRequestException
100
+	 */
101
+	public function cleanup_job(JobParameters $job_parameters)
102
+	{
103
+		//delete important saved options.
104
+		delete_option(self::MODELS_TO_PROCESS_OPTION_KEY);
105
+		return new JobStepResponse($job_parameters, esc_html__(
106
+			'Offset has been applied to all affected fields.',
107
+			'event_espresso'
108
+		));
109
+	}
110 110
 
111 111
 
112
-    /**
113
-     * Contains the logic for processing a model and applying the datetime offset to affected fields on that model.
114
-     * @param string $model_class_name
115
-     * @throws \EE_Error
116
-     */
117
-    protected function processModel($model_class_name)
118
-    {
119
-        global $wpdb;
120
-        /** @var EEM_Base $model */
121
-        $model = $model_class_name::instance();
122
-        $original_offset = self::getOffset();
123
-        $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB';
124
-        $offset = abs($original_offset);
125
-        //since some affected models might have two tables, we have to get our tables and set up a query for each table.
126
-        foreach ($model->get_tables() as $table) {
127
-            $query = 'UPDATE ' . $table->get_table_name();
128
-            $fields_affected = array();
129
-            $inner_query = array();
130
-            foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
131
-                if ($model_field instanceof EE_Datetime_Field) {
132
-                    $inner_query[] = $model_field->get_table_column() . ' = '
133
-                                     . $sql_date_function . '('
134
-                                     . $model_field->get_table_column()
135
-                                     . ", INTERVAL $offset HOUR)";
136
-                    $fields_affected[] = $model_field;
137
-                }
138
-            }
139
-            if (! $fields_affected) {
140
-                continue;
141
-            }
142
-            //k convert innerquery to string
143
-            $query .= ' SET ' . implode(',', $inner_query);
144
-            //execute query
145
-            $wpdb->query($query);
146
-            //record log
147
-            $this->recordChangeLog($model, $original_offset, $table, $fields_affected);
148
-        }
149
-    }
112
+	/**
113
+	 * Contains the logic for processing a model and applying the datetime offset to affected fields on that model.
114
+	 * @param string $model_class_name
115
+	 * @throws \EE_Error
116
+	 */
117
+	protected function processModel($model_class_name)
118
+	{
119
+		global $wpdb;
120
+		/** @var EEM_Base $model */
121
+		$model = $model_class_name::instance();
122
+		$original_offset = self::getOffset();
123
+		$sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB';
124
+		$offset = abs($original_offset);
125
+		//since some affected models might have two tables, we have to get our tables and set up a query for each table.
126
+		foreach ($model->get_tables() as $table) {
127
+			$query = 'UPDATE ' . $table->get_table_name();
128
+			$fields_affected = array();
129
+			$inner_query = array();
130
+			foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
131
+				if ($model_field instanceof EE_Datetime_Field) {
132
+					$inner_query[] = $model_field->get_table_column() . ' = '
133
+									 . $sql_date_function . '('
134
+									 . $model_field->get_table_column()
135
+									 . ", INTERVAL $offset HOUR)";
136
+					$fields_affected[] = $model_field;
137
+				}
138
+			}
139
+			if (! $fields_affected) {
140
+				continue;
141
+			}
142
+			//k convert innerquery to string
143
+			$query .= ' SET ' . implode(',', $inner_query);
144
+			//execute query
145
+			$wpdb->query($query);
146
+			//record log
147
+			$this->recordChangeLog($model, $original_offset, $table, $fields_affected);
148
+		}
149
+	}
150 150
 
151 151
 
152
-    /**
153
-     * Records a changelog entry using the given information.
154
-     * @param EEM_Base              $model
155
-     * @param float                 $offset
156
-     * @param EE_Table_Base         $table
157
-     * @param EE_Model_Field_Base[] $model_fields_affected
158
-     * @throws \EE_Error
159
-     */
160
-    private function recordChangeLog(EEM_Base $model, $offset, EE_Table_Base $table, $model_fields_affected)
161
-    {
162
-        //setup $fields list.
163
-        $fields = array();
164
-        /** @var EE_Datetime_Field $model_field */
165
-        foreach ($model_fields_affected as $model_field) {
166
-            if (! $model_field instanceof EE_Datetime_Field) {
167
-                continue;
168
-            }
169
-            $fields[] = $model_field->get_name();
170
-        }
171
-        //setup the message for the changelog entry.
172
-        $message = sprintf(
173
-            esc_html__(
174
-                'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s',
175
-                'event_espresso'
176
-            ),
177
-            $table->get_table_name(),
178
-            $model->get_this_model_name(),
179
-            $offset,
180
-            implode(',', $fields)
181
-        );
182
-        //write to the log
183
-        $changelog = EE_Change_Log::new_instance(array(
184
-            'LOG_type' => self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE,
185
-            'LOG_message' => $message
186
-        ));
187
-        $changelog->save();
188
-    }
152
+	/**
153
+	 * Records a changelog entry using the given information.
154
+	 * @param EEM_Base              $model
155
+	 * @param float                 $offset
156
+	 * @param EE_Table_Base         $table
157
+	 * @param EE_Model_Field_Base[] $model_fields_affected
158
+	 * @throws \EE_Error
159
+	 */
160
+	private function recordChangeLog(EEM_Base $model, $offset, EE_Table_Base $table, $model_fields_affected)
161
+	{
162
+		//setup $fields list.
163
+		$fields = array();
164
+		/** @var EE_Datetime_Field $model_field */
165
+		foreach ($model_fields_affected as $model_field) {
166
+			if (! $model_field instanceof EE_Datetime_Field) {
167
+				continue;
168
+			}
169
+			$fields[] = $model_field->get_name();
170
+		}
171
+		//setup the message for the changelog entry.
172
+		$message = sprintf(
173
+			esc_html__(
174
+				'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s',
175
+				'event_espresso'
176
+			),
177
+			$table->get_table_name(),
178
+			$model->get_this_model_name(),
179
+			$offset,
180
+			implode(',', $fields)
181
+		);
182
+		//write to the log
183
+		$changelog = EE_Change_Log::new_instance(array(
184
+			'LOG_type' => self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE,
185
+			'LOG_message' => $message
186
+		));
187
+		$changelog->save();
188
+	}
189 189
 
190 190
 
191
-    /**
192
-     * Returns an array of models that have datetime fields.
193
-     * This array is added to a short lived transient cache to keep having to build this list to a minimum.
194
-     * @return array  an array of model class names.
195
-     */
196
-    private function getModelsWithDatetimeFields()
197
-    {
198
-        $this->getModelsToProcess();
199
-        if (! empty($this->models_with_datetime_fields)) {
200
-            return $this->models_with_datetime_fields;
201
-        }
191
+	/**
192
+	 * Returns an array of models that have datetime fields.
193
+	 * This array is added to a short lived transient cache to keep having to build this list to a minimum.
194
+	 * @return array  an array of model class names.
195
+	 */
196
+	private function getModelsWithDatetimeFields()
197
+	{
198
+		$this->getModelsToProcess();
199
+		if (! empty($this->models_with_datetime_fields)) {
200
+			return $this->models_with_datetime_fields;
201
+		}
202 202
 
203
-        $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models;
204
-        foreach ($all_non_abstract_models as $non_abstract_model) {
205
-            //get model instance
206
-            /** @var EEM_Base $non_abstract_model */
207
-            $non_abstract_model = $non_abstract_model::instance();
208
-            if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) {
209
-                $this->models_with_datetime_fields[] = get_class($non_abstract_model);
210
-            }
211
-        }
212
-        $this->setModelsToProcess($this->models_with_datetime_fields);
213
-        return $this->models_with_datetime_fields;
214
-    }
203
+		$all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models;
204
+		foreach ($all_non_abstract_models as $non_abstract_model) {
205
+			//get model instance
206
+			/** @var EEM_Base $non_abstract_model */
207
+			$non_abstract_model = $non_abstract_model::instance();
208
+			if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) {
209
+				$this->models_with_datetime_fields[] = get_class($non_abstract_model);
210
+			}
211
+		}
212
+		$this->setModelsToProcess($this->models_with_datetime_fields);
213
+		return $this->models_with_datetime_fields;
214
+	}
215 215
 
216 216
 
217
-    /**
218
-     * This simply records the models that have been processed with our tracking option.
219
-     * @param array $models_to_set  array of model class names.
220
-     */
221
-    private function setModelsToProcess($models_to_set)
222
-    {
223
-        update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set);
224
-    }
217
+	/**
218
+	 * This simply records the models that have been processed with our tracking option.
219
+	 * @param array $models_to_set  array of model class names.
220
+	 */
221
+	private function setModelsToProcess($models_to_set)
222
+	{
223
+		update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set);
224
+	}
225 225
 
226 226
 
227
-    /**
228
-     * Returns the models that are left to process.
229
-     * @return array  an array of model class names.
230
-     */
231
-    private function getModelsToProcess()
232
-    {
233
-        if (empty($this->models_with_datetime_fields)) {
234
-            $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array());
235
-        }
236
-        return $this->models_with_datetime_fields;
237
-    }
227
+	/**
228
+	 * Returns the models that are left to process.
229
+	 * @return array  an array of model class names.
230
+	 */
231
+	private function getModelsToProcess()
232
+	{
233
+		if (empty($this->models_with_datetime_fields)) {
234
+			$this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array());
235
+		}
236
+		return $this->models_with_datetime_fields;
237
+	}
238 238
 
239 239
 
240
-    /**
241
-     * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns.
242
-     * @param float $offset
243
-     */
244
-    public static function updateOffset($offset)
245
-    {
246
-        update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset);
247
-    }
240
+	/**
241
+	 * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns.
242
+	 * @param float $offset
243
+	 */
244
+	public static function updateOffset($offset)
245
+	{
246
+		update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset);
247
+	}
248 248
 
249 249
 
250
-    /**
251
-     * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns.
252
-     *
253
-     * @return float
254
-     */
255
-    public static function getOffset()
256
-    {
257
-        return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0);
258
-    }
250
+	/**
251
+	 * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns.
252
+	 *
253
+	 * @return float
254
+	 */
255
+	public static function getOffset()
256
+	{
257
+		return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0);
258
+	}
259 259
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -124,23 +124,23 @@  discard block
 block discarded – undo
124 124
         $offset = abs($original_offset);
125 125
         //since some affected models might have two tables, we have to get our tables and set up a query for each table.
126 126
         foreach ($model->get_tables() as $table) {
127
-            $query = 'UPDATE ' . $table->get_table_name();
127
+            $query = 'UPDATE '.$table->get_table_name();
128 128
             $fields_affected = array();
129 129
             $inner_query = array();
130 130
             foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) {
131 131
                 if ($model_field instanceof EE_Datetime_Field) {
132
-                    $inner_query[] = $model_field->get_table_column() . ' = '
133
-                                     . $sql_date_function . '('
132
+                    $inner_query[] = $model_field->get_table_column().' = '
133
+                                     . $sql_date_function.'('
134 134
                                      . $model_field->get_table_column()
135 135
                                      . ", INTERVAL $offset HOUR)";
136 136
                     $fields_affected[] = $model_field;
137 137
                 }
138 138
             }
139
-            if (! $fields_affected) {
139
+            if ( ! $fields_affected) {
140 140
                 continue;
141 141
             }
142 142
             //k convert innerquery to string
143
-            $query .= ' SET ' . implode(',', $inner_query);
143
+            $query .= ' SET '.implode(',', $inner_query);
144 144
             //execute query
145 145
             $wpdb->query($query);
146 146
             //record log
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         $fields = array();
164 164
         /** @var EE_Datetime_Field $model_field */
165 165
         foreach ($model_fields_affected as $model_field) {
166
-            if (! $model_field instanceof EE_Datetime_Field) {
166
+            if ( ! $model_field instanceof EE_Datetime_Field) {
167 167
                 continue;
168 168
             }
169 169
             $fields[] = $model_field->get_name();
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
     private function getModelsWithDatetimeFields()
197 197
     {
198 198
         $this->getModelsToProcess();
199
-        if (! empty($this->models_with_datetime_fields)) {
199
+        if ( ! empty($this->models_with_datetime_fields)) {
200 200
             return $this->models_with_datetime_fields;
201 201
         }
202 202
 
Please login to merge, or discard this patch.