PluginProbe
The WP Remote WordPress Plugin / 5.65
The WP Remote WordPress Plugin v5.65
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / callback / wings / manage.php

manage.php in The WP Remote WordPress Plugin 5.65, at callback/wings/manage.php

906 lines 27.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4 if (!class_exists('BVManageCallback')) :
5 class BVManageCallback extends BVCallbackBase {
6 public $settings;
7 public $skin;
8 public $bvinfo;
9
10 const MANAGE_WING_VERSION = 1.6;
11
12 public function __construct($callback_handler) {
13 $this->settings = $callback_handler->settings;
14 $this->bvinfo = new WPRInfo($this->settings);
15 }
16
17 function getError($err) {
18 return $this->objectToArray($err);
19 }
20
21 function is_pantheon() {
22 return (!empty($_ENV['PANTHEON_ENVIRONMENT']) && $_ENV['PANTHEON_ENVIRONMENT'] !== 'dev');
23 }
24
25 function isServerWritable() {
26 if ($this->is_pantheon()) {
27 return false;
28 }
29
30 if ((!defined('FTP_HOST') || !defined('FTP_USER')) && (get_filesystem_method(array(), false) != 'direct')) {
31 return false;
32 } else {
33 return true;
34 }
35 }
36
37 function include_files() {
38 @include_once ABSPATH.'wp-admin/includes/file.php';
39 @include_once ABSPATH.'wp-admin/includes/plugin.php';
40 @include_once ABSPATH.'wp-admin/includes/theme.php';
41 @include_once ABSPATH.'wp-admin/includes/misc.php';
42 @include_once ABSPATH.'wp-admin/includes/template.php';
43 @include_once ABSPATH.'wp-includes/pluggable.php';
44 @include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
45 @include_once ABSPATH.'wp-admin/includes/class-theme-upgrader.php';
46 @include_once ABSPATH.'wp-admin/includes/class-plugin-upgrader.php';
47 @include_once ABSPATH.'wp-admin/includes/user.php';
48 @include_once ABSPATH.'wp-admin/includes/upgrade.php';
49 @include_once ABSPATH.'wp-admin/includes/update.php';
50 @require_once ABSPATH.'wp-admin/includes/update-core.php';
51 }
52
53 function edit($args) {
54 $result = array();
55 if ($args['type'] == 'plugins') {
56 $result['plugins'] = $this->editPlugins($args);
57 } elseif ($args['type'] == 'themes') {
58 $result['themes'] = $this->editThemes($args);
59 } elseif ($args['type'] == 'users') {
60 $result['users'] = $this->editWpusers($args);
61 }
62 return $result;
63 }
64
65 function editPlugins($args) {
66 $result = array();
67 $plugins = $args['items'];
68 foreach ($plugins as $plugin) {
69 if (array_key_exists('network', $plugin)) {
70 $networkwide = $plugin['network'];
71 } else {
72 $networkwide = false;
73 }
74 switch ($args['action']) {
75 case 'activate':
76 $res = activate_plugin($plugin['file'], '', $networkwide);
77 break;
78 case 'deactivate':
79 $res = deactivate_plugins(array($plugin['file']), false, $networkwide);
80 break;
81 case 'delete':
82 $res = delete_plugins(array($plugin['file']));
83 break;
84 case 'deactivate_delete':
85 $res = deactivate_plugins(array($plugin['file']), false, $networkwide);
86 if ($res || is_wp_error($res))
87 break;
88 $res = delete_plugins(array($plugin['file']));
89 default:
90 break;
91 }
92 if (is_wp_error($res)) {
93 $res = array('status' => "Error", 'message' => $res->get_error_message());
94 } elseif ($res === false) {
95 $res = array('status' => "Error", 'message' => "Failed to perform action.");
96 } else {
97 $res = array('status' => "Done");
98 }
99 $result[$plugin['file']] = $res;
100 }
101 return $result;
102 }
103
104 function editThemes($args) {
105 $result = array();
106 $themes = $args['items'];
107 foreach ($themes as $theme) {
108 switch ($args['action']) {
109 case 'activate':
110 $res = switch_theme($theme['template'], $theme['stylesheet']);
111 break;
112 case 'delete':
113 $res = delete_theme($theme['stylesheet']);
114 break;
115 default:
116 break;
117 }
118
119 if (is_wp_error($res)) {
120 $res = array('status' => "Error", 'message' => $res->get_error_message());
121 } elseif ($res === false) {
122 $res = array('status' => "Error", 'message' => "Failed to perform action.");
123 } else {
124 $res = array( 'status' => "Done");
125 }
126 $result[$theme['template']] = $res;
127 }
128 return $result;
129 }
130
131 function editWpusers($args) {
132 $result = array();
133 $items = $args['items'];
134 foreach ($items as $item) {
135 $res = array();
136 $user = get_user_by('id', $item['id']);
137 if ($user) {
138 switch ($args['action']) {
139 case 'changerole':
140 $data = array();
141 $data['role'] = $item['newrole'];
142 $data['ID'] = $user->ID;
143 $res = wp_update_user($data);
144 break;
145 case 'changepass':
146 $data = array();
147 $data['user_pass'] = $item['newpass'];
148 $data['ID'] = $user->ID;
149 $res = wp_update_user($data);
150 break;
151 case 'delete':
152 if (array_key_exists('reassign', $args)) {
153 $user_to = get_user_by('id', $args['reassign']);
154 if ($user_to != false) {
155 $res = wp_delete_user($user->ID, $user_to->ID);
156 } else {
157 $res = array('status' => "Error", 'message' => 'Reassigned user doesnot exists');
158 }
159 } else {
160 $res = wp_delete_user($user->ID);
161 }
162 break;
163 }
164 if (is_wp_error($res)) {
165 $res = array('status' => "Error", 'message' => $res->get_error_message());
166 } else {
167 $res = array( 'status' => "Done");
168 }
169 } else {
170 $res = array('status' => "Error", 'message' => "Unable to find user");
171 }
172 $result[$item['id']] = $res;
173 }
174 return $result;
175 }
176
177 function addUser($args) {
178 if (username_exists($args['user_login'])) {
179 return array('status' => "Error", 'message' => "Username already exists");
180 }
181 if (email_exists($args['user_email'])) {
182 return array('status' => "Error", 'message' => "Email already exists");
183 }
184 $result = wp_insert_user($args);
185 if ( !is_wp_error( $result ) ) {
186 return array('status' => "Done", 'user_id' => $result);
187 } else {
188 return array('status' => "Error", 'message' => $this->getError($result));
189 }
190 }
191
192 function upgrade($params = null, $has_bv_skin = false, $bv_bulk_upgrade = false) {
193 $result = array();
194 $premium_upgrades = array();
195 if (array_key_exists('clear_filters', $params)) {
196 $filters = $params['clear_filters'];
197 foreach ($filters as $filter)
198 remove_all_filters($filter);
199 }
200 if (array_key_exists('core', $params) && !empty($params['core'])) {
201 $result['core'] = $this->upgradeCore($params['core']);
202 }
203 if (array_key_exists('translations', $params) && !empty($params['translations'])) {
204 $result['translations'] = $this->upgradeTranslations($params['translations'], $has_bv_skin);
205 }
206 if (array_key_exists('plugins', $params) && !empty($params['plugins'])) {
207 $result['plugins'] = $this->upgradePlugins($params['plugins'], $has_bv_skin, $bv_bulk_upgrade);
208 }
209 if (array_key_exists('themes', $params) && !empty($params['themes'])) {
210 $result['themes'] = $this->upgradeThemes($params['themes'], $has_bv_skin, $bv_bulk_upgrade);
211 }
212 return $result;
213 }
214
215 function get_translation_updates() {
216 $updates = array();
217 $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' );
218 foreach ( $transients as $transient => $type ) {
219 $transient = $this->settings->getTransient( $transient );
220 if ( empty( $transient->translations ) )
221 continue;
222
223 foreach ( $transient->translations as $translation ) {
224 $updates[] = (object) $translation;
225 }
226 }
227 return $updates;
228 }
229
230 function upgradeTranslations($translations, $has_bv_skin = false) {
231 $language_updates = $this->get_translation_updates();
232 $valid_updates = array();
233 $result = array();
234 if (!empty($language_updates)) {
235 foreach($language_updates as $update) {
236 if ($update && in_array($update->package, $translations)) {
237 $valid_updates[] = $update;
238 }
239 }
240 }
241 if (!empty($valid_updates)) {
242 if (class_exists('Language_Pack_Upgrader')) {
243 if ($has_bv_skin) {
244 require_once( "bv_upgrader_skin.php" );
245 $skin = new BVUpgraderSkin("upgrade_translations");
246 $this->skin = $skin;
247 } else {
248 $skin = new Language_Pack_Upgrader_Skin(array());
249 }
250 $upgrader = new Language_Pack_Upgrader($skin);
251 $result = $upgrader->bulk_upgrade($valid_updates);
252 if (is_array($result) && !empty($result)) {
253 foreach ($result as $translate_tmp => $translate_info) {
254 if (is_wp_error($translate_info) || empty($translate_info)) {
255 $error = (!empty($translate_info)) ? is_wp_error($translate_info) : "Upgrade failed";
256 return array('status' => "Error", 'message' => $error);
257 }
258 }
259 }
260 return array('status' => "Done");
261 }
262 }
263 return array('status' => "Error", 'message' => "Upgrade failed");
264 }
265
266 function upgradeCore($args) {
267 global $wp_filesystem, $wp_version;
268 $core = $this->settings->getTransient('update_core');
269 $core_update_index = intval($args['coreupdateindex']);
270 if (isset($core->updates) && !empty($core->updates)) {
271 $to_update = $core->updates[$core_update_index];
272 } else {
273 return array('status' => "Error", "message" => "Updates not available");
274 }
275 $resp = array("Core_Upgrader", class_exists('Core_Upgrader'));
276 if (version_compare($wp_version, '3.1.9', '>')) {
277 $core = new Core_Upgrader();
278 $result = $core->upgrade($to_update);
279 if (is_wp_error($result)) {
280 return array('status' => "Error", "message" => $this->getError($result));
281 } else {
282 return array('status' => 'Done');
283 }
284 } else {
285 $resp = array("wp_update_core", function_exists('wp_update_core'));
286 if (function_exists('wp_update_core')) {
287 $result = wp_update_core($to_update);
288 if (is_wp_error($result)) {
289 return array('status' => "Error", "message" => $this->getError($result));
290 } else {
291 return array('status' => 'Done');
292 }
293 }
294
295 $resp = array("WP_Upgrader", class_exists('WP_Upgrader'));
296 if (class_exists('WP_Upgrader')) {
297 $upgrader = new WP_Upgrader();
298
299 $res = $upgrader->fs_connect(
300 array(
301 ABSPATH,
302 WP_CONTENT_DIR,
303 )
304 );
305 if (is_wp_error($res)) {
306 return array('status' => "Error", "message" => $this->getError($res));
307 }
308
309 $wp_dir = trailingslashit($wp_filesystem->abspath());
310
311 $core_package = false;
312 if (isset($to_update->package) && !empty($to_update->package)) {
313 $core_package = $to_update->package;
314 } elseif (isset($to_update->packages->full) && !empty($to_update->packages->full)) {
315 $core_package = $to_update->packages->full;
316 }
317
318 $download = $upgrader->download_package($core_package);
319 if (is_wp_error($download)) {
320 return array('status' => "Error", "message" => $this->getError($download));
321 }
322 $working_dir = $upgrader->unpack_package($download);
323 if (is_wp_error($working_dir)) {
324 return array('status' => "Error", "message" => $this->getError($working_dir));
325 }
326
327 if (!$wp_filesystem->copy($working_dir.'/wordpress/wp-admin/includes/update-core.php', $wp_dir.'wp-admin/includes/update-core.php', true)) {
328 $wp_filesystem->delete($working_dir, true);
329 return array('status' => "Error", "message" => "Unable to move files.");
330 }
331
332 $wp_filesystem->chmod($wp_dir.'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
333
334 $result = update_core($working_dir, $wp_dir);
335
336 if (is_wp_error($result)) {
337 return array('status' => "Error", "message" => $this->getError($result));
338 }
339 return array('status' => 'Done');
340 }
341 }
342 }
343
344 function bv_plugin_bulk_upgrade($upgrader, $_plugins) {
345 $plugins = array_keys($_plugins);
346 $args = array();
347 $defaults = array(
348 'clear_update_cache' => true,
349 );
350 $parsed_args = wp_parse_args($args, $defaults);
351 $upgrader->init();
352 $upgrader->bulk = true;
353 $upgrader->upgrade_strings();
354 add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4);
355 $upgrader->skin->header();
356 $res = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
357 if (!$res) {
358 $upgrader->skin->footer();
359 return false;
360 }
361 $upgrader->skin->bulk_header();
362 $maintenance = (is_multisite() && ! empty($plugins));
363 foreach ($plugins as $plugin) {
364 $maintenance = $maintenance || (is_plugin_active($plugin));
365 }
366 if ($maintenance) {
367 $upgrader->maintenance_mode(true);
368 }
369 $results = array();
370 $upgrader->update_count = count($plugins);
371 $upgrader->update_current = 0;
372 foreach($plugins as $plugin) {
373 $upgrader->update_current++;
374 $upgrader->skin->plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin, false, true);
375 $upgrader->skin->plugin_active = is_plugin_active($plugin);
376 $result = $upgrader->run(
377 array(
378 'package' => $_plugins[$plugin],
379 'destination' => WP_PLUGIN_DIR,
380 'clear_destination' => true,
381 'clear_working' => true,
382 'is_multi' => true,
383 'hook_extra' => array(
384 'plugin' => $plugin,
385 ),
386 )
387 );
388 $results[$plugin] = $result;
389 if (false === $result) {
390 break;
391 }
392 }
393 $upgrader->maintenance_mode(false);
394 wp_clean_plugins_cache($parsed_args['clear_update_cache']);
395 do_action(
396 'upgrader_process_complete',
397 $upgrader,
398 array(
399 'action' => 'update',
400 'type' => 'plugin',
401 'bulk' => true,
402 'plugins' => $plugins,
403 )
404 );
405 $upgrader->skin->bulk_footer();
406 $upgrader->skin->footer();
407 remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'));
408 $past_failure_emails = get_option('auto_plugin_theme_update_emails', array());
409 foreach ($results as $plugin => $result) {
410 if (!$result || is_wp_error($result) || !isset($past_failure_emails[$plugin])) {
411 continue;
412 }
413 unset($past_failure_emails[$plugin]);
414 }
415 update_option('auto_plugin_theme_update_emails', $past_failure_emails);
416 return $results;
417 }
418
419 function upgradePlugins($plugins, $has_bv_skin = false, $bv_bulk_upgrade = false) {
420 $result = array();
421 $_plugins = array();
422 $plugins_by_name = array();
423 foreach ($plugins as $plugin) {
424 $_plugins[$plugin['file']] = $plugin['package'];
425 $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin['file'], false, true);
426 $plugins_by_name[$plugin_data['Name']] = $plugin['file'];
427 }
428 if (empty(array_keys($_plugins))) {
429 return $result;
430 }
431 if (class_exists('Plugin_Upgrader')) {
432 if ($has_bv_skin) {
433 require_once( "bv_upgrader_skin.php" );
434 $skin = new BVUpgraderSkin("plugin_upgrade", $plugins_by_name);
435 $this->skin = $skin;
436 } else {
437 $skin = new Bulk_Plugin_Upgrader_Skin();
438 }
439 $upgrader = new Plugin_Upgrader($skin);
440
441 if ($bv_bulk_upgrade) {
442 $result = $this->bv_plugin_bulk_upgrade($upgrader, $_plugins);
443 } else {
444 $result = $upgrader->bulk_upgrade(array_keys($_plugins));
445 }
446 foreach (array_keys($_plugins) as $file) {
447 if (!array_key_exists($file, $result)) {
448 $result[$file] = array('status' => "Error");
449 } else {
450 $res = $result[$file];
451 if (!$res || is_wp_error($res)) {
452 $result[$file] = array('status' => "Error");
453 } else {
454 $result[$file] = array('status' => "Done");
455 }
456 }
457 }
458 }
459 return $result;
460 }
461
462 function bv_theme_bulk_upgrade($upgrader, $_themes) {
463 $themes = array_keys($_themes);
464 $args = array();
465 $defaults = array(
466 'clear_update_cache' => true,
467 );
468 $parsed_args = wp_parse_args($args, $defaults);
469 $upgrader->init();
470 $upgrader->bulk = true;
471 $upgrader->upgrade_strings();
472 add_filter('upgrader_pre_install', array($upgrader, 'current_before'), 10, 2);
473 add_filter('upgrader_post_install', array( $upgrader, 'current_after'), 10, 2);
474 add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_theme'), 10, 4);
475 $upgrader->skin->header();
476 $res = $upgrader->fs_connect(array(WP_CONTENT_DIR));
477 if (!$res) {
478 $upgrader->skin->footer();
479 return false;
480 }
481 $upgrader->skin->bulk_header();
482 $maintenance = (is_multisite() && !empty($themes));
483 foreach ($themes as $theme) {
484 $maintenance = $maintenance || get_stylesheet() === $theme || get_template() === $theme;
485 }
486 if ($maintenance) {
487 $upgrader->maintenance_mode(true);
488 }
489 $results = array();
490 $upgrader->update_count = count($themes);
491 $upgrader->update_current = 0;
492 foreach ($themes as $theme) {
493 $upgrader->update_current++;
494 $upgrader->skin->theme_info = $upgrader->theme_info($theme);
495 $result = $upgrader->run(
496 array(
497 'package' => $_themes[$theme],
498 'destination' => get_theme_root($theme),
499 'clear_destination' => true,
500 'clear_working' => true,
501 'is_multi' => true,
502 'hook_extra' => array(
503 'theme' => $theme,
504 ),
505 )
506 );
507
508 $results[$theme] = $result;
509 if (false === $result) {
510 break;
511 }
512 }
513 $upgrader->maintenance_mode(false);
514 wp_clean_themes_cache($parsed_args['clear_update_cache']);
515 do_action(
516 'upgrader_process_complete',
517 $upgrader,
518 array(
519 'action' => 'update',
520 'type' => 'theme',
521 'bulk' => true,
522 'themes' => $themes,
523 )
524 );
525 $upgrader->skin->bulk_footer();
526 $upgrader->skin->footer();
527 remove_filter('upgrader_pre_install', array($upgrader, 'current_before'));
528 remove_filter('upgrader_post_install', array($upgrader, 'current_after'));
529 remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_theme'));
530 $past_failure_emails = get_option('auto_plugin_theme_update_emails', array());
531 foreach ($results as $theme => $result) {
532 if (!$result || is_wp_error($result) || !isset($past_failure_emails[$theme])) {
533 continue;
534 }
535 unset($past_failure_emails[$theme]);
536 }
537 update_option('auto_plugin_theme_update_emails', $past_failure_emails);
538 return $results;
539 }
540
541 function upgradeThemes($themes, $has_bv_skin = false, $bv_bulk_upgrade = false) {
542 $result = array();
543 $_themes = array();
544 foreach ($themes as $theme) {
545 $_themes[$theme['stylesheet']] = $theme['package'];
546 }
547 if (empty(array_keys($_themes))) {
548 return $result;
549 }
550 if (class_exists('Theme_Upgrader')) {
551 if ($has_bv_skin) {
552 require_once( "bv_upgrader_skin.php" );
553 $skin = new BVUpgraderSkin("theme_upgrade");
554 $this->skin = $skin;
555 } else {
556 $skin = new Bulk_Theme_Upgrader_Skin();
557 }
558 $upgrader = new Theme_Upgrader($skin);
559 if ($bv_bulk_upgrade) {
560 $result = $this->bv_theme_bulk_upgrade($upgrader, $_themes);
561 } else {
562 $result = $upgrader->bulk_upgrade(array_keys($_themes));
563 }
564 foreach (array_keys($_themes) as $stylesheet) {
565 if (!array_key_exists($stylesheet, $result)) {
566 $result[$stylesheet] = array('status' => "Error");
567 } else {
568 $res = $result[$stylesheet];
569 if (!$res || is_wp_error($res)) {
570 $result[$stylesheet] = array('status' => "Error");
571 } else {
572 $result[$stylesheet] = array('status' => "Done");
573 }
574 }
575 }
576 }
577 return $result;
578 }
579
580 function install($params, $has_bv_skin = false) {
581 $result = array();
582 if (isset($params['plugins'])) {
583 foreach ($params['plugins'] as $plugin) {
584 if (!array_key_exists('plugins', $result))
585 $result["plugins"] = array();
586 $plugin['dest'] = WP_PLUGIN_DIR;
587 $res = $this->installPackage("plugin", $plugin, $has_bv_skin);
588 $pluginName = $plugin['package'];
589 $result["plugins"][$pluginName] = $res;
590 }
591 }
592 if (isset($params['themes'])) {
593 foreach ($params['themes'] as $theme) {
594 if (!array_key_exists('themes', $result))
595 $result["themes"] = array();
596 $theme['dest'] = WP_CONTENT_DIR.'/themes';
597 $res = $this->installPackage("theme", $theme, $has_bv_skin);
598 $themeName = $theme['package'];
599 $result["themes"][$themeName] = $res;
600 }
601 }
602 return $result;
603 }
604
605 function installPackage($type, $params, $has_bv_skin = false) {
606 global $wp_filesystem;
607
608 if (!isset($params['package']) || empty($params['package'])) {
609 return array('status' => "Error", 'message' => "No package is sent");
610 }
611 $valid_domain_regex = "/^(http|https):\/\/[\-\w]*\.(blogvault\.net|w\.org|wp\.org|wordpress\.org)\//";
612 if (WPRHelper::safePregMatch($valid_domain_regex, $params['package']) !== 1) {
613 return array('status' => "Error", 'message' => "Invalid package domain");
614 }
615 if ($has_bv_skin) {
616 require_once( "bv_upgrader_skin.php" );
617 $skin = new BVUpgraderSkin("installer", array(), $params['package']);
618 $this->skin = $skin;
619 } else {
620 $skin = new WP_Upgrader_Skin();
621 }
622 if ("plugin" === $type) {
623 $upgrader = new Plugin_Upgrader($skin);
624 } elseif ("theme" === $type) {
625 $upgrader = new Theme_Upgrader($skin);
626 } else {
627 $upgrader = new WP_Upgrader($skin);
628 }
629 $upgrader->init();
630 $destination = $params['dest'];
631 $clear_destination = isset($params['cleardest']) ? $params['cleardest'] : false;
632 $package_url = $params['package'];
633 $key = basename($package_url);
634 add_filter('upgrader_source_selection', array($upgrader, 'check_package'));
635 $res = $upgrader->run(
636 array(
637 'package' => $package_url,
638 'destination' => $destination,
639 'clear_destination' => $clear_destination,
640 'clear_working' => true,
641 'hook_extra' => array(
642 "type" => $type,
643 "action" => "install"
644 ),
645 )
646 );
647 remove_filter('upgrader_source_selection', array($upgrader, 'check_package'));
648 if (is_wp_error($res)) {
649 $res = array('status' => "Error", 'message' => $this->getError($res));
650 } else {
651 $res = array( 'status' => "Done");
652 }
653 return $res;
654 }
655
656 function getPremiumUpdates() {
657 return apply_filters( 'mwp_premium_update_notification', array() );
658 }
659
660 function getPremiumUpgradesInfo() {
661 return apply_filters( 'mwp_premium_perform_update', array() );
662 }
663
664 function autoLogin($username, $isHttps) {
665 $user = get_user_by('login', $username);
666 if ($user != FALSE) {
667 wp_set_current_user( $user->ID );
668 if ($isHttps) {
669 wp_set_auth_cookie( $user->ID, false, true );
670 } else {
671 # As we are not sure about wp-cofig.php settings for sure login
672 wp_set_auth_cookie( $user->ID, false, true );
673 wp_set_auth_cookie( $user->ID, false, false );
674 }
675 $redirect_to = get_admin_url();
676 wp_safe_redirect( $redirect_to );
677 exit;
678 }
679 }
680
681 public function refreshPluginUpdates() {
682 global $wp_current_filter;
683 $wp_current_filter[] = 'load-update-core.php';
684
685 wp_update_plugins();
686
687 array_pop($wp_current_filter);
688
689 wp_update_plugins();
690
691 return true;
692 }
693
694 public function refreshThemeUpdates() {
695 global $wp_current_filter;
696 $wp_current_filter[] = 'load-update-core.php';
697
698 wp_update_themes();
699
700 array_pop($wp_current_filter);
701
702 wp_update_themes();
703
704 return true;
705 }
706
707 function upgradeElementorDB($file) {
708 try {
709 $managerClass = $file === "elementor/elementor.php" ? '\Elementor\Core\Upgrade\Manager' : '\ElementorPro\Core\Upgrade\Manager';
710
711 if (!class_exists($managerClass)) {
712 return array('status' => 'Error', 'error' => 'Elementor plugin not found or disabled', 'source' => 'BV');
713 }
714
715 $manager = new $managerClass();
716 $required_methods = array('get_task_runner', 'should_upgrade', 'on_runner_complete',
717 'get_current_version', 'get_new_version');
718 foreach ($required_methods as $method) {
719 if (!method_exists($manager, $method)) {
720 return array('status' => 'Error', 'error' => 'Required methods are missing', 'source' => 'BV');
721 }
722 }
723
724 $updateInfo = array(
725 'from' => $manager->get_current_version(),
726 'to' => $manager->get_new_version(),
727 );
728
729 if ($manager->should_upgrade()) {
730 $callbacks = $manager->get_upgrade_callbacks();
731
732 if (!empty($callbacks)) {
733 $manager->get_task_runner()->handle_immediately($callbacks);
734 $manager->on_runner_complete(true);
735 }
736 } else {
737 return array('status' => 'Error', 'error' => 'Database Update is not available currently',
738 'update_info' => $updateInfo, 'source' => 'BV');
739 }
740
741 return array('status' => 'Done', 'update_info' => $updateInfo);
742 } catch (Exception $e) {
743 return array('status' => 'Error', 'error' => $e->getMessage());
744 }
745 }
746
747 function upgradeWoocommerceDb() {
748 try {
749 if (!defined('WC_ABSPATH')) {
750 return array('status' => 'Error', 'error' => 'WC not found', 'source' => 'BV');
751 }
752
753 if (file_exists(WC_ABSPATH . 'includes/class-wc-install.php')) {
754 include_once WC_ABSPATH . 'includes/class-wc-install.php';
755 }
756
757 if (file_exists(WC_ABSPATH . 'includes/wc-update-functions.php')) {
758 include_once WC_ABSPATH . 'includes/wc-update-functions.php';
759 }
760
761 if (!class_exists('WC_Install') || !method_exists('WC_Install', 'needs_db_update') ||
762 !method_exists('WC_Install', 'get_db_update_callbacks')) {
763 return array('status' => 'Error', 'error' => 'WC files missing or corrupted', 'source' => 'BV');
764 }
765
766 $current_db_version = $this->settings->getOption('woocommerce_db_version');
767 if (!$current_db_version) {
768 return array('status' => 'Error', 'error' => 'Current WC DB version not available', 'source' => 'BV');
769 }
770
771 $latest_db_version = $this->bvinfo->getLatestWooCommerceDBVersion();
772 if ($current_db_version >= $latest_db_version) {
773 return array('status' => 'Error', 'error' => 'WC DB update not available', 'source' => 'BV');
774 }
775
776 $db_update_callbacks = WC_Install::get_db_update_callbacks();
777
778 $loop = 0;
779 foreach ($db_update_callbacks as $version => $update_callbacks) {
780 if (version_compare($current_db_version, $version, '<')) {
781 foreach ($update_callbacks as $update_callback) {
782 WC()->queue()->schedule_single(
783 time() + $loop,
784 'woocommerce_run_update_callback',
785 array('update_callback' => $update_callback),
786 'woocommerce-db-updates'
787 );
788 $loop++;
789 }
790 }
791 }
792
793 $current_wc_version = WC()->version;
794 if (version_compare($current_db_version, $current_wc_version, '<') &&
795 !WC()->queue()->get_next('woocommerce_update_db_to_current_version')) {
796 WC()->queue()->schedule_single(
797 time() + $loop,
798 'woocommerce_update_db_to_current_version',
799 array('version' => $current_wc_version),
800 'woocommerce-db-updates'
801 );
802 }
803
804 return array('status' => 'Done');
805 } catch (Exception $e) {
806 return array('status' => 'Error', 'error' => $e->getMessage());
807 }
808 }
809
810 function upgrade_db(){
811 if (function_exists('wp_upgrade')) {
812 wp_upgrade();
813 return "Done";
814 } else {
815 return "NOUPGRADERFUNCTION";
816 }
817 }
818
819 function process($request) {
820 global $wp_filesystem;
821 $this->include_files();
822
823 if (!$this->is_pantheon() && !$wp_filesystem) {
824 WP_Filesystem();
825 }
826
827 $params = $request->params;
828 $resp = array();
829 switch ($request->method) {
830 case "adusr":
831 $resp = array("adduser" => $this->addUser($params['args']));
832 break;
833 case "upgrde":
834 $has_bv_skin = array_key_exists('bvskin', $params);
835 $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $params['args']);
836 $resp = array("upgrades" => $this->upgrade($params['args'], $has_bv_skin, $bv_bulk_upgrade));
837 break;
838 case "cmbneupgrde":
839 $args = $params['args'];
840 $has_bv_skin = array_key_exists('bvskin', $args);
841 $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $args);
842
843 $resp['upgrades'] = $this->upgrade($args['upgrades'], $has_bv_skin, $bv_bulk_upgrade);
844
845 if (isset($args['delete_transient'])) {
846 $resp['delete_transient'] = $this->settings->deleteTransient($args['delete_transient']);
847 }
848 if (isset($args['wp_update_plugins'])) {
849 $resp['wp_update_plugins'] = $this->refreshPluginUpdates();
850 }
851 if (isset($args['wp_update_themes'])) {
852 $resp['wp_update_themes'] = $this->refreshThemeUpdates();
853 }
854 break;
855 case "edt":
856 $resp = array("edit" => $this->edit($params['args']));
857 break;
858 case "instl":
859 $has_bv_skin = array_key_exists('bvskin', $params);
860 $resp = array("install" => $this->install($params['args'], $has_bv_skin));
861 break;
862 case "getpremiumupdates":
863 $resp = array("premiumupdates" => $this->getPremiumUpdates());
864 break;
865 case "getpremiumupgradesinfo":
866 $resp = array("premiumupgradesinfo" => $this->getPremiumUpgradesInfo());
867 break;
868 case "wrteble":
869 $resp = array("writeable" => $this->isServerWritable());
870 break;
871 case "atolgn":
872 $isHttps = false;
873 if (array_key_exists('https', $params))
874 $isHttps = true;
875 $resp = array("autologin" => $this->autoLogin($params['username'], $isHttps));
876 break;
877 case "updatedb":
878 $resp = array("status" => $this->upgrade_db());
879 break;
880 case "updateplgndb":
881 $resp = array();
882 $files = $params['files'];
883
884 foreach ($files as $file) {
885 switch ($file) {
886 case "woocommerce/woocommerce.php":
887 $resp[$file] = $this->upgradeWoocommerceDb();
888 break;
889 case "elementor/elementor.php":
890 case "elementor-pro/elementor-pro.php":
891 $resp[$file] = $this->upgradeElementorDB($file);
892 break;
893 }
894 }
895
896 break;
897 default:
898 $resp = false;
899 }
900 if ($this->skin && is_array($resp)) {
901 $resp = array_merge($resp, $this->skin->status);
902 }
903 return $resp;
904 }
905 }
906 endif;