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

902 lines 27.5 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.7;
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_Upgrader", class_exists('WP_Upgrader'));
286 if (class_exists('WP_Upgrader')) {
287 $upgrader = new WP_Upgrader();
288
289 $res = $upgrader->fs_connect(
290 array(
291 ABSPATH,
292 WP_CONTENT_DIR,
293 )
294 );
295 if (is_wp_error($res)) {
296 return array('status' => "Error", "message" => $this->getError($res));
297 }
298
299 $wp_dir = trailingslashit($wp_filesystem->abspath());
300
301 $core_package = false;
302 if (isset($to_update->package) && !empty($to_update->package)) {
303 $core_package = $to_update->package;
304 } elseif (isset($to_update->packages->full) && !empty($to_update->packages->full)) {
305 $core_package = $to_update->packages->full;
306 }
307
308 $download = $upgrader->download_package($core_package);
309 if (is_wp_error($download)) {
310 return array('status' => "Error", "message" => $this->getError($download));
311 }
312 $working_dir = $upgrader->unpack_package($download);
313 if (is_wp_error($working_dir)) {
314 return array('status' => "Error", "message" => $this->getError($working_dir));
315 }
316
317 if (!$wp_filesystem->copy($working_dir.'/wordpress/wp-admin/includes/update-core.php', $wp_dir.'wp-admin/includes/update-core.php', true)) {
318 $wp_filesystem->delete($working_dir, true);
319 return array('status' => "Error", "message" => "Unable to move files.");
320 }
321
322 $wp_filesystem->chmod($wp_dir.'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
323
324 $result = update_core($working_dir, $wp_dir);
325
326 if (is_wp_error($result)) {
327 return array('status' => "Error", "message" => $this->getError($result));
328 }
329 return array('status' => 'Done');
330 }
331 }
332 }
333
334 function bv_plugin_bulk_upgrade($upgrader, $_plugins) {
335 $plugins = array_keys($_plugins);
336 $args = array();
337 $defaults = array(
338 'clear_update_cache' => true,
339 );
340 $parsed_args = wp_parse_args($args, $defaults);
341 $upgrader->init();
342 $upgrader->bulk = true;
343 $upgrader->upgrade_strings();
344 add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4);
345 $upgrader->skin->header();
346 $res = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
347 if (!$res) {
348 $upgrader->skin->footer();
349 return false;
350 }
351 $upgrader->skin->bulk_header();
352 $maintenance = (is_multisite() && ! empty($plugins));
353 foreach ($plugins as $plugin) {
354 $maintenance = $maintenance || (is_plugin_active($plugin));
355 }
356 if ($maintenance) {
357 $upgrader->maintenance_mode(true);
358 }
359 $results = array();
360 $upgrader->update_count = count($plugins);
361 $upgrader->update_current = 0;
362 foreach($plugins as $plugin) {
363 $upgrader->update_current++;
364 $upgrader->skin->plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin, false, true);
365 $upgrader->skin->plugin_active = is_plugin_active($plugin);
366 $result = $upgrader->run(
367 array(
368 'package' => $_plugins[$plugin],
369 'destination' => WP_PLUGIN_DIR,
370 'clear_destination' => true,
371 'clear_working' => true,
372 'is_multi' => true,
373 'hook_extra' => array(
374 'plugin' => $plugin,
375 ),
376 )
377 );
378 $results[$plugin] = $result;
379 if (false === $result) {
380 break;
381 }
382 }
383 $upgrader->maintenance_mode(false);
384 wp_clean_plugins_cache($parsed_args['clear_update_cache']);
385 do_action(
386 'upgrader_process_complete',
387 $upgrader,
388 array(
389 'action' => 'update',
390 'type' => 'plugin',
391 'bulk' => true,
392 'plugins' => $plugins,
393 )
394 );
395 $upgrader->skin->bulk_footer();
396 $upgrader->skin->footer();
397 remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'));
398 $past_failure_emails = get_option('auto_plugin_theme_update_emails', array());
399 foreach ($results as $plugin => $result) {
400 if (!$result || is_wp_error($result) || !isset($past_failure_emails[$plugin])) {
401 continue;
402 }
403 unset($past_failure_emails[$plugin]);
404 }
405 update_option('auto_plugin_theme_update_emails', $past_failure_emails);
406 return $results;
407 }
408
409 function upgradePlugins($plugins, $has_bv_skin = false, $bv_bulk_upgrade = false) {
410 $result = array();
411 $_plugins = array();
412 $plugins_by_name = array();
413 foreach ($plugins as $plugin) {
414 $_plugins[$plugin['file']] = $plugin['package'];
415 $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin['file'], false, true);
416 $plugins_by_name[$plugin_data['Name']] = $plugin['file'];
417 }
418 if (empty(array_keys($_plugins))) {
419 return $result;
420 }
421 if (class_exists('Plugin_Upgrader')) {
422 if ($has_bv_skin) {
423 require_once( "bv_upgrader_skin.php" );
424 $skin = new BVUpgraderSkin("plugin_upgrade", $plugins_by_name);
425 $this->skin = $skin;
426 } else {
427 $skin = new Bulk_Plugin_Upgrader_Skin();
428 }
429 $upgrader = new Plugin_Upgrader($skin);
430
431 if ($bv_bulk_upgrade) {
432 $result = $this->bv_plugin_bulk_upgrade($upgrader, $_plugins);
433 } else {
434 $result = $upgrader->bulk_upgrade(array_keys($_plugins));
435 }
436 if (!is_array($result)) {
437 return array('status' => "Error", 'message' =>'result is not an array');
438 }
439 foreach (array_keys($_plugins) as $file) {
440 if (!array_key_exists($file, $result)) {
441 $result[$file] = array('status' => "Error");
442 } else {
443 $res = $result[$file];
444 if (!$res || is_wp_error($res)) {
445 $result[$file] = array('status' => "Error");
446 } else {
447 $result[$file] = array('status' => "Done");
448 }
449 }
450 }
451 }
452 return $result;
453 }
454
455 function bv_theme_bulk_upgrade($upgrader, $_themes) {
456 $themes = array_keys($_themes);
457 $args = array();
458 $defaults = array(
459 'clear_update_cache' => true,
460 );
461 $parsed_args = wp_parse_args($args, $defaults);
462 $upgrader->init();
463 $upgrader->bulk = true;
464 $upgrader->upgrade_strings();
465 add_filter('upgrader_pre_install', array($upgrader, 'current_before'), 10, 2);
466 add_filter('upgrader_post_install', array( $upgrader, 'current_after'), 10, 2);
467 add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_theme'), 10, 4);
468 $upgrader->skin->header();
469 $res = $upgrader->fs_connect(array(WP_CONTENT_DIR));
470 if (!$res) {
471 $upgrader->skin->footer();
472 return false;
473 }
474 $upgrader->skin->bulk_header();
475 $maintenance = (is_multisite() && !empty($themes));
476 foreach ($themes as $theme) {
477 $maintenance = $maintenance || get_stylesheet() === $theme || get_template() === $theme;
478 }
479 if ($maintenance) {
480 $upgrader->maintenance_mode(true);
481 }
482 $results = array();
483 $upgrader->update_count = count($themes);
484 $upgrader->update_current = 0;
485 foreach ($themes as $theme) {
486 $upgrader->update_current++;
487 $upgrader->skin->theme_info = $upgrader->theme_info($theme);
488 $result = $upgrader->run(
489 array(
490 'package' => $_themes[$theme],
491 'destination' => get_theme_root($theme),
492 'clear_destination' => true,
493 'clear_working' => true,
494 'is_multi' => true,
495 'hook_extra' => array(
496 'theme' => $theme,
497 ),
498 )
499 );
500
501 $results[$theme] = $result;
502 if (false === $result) {
503 break;
504 }
505 }
506 $upgrader->maintenance_mode(false);
507 wp_clean_themes_cache($parsed_args['clear_update_cache']);
508 do_action(
509 'upgrader_process_complete',
510 $upgrader,
511 array(
512 'action' => 'update',
513 'type' => 'theme',
514 'bulk' => true,
515 'themes' => $themes,
516 )
517 );
518 $upgrader->skin->bulk_footer();
519 $upgrader->skin->footer();
520 remove_filter('upgrader_pre_install', array($upgrader, 'current_before'));
521 remove_filter('upgrader_post_install', array($upgrader, 'current_after'));
522 remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_theme'));
523 $past_failure_emails = get_option('auto_plugin_theme_update_emails', array());
524 foreach ($results as $theme => $result) {
525 if (!$result || is_wp_error($result) || !isset($past_failure_emails[$theme])) {
526 continue;
527 }
528 unset($past_failure_emails[$theme]);
529 }
530 update_option('auto_plugin_theme_update_emails', $past_failure_emails);
531 return $results;
532 }
533
534 function upgradeThemes($themes, $has_bv_skin = false, $bv_bulk_upgrade = false) {
535 $result = array();
536 $_themes = array();
537 foreach ($themes as $theme) {
538 $_themes[$theme['stylesheet']] = $theme['package'];
539 }
540 if (empty(array_keys($_themes))) {
541 return $result;
542 }
543 if (class_exists('Theme_Upgrader')) {
544 if ($has_bv_skin) {
545 require_once( "bv_upgrader_skin.php" );
546 $skin = new BVUpgraderSkin("theme_upgrade");
547 $this->skin = $skin;
548 } else {
549 $skin = new Bulk_Theme_Upgrader_Skin();
550 }
551 $upgrader = new Theme_Upgrader($skin);
552 if ($bv_bulk_upgrade) {
553 $result = $this->bv_theme_bulk_upgrade($upgrader, $_themes);
554 } else {
555 $result = $upgrader->bulk_upgrade(array_keys($_themes));
556 }
557 if (!is_array($result)) {
558 return array('status' => "Error", 'message' =>'result is not an array');
559 }
560 foreach (array_keys($_themes) as $stylesheet) {
561 if (!array_key_exists($stylesheet, $result)) {
562 $result[$stylesheet] = array('status' => "Error");
563 } else {
564 $res = $result[$stylesheet];
565 if (!$res || is_wp_error($res)) {
566 $result[$stylesheet] = array('status' => "Error");
567 } else {
568 $result[$stylesheet] = array('status' => "Done");
569 }
570 }
571 }
572 }
573 return $result;
574 }
575
576 function install($params, $has_bv_skin = false) {
577 $result = array();
578 if (isset($params['plugins'])) {
579 foreach ($params['plugins'] as $plugin) {
580 if (!array_key_exists('plugins', $result))
581 $result["plugins"] = array();
582 $plugin['dest'] = WP_PLUGIN_DIR;
583 $res = $this->installPackage("plugin", $plugin, $has_bv_skin);
584 $pluginName = $plugin['package'];
585 $result["plugins"][$pluginName] = $res;
586 }
587 }
588 if (isset($params['themes'])) {
589 foreach ($params['themes'] as $theme) {
590 if (!array_key_exists('themes', $result))
591 $result["themes"] = array();
592 $theme['dest'] = WP_CONTENT_DIR.'/themes';
593 $res = $this->installPackage("theme", $theme, $has_bv_skin);
594 $themeName = $theme['package'];
595 $result["themes"][$themeName] = $res;
596 }
597 }
598 return $result;
599 }
600
601 function installPackage($type, $params, $has_bv_skin = false) {
602 global $wp_filesystem;
603
604 if (!isset($params['package']) || empty($params['package'])) {
605 return array('status' => "Error", 'message' => "No package is sent");
606 }
607 $valid_domain_regex = "/^(http|https):\/\/[\-\w]*\.(blogvault\.net|w\.org|wp\.org|wordpress\.org)\//";
608 if (WPRHelper::safePregMatch($valid_domain_regex, $params['package']) !== 1) {
609 return array('status' => "Error", 'message' => "Invalid package domain");
610 }
611 if ($has_bv_skin) {
612 require_once( "bv_upgrader_skin.php" );
613 $skin = new BVUpgraderSkin("installer", array(), $params['package']);
614 $this->skin = $skin;
615 } else {
616 $skin = new WP_Upgrader_Skin();
617 }
618 if ("plugin" === $type) {
619 $upgrader = new Plugin_Upgrader($skin);
620 } elseif ("theme" === $type) {
621 $upgrader = new Theme_Upgrader($skin);
622 } else {
623 $upgrader = new WP_Upgrader($skin);
624 }
625 $upgrader->init();
626 $destination = $params['dest'];
627 $clear_destination = isset($params['cleardest']) ? $params['cleardest'] : false;
628 $package_url = $params['package'];
629 $key = basename($package_url);
630 add_filter('upgrader_source_selection', array($upgrader, 'check_package'));
631 $res = $upgrader->run(
632 array(
633 'package' => $package_url,
634 'destination' => $destination,
635 'clear_destination' => $clear_destination,
636 'clear_working' => true,
637 'hook_extra' => array(
638 "type" => $type,
639 "action" => "install"
640 ),
641 )
642 );
643 remove_filter('upgrader_source_selection', array($upgrader, 'check_package'));
644 if (is_wp_error($res)) {
645 $res = array('status' => "Error", 'message' => $this->getError($res));
646 } else {
647 $res = array( 'status' => "Done");
648 }
649 return $res;
650 }
651
652 function getPremiumUpdates() {
653 return apply_filters( 'mwp_premium_update_notification', array() );
654 }
655
656 function getPremiumUpgradesInfo() {
657 return apply_filters( 'mwp_premium_perform_update', array() );
658 }
659
660 function autoLogin($username, $isHttps) {
661 $user = get_user_by('login', $username);
662 if ($user != FALSE) {
663 wp_set_current_user( $user->ID );
664 if ($isHttps) {
665 wp_set_auth_cookie( $user->ID, false, true );
666 } else {
667 # As we are not sure about wp-cofig.php settings for sure login
668 wp_set_auth_cookie( $user->ID, false, true );
669 wp_set_auth_cookie( $user->ID, false, false );
670 }
671 $redirect_to = get_admin_url();
672 wp_safe_redirect( $redirect_to );
673 exit;
674 }
675 }
676
677 public function refreshPluginUpdates() {
678 global $wp_current_filter;
679 $wp_current_filter[] = 'load-update-core.php';
680
681 wp_update_plugins();
682
683 array_pop($wp_current_filter);
684
685 wp_update_plugins();
686
687 return true;
688 }
689
690 public function refreshThemeUpdates() {
691 global $wp_current_filter;
692 $wp_current_filter[] = 'load-update-core.php';
693
694 wp_update_themes();
695
696 array_pop($wp_current_filter);
697
698 wp_update_themes();
699
700 return true;
701 }
702
703 function upgradeElementorDB($file) {
704 try {
705 $managerClass = $file === "elementor/elementor.php" ? '\Elementor\Core\Upgrade\Manager' : '\ElementorPro\Core\Upgrade\Manager';
706
707 if (!class_exists($managerClass)) {
708 return array('status' => 'Error', 'error' => 'Elementor plugin not found or disabled', 'source' => 'BV');
709 }
710
711 $manager = new $managerClass();
712 $required_methods = array('get_task_runner', 'should_upgrade', 'on_runner_complete',
713 'get_current_version', 'get_new_version');
714 foreach ($required_methods as $method) {
715 if (!method_exists($manager, $method)) {
716 return array('status' => 'Error', 'error' => 'Required methods are missing', 'source' => 'BV');
717 }
718 }
719
720 $updateInfo = array(
721 'from' => $manager->get_current_version(),
722 'to' => $manager->get_new_version(),
723 );
724
725 if ($manager->should_upgrade()) {
726 $callbacks = $manager->get_upgrade_callbacks();
727
728 if (!empty($callbacks)) {
729 $manager->get_task_runner()->handle_immediately($callbacks);
730 $manager->on_runner_complete(true);
731 }
732 } else {
733 return array('status' => 'Error', 'error' => 'Database Update is not available currently',
734 'update_info' => $updateInfo, 'source' => 'BV');
735 }
736
737 return array('status' => 'Done', 'update_info' => $updateInfo);
738 } catch (Exception $e) {
739 return array('status' => 'Error', 'error' => $e->getMessage());
740 }
741 }
742
743 function upgradeWoocommerceDb() {
744 try {
745 if (!defined('WC_ABSPATH')) {
746 return array('status' => 'Error', 'error' => 'WC not found', 'source' => 'BV');
747 }
748
749 if (file_exists(WC_ABSPATH . 'includes/class-wc-install.php')) {
750 include_once WC_ABSPATH . 'includes/class-wc-install.php';
751 }
752
753 if (file_exists(WC_ABSPATH . 'includes/wc-update-functions.php')) {
754 include_once WC_ABSPATH . 'includes/wc-update-functions.php';
755 }
756
757 if (!class_exists('WC_Install') || !method_exists('WC_Install', 'needs_db_update') ||
758 !method_exists('WC_Install', 'get_db_update_callbacks')) {
759 return array('status' => 'Error', 'error' => 'WC files missing or corrupted', 'source' => 'BV');
760 }
761
762 $current_db_version = $this->settings->getOption('woocommerce_db_version');
763 if (!$current_db_version) {
764 return array('status' => 'Error', 'error' => 'Current WC DB version not available', 'source' => 'BV');
765 }
766
767 $latest_db_version = $this->bvinfo->getLatestWooCommerceDBVersion();
768 if ($current_db_version >= $latest_db_version) {
769 return array('status' => 'Error', 'error' => 'WC DB update not available', 'source' => 'BV');
770 }
771
772 $db_update_callbacks = WC_Install::get_db_update_callbacks();
773
774 $loop = 0;
775 foreach ($db_update_callbacks as $version => $update_callbacks) {
776 if (version_compare($current_db_version, $version, '<')) {
777 foreach ($update_callbacks as $update_callback) {
778 WC()->queue()->schedule_single(
779 time() + $loop,
780 'woocommerce_run_update_callback',
781 array('update_callback' => $update_callback),
782 'woocommerce-db-updates'
783 );
784 $loop++;
785 }
786 }
787 }
788
789 $current_wc_version = WC()->version;
790 if (version_compare($current_db_version, $current_wc_version, '<') &&
791 !WC()->queue()->get_next('woocommerce_update_db_to_current_version')) {
792 WC()->queue()->schedule_single(
793 time() + $loop,
794 'woocommerce_update_db_to_current_version',
795 array('version' => $current_wc_version),
796 'woocommerce-db-updates'
797 );
798 }
799
800 return array('status' => 'Done');
801 } catch (Exception $e) {
802 return array('status' => 'Error', 'error' => $e->getMessage());
803 }
804 }
805
806 function upgrade_db(){
807 if (function_exists('wp_upgrade')) {
808 wp_upgrade();
809 return "Done";
810 } else {
811 return "NOUPGRADERFUNCTION";
812 }
813 }
814
815 function process($request) {
816 global $wp_filesystem;
817 $this->include_files();
818
819 if (!$this->is_pantheon() && !$wp_filesystem) {
820 WP_Filesystem();
821 }
822
823 $params = $request->params;
824 $resp = array();
825 switch ($request->method) {
826 case "adusr":
827 $resp = array("adduser" => $this->addUser($params['args']));
828 break;
829 case "upgrde":
830 $has_bv_skin = array_key_exists('bvskin', $params);
831 $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $params['args']);
832 $resp = array("upgrades" => $this->upgrade($params['args'], $has_bv_skin, $bv_bulk_upgrade));
833 break;
834 case "cmbneupgrde":
835 $args = $params['args'];
836 $has_bv_skin = array_key_exists('bvskin', $args);
837 $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $args);
838
839 $resp['upgrades'] = $this->upgrade($args['upgrades'], $has_bv_skin, $bv_bulk_upgrade);
840
841 if (isset($args['delete_transient'])) {
842 $resp['delete_transient'] = $this->settings->deleteTransient($args['delete_transient']);
843 }
844 if (isset($args['wp_update_plugins'])) {
845 $resp['wp_update_plugins'] = $this->refreshPluginUpdates();
846 }
847 if (isset($args['wp_update_themes'])) {
848 $resp['wp_update_themes'] = $this->refreshThemeUpdates();
849 }
850 break;
851 case "edt":
852 $resp = array("edit" => $this->edit($params['args']));
853 break;
854 case "instl":
855 $has_bv_skin = array_key_exists('bvskin', $params);
856 $resp = array("install" => $this->install($params['args'], $has_bv_skin));
857 break;
858 case "getpremiumupdates":
859 $resp = array("premiumupdates" => $this->getPremiumUpdates());
860 break;
861 case "getpremiumupgradesinfo":
862 $resp = array("premiumupgradesinfo" => $this->getPremiumUpgradesInfo());
863 break;
864 case "wrteble":
865 $resp = array("writeable" => $this->isServerWritable());
866 break;
867 case "atolgn":
868 $isHttps = false;
869 if (array_key_exists('https', $params))
870 $isHttps = true;
871 $resp = array("autologin" => $this->autoLogin($params['username'], $isHttps));
872 break;
873 case "updatedb":
874 $resp = array("status" => $this->upgrade_db());
875 break;
876 case "updateplgndb":
877 $resp = array();
878 $files = $params['files'];
879
880 foreach ($files as $file) {
881 switch ($file) {
882 case "woocommerce/woocommerce.php":
883 $resp[$file] = $this->upgradeWoocommerceDb();
884 break;
885 case "elementor/elementor.php":
886 case "elementor-pro/elementor-pro.php":
887 $resp[$file] = $this->upgradeElementorDB($file);
888 break;
889 }
890 }
891
892 break;
893 default:
894 $resp = false;
895 }
896 if ($this->skin && is_array($resp)) {
897 $resp = array_merge($resp, $this->skin->status);
898 }
899 return $resp;
900 }
901 }
902 endif;