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 / AdminSetup.php

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

181 lines 9.5 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 setup in the menu in wp-admin
5 */
6
7 namespace WPSynchro\Pages;
8
9 use WPSynchro\Utilities\CommonFunctions;
10 use WPSynchro\Utilities\Configuration\PluginConfiguration;
11
12 class AdminSetup
13 {
14 private $show_update_settings_notice = false;
15 private $notices = [];
16
17 /**
18 * Called from WP menu to show setup
19 */
20 public static function render()
21 {
22 $instance = new self();
23 // Handle post
24 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
25 $instance->handlePOST();
26 }
27 $instance->handleGET();
28 }
29
30 /**
31 * Handle the update of data from setup screen
32 */
33 private function handlePOST()
34 {
35 $nonce = $_POST['nonce'] ?? '';
36 if (!wp_verify_nonce($nonce, 'wpsynchro_save_setup')) {
37 echo "<div class='notice wpsynchro-notice notice-error'><p>" . __('Security token is no longer valid - Try again.', 'wpsynchro') . '</p></div>';
38 return false;
39 }
40
41 $this->show_update_settings_notice = true;
42
43 // Plugin configuration
44 $plugin_configuration = new PluginConfiguration();
45
46 // Save access key
47 if (isset($_POST['accesskey'])) {
48 $plugin_configuration->setAccessKey($_POST['accesskey']);
49 }
50
51 // Save methods allowed
52 $pull_allowed = (isset($_POST['allow_pull']) ? true : false);
53 $push_allowed = (isset($_POST['allow_push']) ? true : false);
54 $plugin_configuration->setAllowedMigrationMethods($pull_allowed, $push_allowed);
55
56 // MU plugin enabled
57 $mu_plugin_enable = (isset($_POST['enable_muplugin']) ? true : false);
58 $mu_plugin_enable_errors = $plugin_configuration->setMUPluginEnabledState($mu_plugin_enable);
59 $this->notices = array_merge($this->notices, $mu_plugin_enable_errors);
60
61 // Slow hosting optimize
62 $slow_hosting_optimize = (isset($_POST['slow_hosting_optimize']) ? true : false);
63 $plugin_configuration->setSlowHostingSetting($slow_hosting_optimize);
64
65 // Basic auth
66 $basic_auth_username = (isset($_POST['basic_auth_username']) ? $_POST['basic_auth_username'] : '');
67 $basic_auth_password = (isset($_POST['basic_auth_password']) ? $_POST['basic_auth_password'] : '');
68 $plugin_configuration->setBasicAuthSetting($basic_auth_username, $basic_auth_password);
69
70 // Usage reporting
71 $usage_reporting = (isset($_POST['usage_reporting']) ? true : false);
72 $plugin_configuration->setUsageReportingSetting($usage_reporting);
73 }
74
75 /**
76 * Show WP Synchro setup screen
77 */
78 private function handleGET()
79 {
80 // Plugin configuration
81 $plugin_configuration = new PluginConfiguration();
82 $commonfunctions = new CommonFunctions();
83
84 $accesskey = $plugin_configuration->getAccessKey();
85 $methodsallowed = $plugin_configuration->getAllowedMigrationMethods();
86 $enable_muplugin = $plugin_configuration->getMUPluginEnabledState();
87 $enable_slow_hosting_optimize = $plugin_configuration->getSlowHostingSetting();
88
89 $basic_auth = $plugin_configuration->getBasicAuthSetting();
90 $basic_auth_username = $basic_auth['username'];
91 $basic_auth_password = $basic_auth['password'];
92
93 // Usage reporting
94 $usage_reporting = $plugin_configuration->getUsageReportingSetting();
95
96 // Save nonce
97 $nonce = wp_create_nonce('wpsynchro_save_setup');
98
99 ?>
100
101 <div class="wrap wpsynchro-setup wpsynchro">
102 <h2 class="wpsynchro-page-header-title"><img src="<?= $commonfunctions->getAssetUrl("icon.png") ?>" width="35" height="35" /> WP Synchro <?= WPSYNCHRO_VERSION ?> <?php echo (\WPSynchro\Utilities\CommonFunctions::isPremiumVersion() ? 'PRO' : 'FREE'); ?> - <?php _e('Setup', 'wpsynchro'); ?></h2>
103
104 <?php
105 if ($this->show_update_settings_notice) {
106 if (count($this->notices) > 0) {
107 ?>
108 <div class="notice notice-error wpsynchro-notice">
109 <?php
110 foreach ($this->notices as $notice) {
111 echo '<p>' . $notice . '</p>';
112 } ?>
113 </div>
114 <?php
115 } else {
116 ?>
117 <div class="notice notice-success wpsynchro-notice">
118 <p><?php _e('WP Synchro settings are now updated', 'wpsynchro'); ?></p>
119 </div>
120 <?php
121 }
122 } ?>
123
124 <form id="wpsynchro-setup-form" method="POST">
125 <input type="hidden" name="nonce" value="<?= $nonce ?>" />
126 <div class="sectionheader"><span class="dashicons dashicons-admin-tools"></span> <?php _e('Configure settings', 'wpsynchro'); ?></div>
127 <table class="">
128 <tr>
129 <td><label for="wp-synchro-accesskey"><?php _e('Access key', 'wpsynchro'); ?></label> <span title="<?= __('Configure the access key used for accessing this migration from remote. Treat the access key like a password and keep it safe from others.', 'wpsynchro') ?>" class="dashicons dashicons-editor-help"></span></td>
130 <td>
131 <input type="text" name="accesskey" id="wp-synchro-accesskey" value="<?php echo $accesskey; ?>" class="regular-text ltr" readonly>
132 <button id="copy-access-key" class="wpsynchrobutton"><?php _e('Copy', 'wpsynchro'); ?></button>
133 <button id="generate-new-access-key" class="wpsynchrobutton"><?php _e('Generate new access key', 'wpsynchro'); ?></button>
134 </td>
135 </tr>
136 <tr>
137 <td><?php _e('Allowed methods', 'wpsynchro'); ?></td>
138 <td>
139 <label><input type="checkbox" name="allow_pull" id="allow_pull" <?php echo ($methodsallowed->pull ? ' checked ' : ''); ?> /> <?php _e('Allow pull - Allow this site to be downloaded', 'wpsynchro'); ?></label><br>
140 <label><input type="checkbox" name="allow_push" id="allow_push" <?php echo ($methodsallowed->push ? ' checked ' : ''); ?> /> <?php _e('Allow push - Allow this site to be overwritten', 'wpsynchro'); ?></label>
141 </td>
142 </tr>
143 <tr>
144 <td><?php _e('Optimize compatibility', 'wpsynchro'); ?></td>
145 <td>
146 <label><input type="checkbox" name="enable_muplugin" id="enable_muplugin" <?php echo ($enable_muplugin ? ' checked ' : ''); ?>> <?php _e('Enable MU Plugin to optimize WP Synchro requests (highly recommended)', 'wpsynchro'); ?> <?= (is_multisite() ? __('(Network wide)', 'wpsynchro') : '') ?></label><br>
147 </td>
148 </tr>
149 <tr>
150 <td><?php _e('Slow hosting', 'wpsynchro'); ?> <span title="<?= __('Timeouts may happen if the two servers are geographically far apart or under heavy load. This can be enabled to better handle this and allow for large timeout margins.', 'wpsynchro') ?>" class="dashicons dashicons-editor-help"></span></td>
151 <td>
152 <label><input type="checkbox" name="slow_hosting_optimize" id="slow_hosting_optimize" <?php echo ($enable_slow_hosting_optimize ? ' checked ' : ''); ?> /> <?php _e('Optimize for slow hosting or slow connections between servers', 'wpsynchro'); ?></label>
153 </td>
154 </tr>
155
156 <tr>
157 <td><?php _e('Basic authentication', 'wpsynchro'); ?> <span title="<?= __('If this site is protected by Basic Authentication access protection, WP Synchro will try to auto-detect it, but it does not always work. In that case you need to fill out these fields. WP Synchro will use it to call local services for all migrations.', 'wpsynchro') ?>" class="dashicons dashicons-editor-help"></span></td>
158 <td>
159 <input type="text" name="basic_auth_username" value="<?= $basic_auth_username ?>" autocomplete="off" data-lpignore="true" placeholder="<?php _e('username', 'wpsynchro'); ?>">
160 <input type="password" name="basic_auth_password" value="<?= $basic_auth_password ?>" autocomplete="off" data-lpignore="true" placeholder="<?php _e('password', 'wpsynchro'); ?>">
161 <span><?php _e('WP Synchro will auto-detect these in most cases.', 'wpsynchro'); ?></span>
162 </td>
163 </tr>
164
165 <tr>
166 <td><?php _e('Usage reporting', 'wpsynchro'); ?> <span title="<?= __('Help WP Synchro become even better, by allowing us to know which features you are using when doing migrations. All reported data sent can be seen in migration log, to provide full transparency.', 'wpsynchro') ?>" class="dashicons dashicons-editor-help"></span></td>
167 <td>
168 <label><input type="checkbox" name="usage_reporting" id="usage_reporting" <?php echo ($usage_reporting ? ' checked ' : ''); ?> /> <?php _e('Allow plugin to report to developer which features are being used when doing migrations. No personal data of course.', 'wpsynchro'); ?></label>
169 </td>
170 </tr>
171
172 </table>
173 <p><input type="submit" value="<?php _e('Save settings', 'wpsynchro'); ?>" /></p>
174
175 </form>
176
177 </div>
178 <?php
179 }
180 }
181