PluginProbe
WP Synchro – The Ultimate WordPress Migration Tool / trunk
WP Synchro – The Ultimate WordPress Migration Tool vtrunk
1.16.1 1.16.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.11.5 1.12.0 1.13.0 1.14.0 1.15.0 1.2.0 1.3.0 1.3.1 1.3.2 All 45 releases
wpsynchro / src / Pages / AdminSupport.php

AdminSupport.php in WP Synchro – The Ultimate WordPress Migration Tool trunk, at src/Pages/AdminSupport.php

107 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class for handling what to show when clicking on support in the menu in wp-admin
5 */
6
7 namespace WPSynchro\Pages;
8
9 use WPSynchro\Utilities\CommonFunctions;
10 use WPSynchro\Utilities\DebugInformation;
11 use WPSynchro\Utilities\Licensing\Licensing;
12 use WPSynchro\Utilities\PluginDirs;
13
14 class AdminSupport
15 {
16 private $show_delete_settings_notice = false;
17
18 /**
19 * Called from WP menu to show support
20 */
21 public static function render()
22 {
23 $instance = new self();
24 // Handle post
25 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
26 $instance->handlePOST();
27 }
28 $instance->handleGET();
29 }
30
31 /**
32 * Handle the update of data from support screen
33 */
34 private function handlePOST()
35 {
36 // Check if it is delete settings
37 if (isset($_POST['deletesettings']) && $_POST['deletesettings'] == 1) {
38 $nonce = $_POST['nonce'] ?? '';
39 if (!wp_verify_nonce($nonce, 'wpsynchro_delete_all_data')) {
40 echo "<div class='notice wpsynchro-notice'><p>" . __('Security token is no longer valid - Go back and try again.', 'wpsynchro') . '</p></div>';
41 return;
42 }
43 $this->cleanUpPluginMigration();
44 $this->show_delete_settings_notice = true;
45 return;
46 }
47 }
48
49 /**
50 * Show WP Synchro support screen
51 */
52 private function handleGET()
53 {
54 $debug_obj = new DebugInformation();
55 $debug_json = $debug_obj->getJSONDebugInformation();
56
57 if (CommonFunctions::isPremiumVersion()) {
58 // Licensing
59 $licensing = new Licensing();
60 }
61
62 // Nonces
63 $delete_all_settings_nonce = wp_create_nonce('wpsynchro_delete_all_data');
64
65 // Data for JS
66 $data_for_js = [
67 'delete_all_settings_nonce' => $delete_all_settings_nonce,
68 'show_delete_settings_notice' => $this->show_delete_settings_notice,
69 'isPro' => CommonFunctions::isPremiumVersion() && $licensing->verifyLicense(),
70 'debugJson' => $debug_json,
71 ];
72 wp_localize_script('wpsynchro_admin_js', 'wpsynchro_support_data', $data_for_js);
73
74 // Print content
75 echo '<div id="wpsynchro-support" class="wpsynchro"></div>';
76 }
77
78 /**
79 * Clean up WP Synchro migration (used in setup)
80 */
81 public function cleanUpPluginMigration()
82 {
83 // Setup
84 $plugins_dirs = new PluginDirs();
85 $log_dir = $plugins_dirs->getUploadsFilePath();
86
87 // Clean files
88 @array_map('unlink', glob("$log_dir*.log"));
89 @array_map('unlink', glob("$log_dir*.sql"));
90 @array_map('unlink', glob("$log_dir*.txt"));
91 @array_map('unlink', glob("$log_dir*.tmp"));
92
93 // Delete from database
94 $options_to_keep = [
95 'wpsynchro_license_key',
96 'wpsynchro_dbversion',
97 'wpsynchro_accesskey',
98 'wpsynchro_allowed_methods',
99 'wpsynchro_muplugin_enabled',
100 'wpsynchro_uploads_dir_secret'
101 ];
102
103 global $wpdb;
104 $wpdb->query('delete FROM ' . $wpdb->options . " WHERE option_name like 'wpsynchro_%' and option_name not in ('" . implode("','", $options_to_keep) . "') ");
105 }
106 }
107