PluginProbe
The WP Remote WordPress Plugin / 6.76
The WP Remote WordPress Plugin v6.76
6.76 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 All 54 releases
← All changes | callback/wings/manage.php +425 -66 4.876.76 View file →
@@ -1,16 +1,18 @@
1 1 <?php
2 2
3 3 if (!defined('ABSPATH')) exit;
4 -if (!class_exists('BVManageCallback')) :
5 -class BVManageCallback extends BVCallbackBase {
4 +if (!class_exists('WPRManageCallback')) :
5 +class WPRManageCallback extends WPRCallbackBase {
6 6 public $settings;
7 7 public $skin;
8 + public $bvinfo;
8 9
9 - const MANAGE_WING_VERSION = 1.1;
10 + const MANAGE_WING_VERSION = 2.0;
10 11
11 12 public function __construct($callback_handler) {
12 13 $this->settings = $callback_handler->settings;
14 + $this->bvinfo = new WPRInfo($this->settings);
13 15 }
14 16
15 17 function getError($err) {
16 18 return $this->objectToArray($err);
@@ -31,23 +33,30 @@
31 33 return true;
32 34 }
33 35 }
34 36
37 + /**
38 + * Load a file with require_once only if it exists, so missing files don't fatal the script.
39 + */
40 + function safe_require_once($path) {
41 + if ($path && file_exists($path)) {
42 + require_once $path;
43 + }
44 + }
45 +
35 46 function include_files() {
36 - @include_once ABSPATH.'wp-admin/includes/file.php';
37 - @include_once ABSPATH.'wp-admin/includes/plugin.php';
38 - @include_once ABSPATH.'wp-admin/includes/theme.php';
39 - @include_once ABSPATH.'wp-admin/includes/misc.php';
40 - @include_once ABSPATH.'wp-admin/includes/template.php';
41 - @include_once ABSPATH.'wp-includes/pluggable.php';
42 - @include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
43 - @include_once ABSPATH.'wp-admin/includes/class-theme-upgrader.php';
44 - @include_once ABSPATH.'wp-admin/includes/class-plugin-upgrader.php';
45 - @include_once ABSPATH.'wp-admin/includes/user.php';
46 - @include_once ABSPATH.'wp-includes/registration.php';
47 - @include_once ABSPATH.'wp-admin/includes/upgrade.php';
48 - @include_once ABSPATH.'wp-admin/includes/update.php';
49 - @require_once ABSPATH.'wp-admin/includes/update-core.php';
47 + $this->safe_require_once(ABSPATH.'wp-admin/includes/file.php');
48 + $this->safe_require_once(ABSPATH.'wp-admin/includes/plugin.php');
49 + $this->safe_require_once(ABSPATH.'wp-admin/includes/theme.php');
50 + $this->safe_require_once(ABSPATH.'wp-admin/includes/misc.php');
51 + $this->safe_require_once(ABSPATH.'wp-admin/includes/template.php');
52 + $this->safe_require_once(ABSPATH.'wp-includes/pluggable.php');
53 + $this->safe_require_once(ABSPATH.'wp-admin/includes/class-wp-upgrader.php');
54 + $this->safe_require_once(ABSPATH.'wp-admin/includes/class-theme-upgrader.php');
55 + $this->safe_require_once(ABSPATH.'wp-admin/includes/class-plugin-upgrader.php');
56 + $this->safe_require_once(ABSPATH.'wp-admin/includes/user.php');
57 + $this->safe_require_once(ABSPATH.'wp-admin/includes/upgrade.php');
58 + $this->safe_require_once(ABSPATH.'wp-admin/includes/update.php');
50 59 }
51 60
52 61 function edit($args) {
53 62 $result = array();
@@ -240,9 +249,9 @@
240 249 if (!empty($valid_updates)) {
241 250 if (class_exists('Language_Pack_Upgrader')) {
242 251 if ($has_bv_skin) {
243 252 require_once( "bv_upgrader_skin.php" );
244 - $skin = new BVUpgraderSkin("upgrade_translations");
253 + $skin = new WPRUpgraderSkin("upgrade_translations");
245 254 $this->skin = $skin;
246 255 } else {
247 256 $skin = new Language_Pack_Upgrader_Skin(array());
248 257 }
@@ -263,15 +272,54 @@
263 272 }
264 273
265 274 function upgradeCore($args) {
266 275 global $wp_filesystem, $wp_version;
267 - $core = $this->settings->getTransient('update_core');
268 - $core_update_index = intval($args['coreupdateindex']);
269 - if (isset($core->updates) && !empty($core->updates)) {
270 - $to_update = $core->updates[$core_update_index];
276 + $to_update = null;
277 +
278 + // Prefer validated update data from server (BlogVault), then site transient.
279 + // This protects upgrades from poisoned/overridden transients.
280 + $validated = null;
281 + if (isset($args['core_validated_update']) && !empty($args['core_validated_update'])) {
282 + $validated = $args['core_validated_update'];
283 + }
284 +
285 + if (!empty($validated) && is_array($validated) &&
286 + isset($validated['version']) && !empty($validated['version']) &&
287 + isset($validated['response']) && ($validated['response'] === 'upgrade')) {
288 + $to_update = new stdClass();
289 + $to_update->version = $validated['version'];
290 + $to_update->response = $validated['response'];
291 + $to_update->download = isset($validated['download']) ? $validated['download'] : '';
292 +
293 + // Preserve all packages keys if provided; Core_Upgrader expects packages-like data.
294 + if (isset($validated['packages']) && is_array($validated['packages'])) {
295 + $to_update->packages = (object)$validated['packages'];
296 + } else {
297 + $to_update->packages = new stdClass();
298 + }
299 +
300 + // WordPress uses either ->package or ->packages->full depending on path/version.
301 + if (isset($to_update->packages->full) && !empty($to_update->packages->full)) {
302 + $to_update->package = $to_update->packages->full;
303 + } else {
304 + $to_update->package = $to_update->download;
305 + $to_update->packages->full = $to_update->download;
306 + }
271 307 } else {
308 + // Fallback to transient-based approach
309 + $core = $this->settings->getTransient('update_core');
310 + $core_update_index = intval($args['coreupdateindex']);
311 + if (isset($core->updates) && !empty($core->updates)) {
312 + $to_update = $core->updates[$core_update_index];
313 + } else {
314 + return array('status' => "Error", "message" => "Updates not available");
315 + }
316 + }
317 +
318 + if (!$to_update) {
272 319 return array('status' => "Error", "message" => "Updates not available");
273 320 }
321 +
274 322 $resp = array("Core_Upgrader", class_exists('Core_Upgrader'));
275 323 if (version_compare($wp_version, '3.1.9', '>')) {
276 324 $core = new Core_Upgrader();
277 325 $result = $core->upgrade($to_update);
@@ -280,18 +328,8 @@
280 328 } else {
281 329 return array('status' => 'Done');
282 330 }
283 331 } else {
284 - $resp = array("wp_update_core", function_exists('wp_update_core'));
285 - if (function_exists('wp_update_core')) {
286 - $result = wp_update_core($to_update);
287 - if (is_wp_error($result)) {
288 - return array('status' => "Error", "message" => $this->getError($result));
289 - } else {
290 - return array('status' => 'Done');
291 - }
292 - }
293 -
294 332 $resp = array("WP_Upgrader", class_exists('WP_Upgrader'));
295 333 if (class_exists('WP_Upgrader')) {
296 334 $upgrader = new WP_Upgrader();
297 335
@@ -329,8 +367,9 @@
329 367 }
330 368
331 369 $wp_filesystem->chmod($wp_dir.'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
332 370
371 + $this->safe_require_once(ABSPATH.'wp-admin/includes/update-core.php');
333 372 $result = update_core($working_dir, $wp_dir);
334 373
335 374 if (is_wp_error($result)) {
336 375 return array('status' => "Error", "message" => $this->getError($result));
@@ -340,9 +379,11 @@
340 379 }
341 380 }
342 381
343 382 function bv_plugin_bulk_upgrade($upgrader, $_plugins) {
383 + global $wp_version;
344 384 $plugins = array_keys($_plugins);
385 + $current = get_site_transient('update_plugins');
345 386 $args = array();
346 387 $defaults = array(
347 388 'clear_update_cache' => true,
348 389 );
@@ -371,20 +412,60 @@
371 412 foreach($plugins as $plugin) {
372 413 $upgrader->update_current++;
373 414 $upgrader->skin->plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin, false, true);
374 415 $upgrader->skin->plugin_active = is_plugin_active($plugin);
375 - $result = $upgrader->run(
376 - array(
377 - 'package' => $_plugins[$plugin],
378 - 'destination' => WP_PLUGIN_DIR,
379 - 'clear_destination' => true,
380 - 'clear_working' => true,
381 - 'is_multi' => true,
382 - 'hook_extra' => array(
383 - 'plugin' => $plugin,
384 - ),
385 - )
386 - );
416 + $plugin_upgrade_data = $_plugins[$plugin];
417 + if (isset($current->response[$plugin])) {
418 + if (isset($current->response[$plugin]->requires)) {
419 + $plugin_upgrade_data['requires'] = $current->response[$plugin]->requires;
420 + }
421 + if (isset($current->response[$plugin]->requires_php)) {
422 + $plugin_upgrade_data['requires_php'] = $current->response[$plugin]->requires_php;
423 + }
424 + }
425 + if ( isset( $plugin_upgrade_data['requires'] ) && function_exists('is_wp_version_compatible') && !is_wp_version_compatible( $plugin_upgrade_data['requires'] ) ) {
426 + $result = new WP_Error(
427 + 'incompatible_wp_required_version',
428 + sprintf(
429 + __( 'Your WordPress version is %1$s, however the new plugin version requires %2$s.' ),
430 + $wp_version,
431 + $plugin_upgrade_data['requires']
432 + )
433 + );
434 +
435 + $upgrader->skin->before( $result );
436 + $upgrader->skin->error( $result );
437 + $upgrader->skin->after();
438 + } elseif ( isset( $plugin_upgrade_data['requires_php'] ) && function_exists('is_php_version_compatible') && !is_php_version_compatible( $plugin_upgrade_data['requires_php'] ) ) {
439 +
440 + $result = new WP_Error(
441 + 'incompatible_php_required_version',
442 + sprintf(
443 + __( 'The PHP version on your server is %1$s, however the new plugin version requires %2$s.' ),
444 + PHP_VERSION,
445 + $plugin_upgrade_data['requires_php']
446 + )
447 + );
448 +
449 + $upgrader->skin->before( $result );
450 + $upgrader->skin->error( $result );
451 + $upgrader->skin->after();
452 + } else {
453 + add_filter('upgrader_source_selection', array($upgrader, 'check_package'));
454 + $result = $upgrader->run(
455 + array(
456 + 'package' => $_plugins[$plugin]['package'],
457 + 'destination' => WP_PLUGIN_DIR,
458 + 'clear_destination' => true,
459 + 'clear_working' => true,
460 + 'is_multi' => true,
461 + 'hook_extra' => array(
462 + 'plugin' => $plugin,
463 + ),
464 + )
465 + );
466 + remove_filter('upgrader_source_selection', array($upgrader, 'check_package'));
467 + }
387 468 $results[$plugin] = $result;
388 469 if (false === $result) {
389 470 break;
390 471 }
@@ -417,10 +498,22 @@
417 498
418 499 function upgradePlugins($plugins, $has_bv_skin = false, $bv_bulk_upgrade = false) {
419 500 $result = array();
420 501 $_plugins = array();
502 + $plugins_by_name = array();
421 503 foreach ($plugins as $plugin) {
422 - $_plugins[$plugin['file']] = $plugin['package'];
504 + $_plugins[$plugin['file']] = [
505 + 'package' => $plugin['package']
506 + ];
507 + if (isset($plugin['requires'])) {
508 + $_plugins[$plugin['file']]['requires'] = $plugin['requires'];
509 + }
510 +
511 + if (isset($plugin['requires_php'])) {
512 + $_plugins[$plugin['file']]['requires_php'] = $plugin['requires_php'];
513 + }
514 + $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin['file'], false, true);
515 + $plugins_by_name[$plugin_data['Name']] = $plugin['file'];
423 516 }
424 517 if (empty(array_keys($_plugins))) {
425 518 return $result;
426 519 }
@@ -426,9 +519,9 @@
426 519 }
427 520 if (class_exists('Plugin_Upgrader')) {
428 521 if ($has_bv_skin) {
429 522 require_once( "bv_upgrader_skin.php" );
430 - $skin = new BVUpgraderSkin("plugin_upgrade");
523 + $skin = new WPRUpgraderSkin("plugin_upgrade", $plugins_by_name);
431 524 $this->skin = $skin;
432 525 } else {
433 526 $skin = new Bulk_Plugin_Upgrader_Skin();
434 527 }
@@ -438,8 +531,11 @@
438 531 $result = $this->bv_plugin_bulk_upgrade($upgrader, $_plugins);
439 532 } else {
440 533 $result = $upgrader->bulk_upgrade(array_keys($_plugins));
441 534 }
535 + if (!is_array($result)) {
536 + return array('status' => "Error", 'message' =>'result is not an array');
537 + }
442 538 foreach (array_keys($_plugins) as $file) {
443 539 if (!array_key_exists($file, $result)) {
444 540 $result[$file] = array('status' => "Error");
445 541 } else {
@@ -455,9 +551,11 @@
455 551 return $result;
456 552 }
457 553
458 554 function bv_theme_bulk_upgrade($upgrader, $_themes) {
555 + global $wp_version;
459 556 $themes = array_keys($_themes);
557 + $current = get_site_transient('update_themes');
460 558 $args = array();
461 559 $defaults = array(
462 560 'clear_update_cache' => true,
463 561 );
@@ -487,21 +585,59 @@
487 585 $upgrader->update_current = 0;
488 586 foreach ($themes as $theme) {
489 587 $upgrader->update_current++;
490 588 $upgrader->skin->theme_info = $upgrader->theme_info($theme);
491 - $result = $upgrader->run(
492 - array(
493 - 'package' => $_themes[$theme],
494 - 'destination' => get_theme_root($theme),
495 - 'clear_destination' => true,
496 - 'clear_working' => true,
497 - 'is_multi' => true,
498 - 'hook_extra' => array(
499 - 'theme' => $theme,
500 - ),
501 - )
502 - );
589 + $theme_upgrade_data = $_themes[$theme];
590 + if (isset($current->response[$theme])) {
591 + if (isset($current->response[$theme]['requires'])) {
592 + $theme_upgrade_data['requires'] = $current->response[$theme]['requires'];
593 + }
594 + if (isset($current->response[$theme]['requires_php'])) {
595 + $theme_upgrade_data['requires_php'] = $current->response[$theme]['requires_php'];
596 + }
597 + }
598 + if ( isset( $theme_upgrade_data['requires'] ) && function_exists('is_wp_version_compatible') && !is_wp_version_compatible( $theme_upgrade_data['requires'] ) ) {
599 + $result = new WP_Error(
600 + 'incompatible_wp_required_version',
601 + sprintf(
602 + __( 'Your WordPress version is %1$s, however the new theme version requires %2$s.' ),
603 + $wp_version,
604 + $theme_upgrade_data['requires']
605 + )
606 + );
503 607
608 + $upgrader->skin->before( $result );
609 + $upgrader->skin->error( $result );
610 + $upgrader->skin->after();
611 + } elseif ( isset( $theme_upgrade_data['requires_php'] ) && function_exists('is_php_version_compatible') && !is_php_version_compatible( $theme_upgrade_data['requires_php'] ) ) {
612 + $result = new WP_Error(
613 + 'incompatible_php_required_version',
614 + sprintf(
615 + __( 'The PHP version on your server is %1$s, however the new theme version requires %2$s.' ),
616 + PHP_VERSION,
617 + $theme_upgrade_data['requires_php']
618 + )
619 + );
620 +
621 + $upgrader->skin->before( $result );
622 + $upgrader->skin->error( $result );
623 + $upgrader->skin->after();
624 + } else {
625 + add_filter('upgrader_source_selection', array($upgrader, 'check_package'));
626 + $result = $upgrader->run(
627 + array(
628 + 'package' => $_themes[$theme]['package'],
629 + 'destination' => get_theme_root($theme),
630 + 'clear_destination' => true,
631 + 'clear_working' => true,
632 + 'is_multi' => true,
633 + 'hook_extra' => array(
634 + 'theme' => $theme,
635 + ),
636 + )
637 + );
638 + remove_filter('upgrader_source_selection', array($upgrader, 'check_package'));
639 + }
504 640 $results[$theme] = $result;
505 641 if (false === $result) {
506 642 break;
507 643 }
@@ -537,9 +673,17 @@
537 673 function upgradeThemes($themes, $has_bv_skin = false, $bv_bulk_upgrade = false) {
538 674 $result = array();
539 675 $_themes = array();
540 676 foreach ($themes as $theme) {
541 - $_themes[$theme['stylesheet']] = $theme['package'];
677 + $_themes[$theme['stylesheet']] = [
678 + 'package' => $theme['package']
679 + ];
680 + if (isset($theme['requires'])) {
681 + $_themes[$theme['stylesheet']]['requires'] = $theme['requires'];
682 + }
683 + if (isset($theme['requires_php'])) {
684 + $_themes[$theme['stylesheet']]['requires_php'] = $theme['requires_php'];
685 + }
542 686 }
543 687 if (empty(array_keys($_themes))) {
544 688 return $result;
545 689 }
@@ -545,9 +689,9 @@
545 689 }
546 690 if (class_exists('Theme_Upgrader')) {
547 691 if ($has_bv_skin) {
548 692 require_once( "bv_upgrader_skin.php" );
549 - $skin = new BVUpgraderSkin("theme_upgrade");
693 + $skin = new WPRUpgraderSkin("theme_upgrade");
550 694 $this->skin = $skin;
551 695 } else {
552 696 $skin = new Bulk_Theme_Upgrader_Skin();
553 697 }
@@ -556,8 +700,11 @@
556 700 $result = $this->bv_theme_bulk_upgrade($upgrader, $_themes);
557 701 } else {
558 702 $result = $upgrader->bulk_upgrade(array_keys($_themes));
559 703 }
704 + if (!is_array($result)) {
705 + return array('status' => "Error", 'message' =>'result is not an array');
706 + }
560 707 foreach (array_keys($_themes) as $stylesheet) {
561 708 if (!array_key_exists($stylesheet, $result)) {
562 709 $result[$stylesheet] = array('status' => "Error");
563 710 } else {
@@ -604,14 +751,14 @@
604 751 if (!isset($params['package']) || empty($params['package'])) {
605 752 return array('status' => "Error", 'message' => "No package is sent");
606 753 }
607 754 $valid_domain_regex = "/^(http|https):\/\/[\-\w]*\.(blogvault\.net|w\.org|wp\.org|wordpress\.org)\//";
608 - if (preg_match($valid_domain_regex, $params['package']) !== 1) {
755 + if (WPRHelper::safePregMatch($valid_domain_regex, $params['package']) !== 1) {
609 756 return array('status' => "Error", 'message' => "Invalid package domain");
610 757 }
611 758 if ($has_bv_skin) {
612 759 require_once( "bv_upgrader_skin.php" );
613 - $skin = new BVUpgraderSkin("installer", $params['package']);
760 + $skin = new WPRUpgraderSkin("installer", array(), $params['package']);
614 761 $this->skin = $skin;
615 762 } else {
616 763 $skin = new WP_Upgrader_Skin();
617 764 }
@@ -625,10 +772,14 @@
625 772 $upgrader->init();
626 773 $destination = $params['dest'];
627 774 $clear_destination = isset($params['cleardest']) ? $params['cleardest'] : false;
628 775 $package_url = $params['package'];
776 + $is_parent_theme_install_disabled = isset($params['is_parent_theme_install_disabled']) ? $params['is_parent_theme_install_disabled'] : false;
629 777 $key = basename($package_url);
630 778 add_filter('upgrader_source_selection', array($upgrader, 'check_package'));
779 + if ("theme" === $type && false === $is_parent_theme_install_disabled) {
780 + add_filter('upgrader_post_install', array($upgrader, 'check_parent_theme_filter'), 10, 3);
781 + }
631 782 $res = $upgrader->run(
632 783 array(
633 784 'package' => $package_url,
634 785 'destination' => $destination,
@@ -640,8 +791,11 @@
640 791 ),
641 792 )
642 793 );
643 794 remove_filter('upgrader_source_selection', array($upgrader, 'check_package'));
795 + if ("theme" === $type && false === $is_parent_theme_install_disabled) {
796 + remove_filter('upgrader_post_install', array($upgrader, 'check_parent_theme_filter'), 10);
797 + }
644 798 if (is_wp_error($res)) {
645 799 $res = array('status' => "Error", 'message' => $this->getError($res));
646 800 } else {
647 801 $res = array( 'status' => "Done");
@@ -656,9 +810,17 @@
656 810 function getPremiumUpgradesInfo() {
657 811 return apply_filters( 'mwp_premium_perform_update', array() );
658 812 }
659 813
660 - function autoLogin($username, $isHttps) {
814 + function autoLogin($username, $isHttps, $auto_login_token = null) {
815 + # Validate nonce if provided (other plugin compatibility: allow login if token missing)
816 + if ($auto_login_token !== null && $auto_login_token !== '') {
817 + $validation_result = $this->validateAutoLoginToken($auto_login_token);
818 + if ($validation_result !== true) {
819 + return $validation_result;
820 + }
821 + }
822 +
661 823 $user = get_user_by('login', $username);
662 824 if ($user != FALSE) {
663 825 wp_set_current_user( $user->ID );
664 826 if ($isHttps) {
@@ -673,12 +835,174 @@
673 835 exit;
674 836 }
675 837 }
676 838
839 + private function validateAutoLoginToken($auto_login_token) {
840 + # Get plugin name for transient key prefix
841 + $plugname = $this->bvinfo->plugname;
842 + if (empty($plugname)) {
843 + return array(
844 + 'status' => 'Error',
845 + 'message' => 'PLUGIN_NAME_NOT_FOUND',
846 + 'error_code' => 'PLUGIN_NAME_ERROR'
847 + );
848 + }
849 +
850 + # Construct transient key: {plugname}_auto_login_tk_{token}
851 + $transient_key = $plugname . '_auto_login_tk_' . $auto_login_token;
852 +
853 + # Check if token has already been used
854 + $used_token = $this->settings->getTransient($transient_key);
855 + if ($used_token !== false) {
856 + # Token already used - prevent replay attack
857 + return array(
858 + 'status' => 'Error',
859 + 'message' => 'AUTO_LOGIN_TOKEN_ALREADY_USED',
860 + 'error_code' => 'AUTO_LOGIN_TOKEN_ERROR'
861 + );
862 + }
863 +
864 + # Store token as used for 24 hours to prevent reuse
865 + # WordPress will automatically clean up expired transients
866 + $this->settings->setTransient($transient_key, true, DAY_IN_SECONDS);
867 +
868 + # Token is valid and has been marked as used
869 + return true;
870 + }
871 +
872 + public function refreshPluginUpdates() {
873 + global $wp_current_filter;
874 + $wp_current_filter[] = 'load-update-core.php';
875 +
876 + wp_update_plugins();
877 +
878 + array_pop($wp_current_filter);
879 +
880 + wp_update_plugins();
881 +
882 + return true;
883 + }
884 +
885 + public function refreshThemeUpdates() {
886 + global $wp_current_filter;
887 + $wp_current_filter[] = 'load-update-core.php';
888 +
889 + wp_update_themes();
890 +
891 + array_pop($wp_current_filter);
892 +
893 + wp_update_themes();
894 +
895 + return true;
896 + }
897 +
898 + function upgradeElementorDB($file) {
899 + try {
900 + $managerClass = $file === "elementor/elementor.php" ? '\Elementor\Core\Upgrade\Manager' : '\ElementorPro\Core\Upgrade\Manager';
901 +
902 + if (!class_exists($managerClass)) {
903 + return array('status' => 'Error', 'error' => 'Elementor plugin not found or disabled', 'source' => 'BV');
904 + }
905 +
906 + $manager = new $managerClass();
907 + $required_methods = array('get_task_runner', 'should_upgrade', 'on_runner_complete',
908 + 'get_current_version', 'get_new_version');
909 + foreach ($required_methods as $method) {
910 + if (!method_exists($manager, $method)) {
911 + return array('status' => 'Error', 'error' => 'Required methods are missing', 'source' => 'BV');
912 + }
913 + }
914 +
915 + $updateInfo = array(
916 + 'from' => $manager->get_current_version(),
917 + 'to' => $manager->get_new_version(),
918 + );
919 +
920 + if ($manager->should_upgrade()) {
921 + $callbacks = $manager->get_upgrade_callbacks();
922 +
923 + if (!empty($callbacks)) {
924 + $manager->get_task_runner()->handle_immediately($callbacks);
925 + $manager->on_runner_complete(true);
926 + }
927 + } else {
928 + return array('status' => 'Error', 'error' => 'Database Update is not available currently',
929 + 'update_info' => $updateInfo, 'source' => 'BV');
930 + }
931 +
932 + return array('status' => 'Done', 'update_info' => $updateInfo);
933 + } catch (Exception $e) {
934 + return array('status' => 'Error', 'error' => $e->getMessage());
935 + }
936 + }
937 +
938 + function upgradeWoocommerceDb() {
939 + try {
940 + if (!defined('WC_ABSPATH')) {
941 + return array('status' => 'Error', 'error' => 'WC not found', 'source' => 'BV');
942 + }
943 +
944 + if (file_exists(WC_ABSPATH . 'includes/class-wc-install.php')) {
945 + include_once WC_ABSPATH . 'includes/class-wc-install.php';
946 + }
947 +
948 + if (file_exists(WC_ABSPATH . 'includes/wc-update-functions.php')) {
949 + include_once WC_ABSPATH . 'includes/wc-update-functions.php';
950 + }
951 +
952 + if (!class_exists('WC_Install') || !method_exists('WC_Install', 'needs_db_update') ||
953 + !method_exists('WC_Install', 'get_db_update_callbacks')) {
954 + return array('status' => 'Error', 'error' => 'WC files missing or corrupted', 'source' => 'BV');
955 + }
956 +
957 + $current_db_version = $this->settings->getOption('woocommerce_db_version');
958 + if (!$current_db_version) {
959 + return array('status' => 'Error', 'error' => 'Current WC DB version not available', 'source' => 'BV');
960 + }
961 +
962 + $latest_db_version = $this->bvinfo->getLatestWooCommerceDBVersion();
963 + if ($current_db_version >= $latest_db_version) {
964 + return array('status' => 'Error', 'error' => 'WC DB update not available', 'source' => 'BV');
965 + }
966 +
967 + $db_update_callbacks = WC_Install::get_db_update_callbacks();
968 +
969 + $loop = 0;
970 + foreach ($db_update_callbacks as $version => $update_callbacks) {
971 + if (version_compare($current_db_version, $version, '<')) {
972 + foreach ($update_callbacks as $update_callback) {
973 + WC()->queue()->schedule_single(
974 + time() + $loop,
975 + 'woocommerce_run_update_callback',
976 + array('update_callback' => $update_callback),
977 + 'woocommerce-db-updates'
978 + );
979 + $loop++;
980 + }
981 + }
982 + }
983 +
984 + $current_wc_version = WC()->version;
985 + if (version_compare($current_db_version, $current_wc_version, '<') &&
986 + !WC()->queue()->get_next('woocommerce_update_db_to_current_version')) {
987 + WC()->queue()->schedule_single(
988 + time() + $loop,
989 + 'woocommerce_update_db_to_current_version',
990 + array('version' => $current_wc_version),
991 + 'woocommerce-db-updates'
992 + );
993 + }
994 +
995 + return array('status' => 'Done');
996 + } catch (Exception $e) {
997 + return array('status' => 'Error', 'error' => $e->getMessage());
998 + }
999 + }
1000 +
677 1001 function upgrade_db(){
678 1002 if (function_exists('wp_upgrade')) {
679 1003 wp_upgrade();
680 - return "DONE";
1004 + return "Done";
681 1005 } else {
682 1006 return "NOUPGRADERFUNCTION";
683 1007 }
684 1008 }
@@ -701,8 +1025,25 @@
701 1025 $has_bv_skin = array_key_exists('bvskin', $params);
702 1026 $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $params['args']);
703 1027 $resp = array("upgrades" => $this->upgrade($params['args'], $has_bv_skin, $bv_bulk_upgrade));
704 1028 break;
1029 + case "cmbneupgrde":
1030 + $args = $params['args'];
1031 + $has_bv_skin = array_key_exists('bvskin', $args);
1032 + $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $args);
1033 +
1034 + $resp['upgrades'] = $this->upgrade($args['upgrades'], $has_bv_skin, $bv_bulk_upgrade);
1035 +
1036 + if (isset($args['delete_transient'])) {
1037 + $resp['delete_transient'] = $this->settings->deleteTransient($args['delete_transient']);
1038 + }
1039 + if (isset($args['wp_update_plugins'])) {
1040 + $resp['wp_update_plugins'] = $this->refreshPluginUpdates();
1041 + }
1042 + if (isset($args['wp_update_themes'])) {
1043 + $resp['wp_update_themes'] = $this->refreshThemeUpdates();
1044 + }
1045 + break;
705 1046 case "edt":
706 1047 $resp = array("edit" => $this->edit($params['args']));
707 1048 break;
708 1049 case "instl":
@@ -721,13 +1062,31 @@
721 1062 case "atolgn":
722 1063 $isHttps = false;
723 1064 if (array_key_exists('https', $params))
724 1065 $isHttps = true;
725 - $resp = array("autologin" => $this->autoLogin($params['username'], $isHttps));
1066 + $auto_login_token = array_key_exists('auto_login_token', $params) ? $params['auto_login_token'] : null;
1067 + $resp = array("autologin" => $this->autoLogin($params['username'], $isHttps, $auto_login_token));
726 1068 break;
727 1069 case "updatedb":
728 1070 $resp = array("status" => $this->upgrade_db());
729 1071 break;
1072 + case "updateplgndb":
1073 + $resp = array();
1074 + $files = $params['files'];
1075 +
1076 + foreach ($files as $file) {
1077 + switch ($file) {
1078 + case "woocommerce/woocommerce.php":
1079 + $resp[$file] = $this->upgradeWoocommerceDb();
1080 + break;
1081 + case "elementor/elementor.php":
1082 + case "elementor-pro/elementor-pro.php":
1083 + $resp[$file] = $this->upgradeElementorDB($file);
1084 + break;
1085 + }
1086 + }
1087 +
1088 + break;
730 1089 default:
731 1090 $resp = false;
732 1091 }
733 1092 if ($this->skin && is_array($resp)) {
@@ -735,5 +1094,5 @@
735 1094 }
736 1095 return $resp;
737 1096 }
738 1097 }
739 -endif;
1098 +endif;