PluginProbe
The WP Remote WordPress Plugin / 5.45
The WP Remote WordPress Plugin v5.45
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.45, at callback/wings/manage.php

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