PluginProbe ʕ •ᴥ•ʔ
UpdraftPlus: WP Backup & Migration Plugin / 1.12.40
UpdraftPlus: WP Backup & Migration Plugin v1.12.40
1.26.4 1.26.3 1.9.19 1.9.25 1.9.26 1.9.30 1.9.31 1.9.32 1.9.4 1.9.40 1.9.41 1.9.42 1.9.43 1.9.44 1.9.45 1.9.46 1.9.5 1.9.50 1.9.51 1.9.60 1.9.62 1.9.63 1.9.64 1.11.12 1.4.8 1.11.15 1.4.9 1.11.17 1.5.16 1.11.18 1.5.20 1.11.2 1.5.21 1.11.20 1.5.22 1.11.23 1.5.5 1.11.24 1.5.6 1.11.25 1.5.7 1.11.26 1.5.8 1.11.27 1.5.9 1.11.28 1.6.1 1.11.3 1.6.17 1.11.4 1.6.2 1.11.5 1.6.46 1.11.8 1.7.0 1.11.9 1.7.1 1.12.0 1.7.18 1.12.1 1.7.20 1.12.12 1.7.3 1.12.13 1.7.34 1.12.15 1.7.35 1.12.17 1.7.39 1.12.2 1.7.40 1.12.20 1.7.41 1.12.23 1.8.1 1.12.24 1.8.11 1.12.25 1.8.12 1.12.28 1.8.13 1.12.29 1.8.2 1.12.30 1.8.5 1.12.32 1.8.8 1.12.34 1.9.0 1.12.35 1.9.13 1.12.37 1.9.15 1.12.39 1.9.17 1.12.4 1.12.40 1.12.6 1.13.1 1.13.11 1.13.12 1.13.15 1.13.16 1.13.2 1.13.3 1.13.4 1.13.5 1.13.6 1.13.7 1.13.8 1.13.9 1.14.10 1.14.11 1.14.12 1.14.13 1.14.2 1.14.3 1.14.4 1.14.5 1.14.7 1.14.9 1.15.0 1.15.2 1.15.3 1.15.5 1.15.6 1.15.7 1.16.0 1.16.10 1.16.11 1.16.12 1.16.13 1.16.14 1.16.15 1.16.16 1.16.17 1.16.20 1.16.21 1.16.22 1.16.23 1.16.24 1.16.25 1.16.26 1.16.28 1.16.29 1.16.32 1.16.34 1.16.35 1.16.36 1.16.37 1.16.4 1.16.40 1.16.41 1.16.42 1.16.43 1.16.44 1.16.45 1.16.46 1.16.47 1.16.48 1.16.49 1.16.5 1.16.50 1.16.51 1.16.53 1.16.55 1.16.56 1.16.59 1.16.6 1.16.60 1.16.61 1.16.62 1.16.63 1.16.64 1.16.65 1.16.66 1.16.67 1.16.68 1.16.69 1.16.7 1.16.8 1.16.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.14 1.2.15 1.2.16 1.2.17 1.2.19 1.2.2 1.2.20 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.33 1.2.35 1.2.36 1.2.38 1.2.39 1.2.4 1.2.40 1.2.41 1.2.42 1.2.43 1.2.44 1.2.45 1.2.46 1.2.5 1.2.7 1.2.8 1.2.9 1.22.1 1.22.10 1.22.11 1.22.12 1.22.14 1.22.15 1.22.16 1.22.17 1.22.18 1.22.19 1.22.20 1.22.21 1.22.22 1.22.23 1.22.24 1.22.3 1.22.4 1.22.5 1.22.6 1.22.7 1.22.8 1.22.9 1.23.1 1.23.10 1.23.11 1.23.12 1.23.13 1.23.15 1.23.16 1.23.2 1.23.3 1.23.4 1.23.5 1.23.6 1.23.7 1.23.8 1.23.9 1.24.1 1.24.10 1.24.11 1.24.12 1.24.2 trunk 1.24.3 0.7.4 1.24.4 0.7.7 1.24.5 0.8.28 1.24.6 0.8.29 1.24.7 0.8.30 1.24.8 0.8.31 1.24.9 0.8.32 1.25.1 0.8.33 1.25.2 0.8.36 1.25.3 0.8.37 1.25.5 0.8.50 1.25.6 0.8.51 1.25.7 0.9.1 1.25.8 0.9.10 1.25.9 0.9.11 1.26.1 0.9.12 1.26.2 0.9.2 1.3.10 0.9.20 1.3.12 0.9.21 1.3.14 0.9.22 1.3.15 1.0.10 1.3.17 1.0.11 1.3.18 1.0.12 1.3.19 1.0.15 1.3.2 1.0.16 1.3.20 1.0.18 1.3.22 1.0.20 1.3.23 1.0.3 1.3.24 1.0.4 1.3.25 1.0.5 1.3.3 1.0.6 1.3.4 1.0.7 1.3.6 1.0.8 1.3.7 1.0.9 1.3.8 1.1.0 1.3.9 1.1.10 1.4.0 1.1.11 1.4.10 1.1.12 1.4.11 1.1.13 1.4.12 1.1.14 1.4.13 1.1.15 1.4.14 1.1.16 1.4.15 1.1.17 1.4.2 1.1.2 1.4.27 1.1.3 1.4.28 1.1.5 1.4.29 1.1.6 1.4.30 1.1.8 1.4.4 1.1.9 1.4.48 1.10.1 1.4.5 1.10.3 1.4.6 1.11.1 1.4.7
updraftplus / includes / class-commands.php
updraftplus / includes Last commit date
Dropbox 9 years ago Dropbox2 9 years ago Google 9 years ago cloudfiles 12 years ago images 9 years ago labelauty 9 years ago phpseclib 9 years ago S3.php 9 years ago S3compat.php 9 years ago cacert.pem 9 years ago class-commands.php 9 years ago class-database-utility.php 9 years ago class-partialfileservlet.php 9 years ago class-semaphore.php 9 years ago class-udrpc.php 9 years ago class-updraftcentral-updraftplus-commands.php 9 years ago class-wpadmin-commands.php 9 years ago deprecated-actions.php 9 years ago ftp.class.php 9 years ago get-cpanel-quota-usage.pl 12 years ago google-extensions.php 9 years ago jquery-ui.custom.css 9 years ago jquery.blockUI.js 9 years ago updraft-admin.js 9 years ago updraft-notices.php 9 years ago updraftplus-notices.php 9 years ago
class-commands.php
584 lines
1 <?php
2
3 if (!defined('UPDRAFTPLUS_DIR')) die('No access.');
4
5 /*
6 - A container for all the remote commands implemented. Commands map exactly onto method names (and hence this class should not implement anything else, beyond the constructor, and private methods)
7 - Return format is either to return data (boolean, string, array), or an WP_Error object
8
9 Commands are not allowed to begin with an underscore. So, any private methods can be prefixed with an underscore.
10
11 TODO: Many of these just verify input, and then call back into a relevant method in UpdraftPlus_Admin. Once all commands have been ported over to go via this class, those methods in UpdraftPlus_Admin can generally be folded into the relevant method in here, and removed from UpdraftPlus_Admin. (Since this class is intended to become the official way of performing actions). As a bonus, we then won't need so much _load_ud(_admin) boilerplate.
12
13 */
14
15 if (class_exists('UpdraftPlus_Commands')) return;
16
17 class UpdraftPlus_Commands {
18
19 private $_uc_helper;
20
21 // The 'helper' needs to provide the method _updraftplus_background_operation_started
22 public function __construct($uc_helper) {
23 $this->_uc_helper = $uc_helper;
24 }
25
26 //Get the Advanced Tools HTMl and return to Central
27 public function get_advanced_settings($options) {
28 //load global updraftplus and admin
29 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
30 if (false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
31
32 $html = $updraftplus_admin->settings_advanced_tools(true, array('options' => $options));
33
34 return $html;
35 }
36
37 public function get_download_status($items) {
38 //load global updraftplus and admin
39 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
40
41 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
42
43 if (!is_array($items)) $items = array();
44
45 return $updraftplus_admin->get_download_statuses($items);
46
47 }
48
49 public function downloader($downloader_params) {
50
51 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
52
53 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
54
55 $findex = $downloader_params['findex'];
56 $type = $downloader_params['type'];
57 $timestamp = $downloader_params['timestamp'];
58 // Valid stages: 2='spool the data'|'delete'='delete local copy'|anything else='make sure it is present'
59 $stage = empty($downloader_params['stage']) ? false : $downloader_params['stage'];
60
61 // This may, or may not, return, depending upon whether the files are already downloaded
62 // The response is usually an array with key 'result', and values deleted|downloaded|needs_download|download_failed
63 $response = $updraftplus_admin->do_updraft_download_backup($findex, $type, $timestamp, $stage, array($this->_uc_helper, '_updraftplus_background_operation_started'));
64
65 if (is_array($response)) {
66 $response['request'] = $downloader_params;
67 }
68
69 return $response;
70 }
71
72 public function delete_downloaded($set_info) {
73 $set_info['stage'] = 'delete';
74 return $this->downloader($set_info);
75 }
76
77 public function backup_progress($params) {
78
79 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
80
81 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
82
83 $request = array(
84 'thisjobonly' => $params['job_id']
85 );
86
87 $activejobs_list = $updraftplus_admin->get_activejobs_list($request);
88
89 return $activejobs_list;
90
91 }
92
93 public function backupnow($params) {
94
95 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
96
97 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
98
99 $updraftplus_admin->request_backupnow($params, array($this->_uc_helper, '_updraftplus_background_operation_started'));
100
101 // Control returns when the backup finished; but, the browser connection should have been closed before
102 die;
103 }
104
105 private function _load_ud() {
106 global $updraftplus;
107 return is_a($updraftplus, 'UpdraftPlus') ? $updraftplus : false;
108 }
109
110 private function _load_ud_admin() {
111 if (!defined('UPDRAFTPLUS_DIR') || !is_file(UPDRAFTPLUS_DIR.'/admin.php')) return false;
112 require_once(UPDRAFTPLUS_DIR.'/admin.php');
113 global $updraftplus_admin;
114 return $updraftplus_admin;
115 }
116
117 public function get_log($job_id = '') {
118
119 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
120
121 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
122
123 if ('' != $job_id && !preg_match("/^[0-9a-f]{12}$/", $job_id)) return new WP_Error('updraftplus_permission_invalid_jobid');
124
125 return $updraftplus_admin->fetch_log($job_id);
126
127 }
128
129 public function activejobs_delete($job_id) {
130
131 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
132
133 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
134
135 return $updraftplus_admin->activejobs_delete((string)$job_id);
136
137 }
138
139 public function deleteset($what) {
140
141 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
142
143 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
144
145 $results = $updraftplus_admin->delete_set($what);
146
147 $get_history_opts = isset($what['get_history_opts']) ? $what['get_history_opts'] : array();
148
149 $backup_history = UpdraftPlus_Options::get_updraft_option('updraft_backup_history');
150 $backup_history = is_array($backup_history) ? $backup_history : array();
151
152 $history = $updraftplus_admin->settings_downloading_and_restoring($backup_history, true, $get_history_opts);
153
154 $results['history'] = $history;
155
156 $results['count_backups'] = count($backup_history);
157
158 return $results;
159
160 }
161
162 // Slightly misnamed - this doesn't always rescan, but it does always return the history status (possibly after a rescan)
163 public function rescan($what) {
164
165 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
166
167 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
168
169 $remotescan = ('remotescan' == $what);
170 $rescan = ($remotescan || 'rescan' == $what);
171
172 $history_status = $updraftplus_admin->get_history_status($rescan, $remotescan);
173
174 return $history_status;
175
176 }
177
178 public function get_settings($options) {
179 if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
180
181 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
182
183 ob_start();
184 $updraftplus_admin->settings_formcontents($options);
185 $output = ob_get_contents();
186 ob_end_clean();
187
188 return array(
189 'settings' => $output,
190 'meta' => apply_filters('updraftplus_get_settings_meta', array()),
191 );
192
193 }
194
195 public function test_storage_settings($test_data) {
196
197 if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
198
199 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
200
201 ob_start();
202 $updraftplus_admin->do_credentials_test($test_data);
203 $output = ob_get_contents();
204 ob_end_clean();
205
206 return array(
207 'output' => $output,
208 );
209
210 }
211
212 public function extradb_testconnection($info) {
213
214 if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
215
216 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
217
218 $results = apply_filters('updraft_extradb_testconnection_go', array(), $info);
219
220 return $results;
221
222 }
223
224 public function vault_recountquota() {
225 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
226
227 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
228
229 $vault = $updraftplus_admin->get_updraftvault();
230
231 return $vault->ajax_vault_recountquota(false);
232 }
233
234 public function vault_connect($credentials) {
235
236 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
237
238 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
239
240 return $updraftplus_admin->get_updraftvault()->ajax_vault_connect(false, $credentials);
241
242 }
243
244 public function vault_disconnect($params = array()) {
245
246 if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
247
248 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
249
250 $echo_results = empty($params['immediate_echo']) ? false : true;
251
252 $results = (array)$updraftplus_admin->get_updraftvault()->ajax_vault_disconnect($echo_results);
253
254 return $results;
255
256 }
257
258 public function vault_recount_quota() {
259 if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
260
261 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
262
263 $results = $updraftplus_admin->get_updraftvault()->ajax_vault_recountquota(false);
264
265 return $results;
266 }
267
268 /**
269 * A handler method to call the UpdraftPlus admin save settings method. It will check if the settings passed to it are in the format of a string if so it converts it to an array otherwise just pass the array
270 * @param String/Array $settings Settings to be saved to UpdraftPlus either in the form of a string ready to be converted to an array or already an array ready to be passed to the save settings function in UpdraftPlus.
271 * @return Array An Array response to be sent back
272 */
273 public function save_settings($settings) {
274
275 if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
276
277 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
278
279 if (!empty($settings)) {
280
281 if (is_string($settings)) {
282 parse_str($settings, $settings_as_array);
283 } elseif (is_array($settings)) {
284 $settings_as_array = $settings;
285 } else {
286 return new WP_Error('invalid_settings');
287 }
288 }
289
290 $results = $updraftplus_admin->save_settings($settings_as_array);
291
292 return $results;
293
294 }
295
296 public function s3_newuser($data) {
297 if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
298
299 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
300 $results = apply_filters('updraft_s3_newuser_go', array(), $data);
301
302 return $results;
303 }
304
305 public function cloudfiles_newuser($data) {
306
307 global $updraftplus_addon_cloudfilesenhanced;
308 if (!is_a($updraftplus_addon_cloudfilesenhanced, 'UpdraftPlus_Addon_CloudFilesEnhanced')) {
309 $data = array('e' => 1, 'm' => sprintf(__('%s add-on not found', 'updraftplus'), 'Rackspace Cloud Files'));
310 } else {
311 $data = $updraftplus_addon_cloudfilesenhanced->create_api_user($data);
312 }
313
314 if ($data["e"] === 0) {
315 return $data;
316 } else {
317 return new WP_Error('error', '', $data);
318 }
319 }
320
321 public function get_fragment($fragment) {
322
323 if (false === ($updraftplus_admin = $this->_load_ud_admin()) || false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
324
325 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
326
327 if (is_array($fragment)) {
328 $data = $fragment['data'];
329 $fragment = $fragment['fragment'];
330 }
331
332 $error = false;
333
334 switch ($fragment) {
335
336 case 'last_backup_html':
337 $output = $updraftplus_admin->last_backup_html();
338 break;
339
340 case 's3_new_api_user_form':
341 ob_start();
342 do_action('updraft_s3_print_new_api_user_form', false);
343 $output = ob_get_contents();
344 ob_end_clean();
345 break;
346
347 case 'cloudfiles_new_api_user_form':
348 global $updraftplus_addon_cloudfilesenhanced;
349 if (!is_a($updraftplus_addon_cloudfilesenhanced, 'UpdraftPlus_Addon_CloudFilesEnhanced')) {
350 $error = true;
351 $output = 'cloudfiles_addon_not_found';
352 } else {
353 $output = array(
354 'accounts' => $updraftplus_addon_cloudfilesenhanced->account_options(),
355 'regions' => $updraftplus_addon_cloudfilesenhanced->region_options(),
356 );
357 }
358 break;
359
360 case 'backupnow_modal_contents':
361 $updraft_dir = $updraftplus->backups_dir_location();
362 if (!$updraftplus->really_is_writable($updraft_dir)) {
363 $output = array('error' => true, 'html' => __("The 'Backup Now' button is disabled as your backup directory is not writable (go to the 'Settings' tab and find the relevant option).", 'updraftplus'));
364 } else {
365 $output = array('html' => $updraftplus_admin->backupnow_modal_contents());
366 }
367 break;
368
369 case 'panel_download_and_restore':
370 $backup_history = UpdraftPlus_Options::get_updraft_option('updraft_backup_history');
371 if (empty($backup_history)) {
372 $updraftplus->rebuild_backup_history();
373 $backup_history = UpdraftPlus_Options::get_updraft_option('updraft_backup_history');
374 }
375 $backup_history = is_array($backup_history) ? $backup_history : array();
376
377 $output = $updraftplus_admin->settings_downloading_and_restoring($backup_history, true, $data);
378 break;
379
380 case 'disk_usage':
381 $output = $updraftplus_admin->get_disk_space_used($data);
382 break;
383 default:
384 // We just return a code - translation is done on the other side
385 $output = 'ud_get_fragment_could_not_return';
386 $error = true;
387 break;
388 }
389
390 if (!$error) {
391 return array(
392 'output' => $output,
393 );
394 } else {
395 return new WP_Error('get_fragment_error', '', $output);
396 }
397
398 }
399
400 //This gets the http_get function from admin to grab information on a url
401 public function http_get($uri) {
402 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
403
404 if (empty($uri)) {
405 return new WP_Error('error', '', 'no_uri');
406 }
407
408 $response = $updraftplus_admin->http_get($uri, false);
409 $response_decode = json_decode($response);
410
411 if (isset($response_decode->e)) {
412 return new WP_Error('error', '', htmlspecialchars($response_decode->e));
413 }
414
415 return array(
416 'status' => $response_decode->code,
417 'response' => $response_decode->html_response
418 );
419 }
420
421 //This gets the http_get function from admin to grab cURL information on a url
422 public function http_get_curl($uri) {
423 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
424
425 if (empty($uri)) {
426 return new WP_Error('error', '', 'no_uri');
427 }
428
429 if (!function_exists('curl_exec')) {
430 return new WP_Error('error', '', 'no_curl');
431 }
432
433 $response_encode = $updraftplus_admin->http_get($uri, true);
434 $response_decode = json_decode($response_encode);
435
436 $response = 'Curl Info: ' . $response_decode->verb
437 .'Response: ' . $response_decode->response;
438
439 if($response_decode->response === false) {
440 return new WP_Error('error', '', array(
441 'error' => htmlspecialchars($response_decode->e),
442 "status" => $response_decode->status,
443 "log" => htmlspecialchars($response_decode->verb)
444 ));
445 }
446
447 return array(
448 'response'=> htmlspecialchars(substr($response, 0, 2048)),
449 'status'=> $response_decode->status,
450 'log'=> htmlspecialchars($response_decode->verb)
451 );
452 }
453
454 // Display raw backup and file list
455 public function show_raw_backup_and_file_list() {
456 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
457
458 /*
459 need to remove the pre tags as the modal assumes a <pre> is for a new box.
460 This cause issues specifically with fetch log events. Do this by passing true
461 to the method show_raw_backups
462 */
463
464 $response = $updraftplus_admin->show_raw_backups(true);
465
466 return $response['html'];
467 }
468
469 public function reset_site_id() {
470 if (false === ($updraftplus = $this->_load_ud())) return new WP_Error('no_updraftplus');
471 delete_site_option('updraftplus-addons_siteid');
472 return $updraftplus->siteid();
473 }
474
475 public function search_replace($query) {
476
477 if (!class_exists('UpdraftPlus_Addons_Migrator')) {
478 return new WP_Error('error', '', 'no_class_found');
479 }
480
481 global $updraftplus_addons_migrator;
482
483 if (!is_a( $updraftplus_addons_migrator, 'UpdraftPlus_Addons_Migrator')) {
484 return new WP_Error('error', 'no_object_found');
485 }
486
487 $_POST = $query;
488
489 ob_start();
490
491 do_action('updraftplus_adminaction_searchreplace', $query);
492
493 $response = array('log' => ob_get_clean());
494
495 return $response;
496 }
497
498 public function change_lock_settings($data) {
499 global $updraftplus_addon_lockadmin;
500
501 if (!class_exists('UpdraftPlus_Addon_LockAdmin')) {
502 return new WP_Error('error', '', 'no_class_found');
503 }
504
505 if(!is_a( $updraftplus_addon_lockadmin, "UpdraftPlus_Addon_LockAdmin")) {
506 return new WP_Error('error', '', 'no_object_found');
507 }
508
509 $session_length = empty($data["session_length"]) ? '' : $data["session_length"];
510 $password = empty($data["password"]) ? '' : $data["password"];
511 $old_password = empty($data["old_password"]) ? '' : $data["old_password"];
512 $support_url = $data["support_url"];
513
514 $user = wp_get_current_user();
515 if (0 == $user->ID) {
516 return new WP_Error('no_user_found');
517 }
518
519 $options = $updraftplus_addon_lockadmin->return_opts();
520
521 if($old_password == $options['password']) {
522
523 $options['password'] = (string)$password;
524 $options['support_url'] = (string)$support_url;
525 $options['session_length'] = (int)$session_length;
526 UpdraftPlus_Options::update_updraft_option('updraft_adminlocking', $options);
527
528 return "lock_changed";
529 } else {
530 return new WP_Error('error', '', 'wrong_old_password');
531 }
532 }
533
534 public function delete_key($key_id) {
535 global $updraftplus_updraftcentral_main;
536
537 if (!is_a($updraftplus_updraftcentral_main, 'UpdraftPlus_UpdraftCentral_Main')) {
538 return new WP_Error('error', '', 'UpdraftPlus_UpdraftCentral_Main object not found');
539 }
540
541 $response = $updraftplus_updraftcentral_main->delete_key($key_id);
542 return $response;
543
544 }
545
546 public function create_key($data) {
547 global $updraftplus_updraftcentral_main;
548
549 if (!is_a($updraftplus_updraftcentral_main, 'UpdraftPlus_UpdraftCentral_Main')) {
550 return new WP_Error('error', '', 'UpdraftPlus_UpdraftCentral_Main object not found');
551 }
552
553 $response = call_user_func(array($updraftplus_updraftcentral_main, 'create_key'), $data);
554
555 return $response;
556 }
557
558 public function fetch_log($data) {
559 global $updraftplus_updraftcentral_main;
560
561 if (!is_a($updraftplus_updraftcentral_main, 'UpdraftPlus_UpdraftCentral_Main')) {
562 return new WP_Error('error', '', 'UpdraftPlus_UpdraftCentral_Main object not found');
563 }
564
565 $response = call_user_func(array($updraftplus_updraftcentral_main, 'get_log'), $data);
566 return $response;
567 }
568
569 /**
570 * A handler method to call the UpdraftPlus admin wipe settings method
571 * @return Array An Array response to be sent back
572 */
573 public function wipe_settings() {
574 if (false === ($updraftplus_admin = $this->_load_ud_admin())) return new WP_Error('no_updraftplus');
575
576 if (!UpdraftPlus_Options::user_can_manage()) return new WP_Error('updraftplus_permission_denied');
577
578 // pass false to this method so that it does not remove the UpdraftCentral key
579 $response = $updraftplus_admin->updraft_wipe_settings(false);
580
581 return $response;
582 }
583 }
584