| @@ -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.3; | |
| 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 | } |
| @@ -419,9 +500,18 @@ | ||
| 419 | 500 | $result = array(); |
| 420 | 501 | $_plugins = array(); |
| 421 | 502 | $plugins_by_name = array(); |
| 422 | 503 | foreach ($plugins as $plugin) { |
| 423 | - $_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 | + } | |
| 424 | 514 | $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin['file'], false, true); |
| 425 | 515 | $plugins_by_name[$plugin_data['Name']] = $plugin['file']; |
| 426 | 516 | } |
| 427 | 517 | if (empty(array_keys($_plugins))) { |
| @@ -429,9 +519,9 @@ | ||
| 429 | 519 | } |
| 430 | 520 | if (class_exists('Plugin_Upgrader')) { |
| 431 | 521 | if ($has_bv_skin) { |
| 432 | 522 | require_once( "bv_upgrader_skin.php" ); |
| 433 | - $skin = new BVUpgraderSkin("plugin_upgrade", $plugins_by_name); | |
| 523 | + $skin = new WPRUpgraderSkin("plugin_upgrade", $plugins_by_name); | |
| 434 | 524 | $this->skin = $skin; |
| 435 | 525 | } else { |
| 436 | 526 | $skin = new Bulk_Plugin_Upgrader_Skin(); |
| 437 | 527 | } |
| @@ -441,8 +531,11 @@ | ||
| 441 | 531 | $result = $this->bv_plugin_bulk_upgrade($upgrader, $_plugins); |
| 442 | 532 | } else { |
| 443 | 533 | $result = $upgrader->bulk_upgrade(array_keys($_plugins)); |
| 444 | 534 | } |
| 535 | + if (!is_array($result)) { | |
| 536 | + return array('status' => "Error", 'message' =>'result is not an array'); | |
| 537 | + } | |
| 445 | 538 | foreach (array_keys($_plugins) as $file) { |
| 446 | 539 | if (!array_key_exists($file, $result)) { |
| 447 | 540 | $result[$file] = array('status' => "Error"); |
| 448 | 541 | } else { |
| @@ -458,9 +551,11 @@ | ||
| 458 | 551 | return $result; |
| 459 | 552 | } |
| 460 | 553 | |
| 461 | 554 | function bv_theme_bulk_upgrade($upgrader, $_themes) { |
| 555 | + global $wp_version; | |
| 462 | 556 | $themes = array_keys($_themes); |
| 557 | + $current = get_site_transient('update_themes'); | |
| 463 | 558 | $args = array(); |
| 464 | 559 | $defaults = array( |
| 465 | 560 | 'clear_update_cache' => true, |
| 466 | 561 | ); |
| @@ -490,21 +585,59 @@ | ||
| 490 | 585 | $upgrader->update_current = 0; |
| 491 | 586 | foreach ($themes as $theme) { |
| 492 | 587 | $upgrader->update_current++; |
| 493 | 588 | $upgrader->skin->theme_info = $upgrader->theme_info($theme); |
| 494 | - $result = $upgrader->run( | |
| 495 | - array( | |
| 496 | - 'package' => $_themes[$theme], | |
| 497 | - 'destination' => get_theme_root($theme), | |
| 498 | - 'clear_destination' => true, | |
| 499 | - 'clear_working' => true, | |
| 500 | - 'is_multi' => true, | |
| 501 | - 'hook_extra' => array( | |
| 502 | - 'theme' => $theme, | |
| 503 | - ), | |
| 504 | - ) | |
| 505 | - ); | |
| 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 | + ); | |
| 506 | 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 | + } | |
| 507 | 640 | $results[$theme] = $result; |
| 508 | 641 | if (false === $result) { |
| 509 | 642 | break; |
| 510 | 643 | } |
| @@ -540,9 +673,17 @@ | ||
| 540 | 673 | function upgradeThemes($themes, $has_bv_skin = false, $bv_bulk_upgrade = false) { |
| 541 | 674 | $result = array(); |
| 542 | 675 | $_themes = array(); |
| 543 | 676 | foreach ($themes as $theme) { |
| 544 | - $_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 | + } | |
| 545 | 686 | } |
| 546 | 687 | if (empty(array_keys($_themes))) { |
| 547 | 688 | return $result; |
| 548 | 689 | } |
| @@ -548,9 +689,9 @@ | ||
| 548 | 689 | } |
| 549 | 690 | if (class_exists('Theme_Upgrader')) { |
| 550 | 691 | if ($has_bv_skin) { |
| 551 | 692 | require_once( "bv_upgrader_skin.php" ); |
| 552 | - $skin = new BVUpgraderSkin("theme_upgrade"); | |
| 693 | + $skin = new WPRUpgraderSkin("theme_upgrade"); | |
| 553 | 694 | $this->skin = $skin; |
| 554 | 695 | } else { |
| 555 | 696 | $skin = new Bulk_Theme_Upgrader_Skin(); |
| 556 | 697 | } |
| @@ -559,8 +700,11 @@ | ||
| 559 | 700 | $result = $this->bv_theme_bulk_upgrade($upgrader, $_themes); |
| 560 | 701 | } else { |
| 561 | 702 | $result = $upgrader->bulk_upgrade(array_keys($_themes)); |
| 562 | 703 | } |
| 704 | + if (!is_array($result)) { | |
| 705 | + return array('status' => "Error", 'message' =>'result is not an array'); | |
| 706 | + } | |
| 563 | 707 | foreach (array_keys($_themes) as $stylesheet) { |
| 564 | 708 | if (!array_key_exists($stylesheet, $result)) { |
| 565 | 709 | $result[$stylesheet] = array('status' => "Error"); |
| 566 | 710 | } else { |
| @@ -612,9 +756,9 @@ | ||
| 612 | 756 | return array('status' => "Error", 'message' => "Invalid package domain"); |
| 613 | 757 | } |
| 614 | 758 | if ($has_bv_skin) { |
| 615 | 759 | require_once( "bv_upgrader_skin.php" ); |
| 616 | - $skin = new BVUpgraderSkin("installer", array(), $params['package']); | |
| 760 | + $skin = new WPRUpgraderSkin("installer", array(), $params['package']); | |
| 617 | 761 | $this->skin = $skin; |
| 618 | 762 | } else { |
| 619 | 763 | $skin = new WP_Upgrader_Skin(); |
| 620 | 764 | } |
| @@ -628,10 +772,14 @@ | ||
| 628 | 772 | $upgrader->init(); |
| 629 | 773 | $destination = $params['dest']; |
| 630 | 774 | $clear_destination = isset($params['cleardest']) ? $params['cleardest'] : false; |
| 631 | 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; | |
| 632 | 777 | $key = basename($package_url); |
| 633 | 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 | + } | |
| 634 | 782 | $res = $upgrader->run( |
| 635 | 783 | array( |
| 636 | 784 | 'package' => $package_url, |
| 637 | 785 | 'destination' => $destination, |
| @@ -643,8 +791,11 @@ | ||
| 643 | 791 | ), |
| 644 | 792 | ) |
| 645 | 793 | ); |
| 646 | 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 | + } | |
| 647 | 798 | if (is_wp_error($res)) { |
| 648 | 799 | $res = array('status' => "Error", 'message' => $this->getError($res)); |
| 649 | 800 | } else { |
| 650 | 801 | $res = array( 'status' => "Done"); |
| @@ -659,9 +810,17 @@ | ||
| 659 | 810 | function getPremiumUpgradesInfo() { |
| 660 | 811 | return apply_filters( 'mwp_premium_perform_update', array() ); |
| 661 | 812 | } |
| 662 | 813 | |
| 663 | - 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 | + | |
| 664 | 823 | $user = get_user_by('login', $username); |
| 665 | 824 | if ($user != FALSE) { |
| 666 | 825 | wp_set_current_user( $user->ID ); |
| 667 | 826 | if ($isHttps) { |
| @@ -676,8 +835,41 @@ | ||
| 676 | 835 | exit; |
| 677 | 836 | } |
| 678 | 837 | } |
| 679 | 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 | + | |
| 680 | 872 | public function refreshPluginUpdates() { |
| 681 | 873 | global $wp_current_filter; |
| 682 | 874 | $wp_current_filter[] = 'load-update-core.php'; |
| 683 | 875 | |
| @@ -702,66 +894,115 @@ | ||
| 702 | 894 | |
| 703 | 895 | return true; |
| 704 | 896 | } |
| 705 | 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 | + | |
| 706 | 938 | function upgradeWoocommerceDb() { |
| 707 | - if (!defined('WC_ABSPATH')) { | |
| 708 | - return array('status' => 'Error', 'error' => 'WC not found'); | |
| 709 | - } | |
| 939 | + try { | |
| 940 | + if (!defined('WC_ABSPATH')) { | |
| 941 | + return array('status' => 'Error', 'error' => 'WC not found', 'source' => 'BV'); | |
| 942 | + } | |
| 710 | 943 | |
| 711 | - if (file_exists(WC_ABSPATH . 'includes/class-wc-install.php')) { | |
| 712 | - include_once WC_ABSPATH . 'includes/class-wc-install.php'; | |
| 713 | - } | |
| 944 | + if (file_exists(WC_ABSPATH . 'includes/class-wc-install.php')) { | |
| 945 | + include_once WC_ABSPATH . 'includes/class-wc-install.php'; | |
| 946 | + } | |
| 714 | 947 | |
| 715 | - if (file_exists(WC_ABSPATH . 'includes/wc-update-functions.php')) { | |
| 716 | - include_once WC_ABSPATH . 'includes/wc-update-functions.php'; | |
| 717 | - } | |
| 948 | + if (file_exists(WC_ABSPATH . 'includes/wc-update-functions.php')) { | |
| 949 | + include_once WC_ABSPATH . 'includes/wc-update-functions.php'; | |
| 950 | + } | |
| 718 | 951 | |
| 719 | - if (!class_exists('WC_Install') || !method_exists('WC_Install', 'needs_db_update') || | |
| 720 | - !method_exists('WC_Install', 'get_db_update_callbacks')) { | |
| 721 | - return array('status' => 'Error', 'error' => 'WC files missing or corrupted'); | |
| 722 | - } | |
| 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 | + } | |
| 723 | 956 | |
| 724 | - $current_db_version = $this->settings->getOption('woocommerce_db_version'); | |
| 725 | - if (!$current_db_version) { | |
| 726 | - return array('status' => 'Error', 'error' => 'Current WC DB version not available'); | |
| 727 | - } | |
| 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 | + } | |
| 728 | 961 | |
| 729 | - $db_update_callbacks = WC_Install::get_db_update_callbacks(); | |
| 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 | + } | |
| 730 | 966 | |
| 731 | - $loop = 0; | |
| 732 | - foreach ($db_update_callbacks as $version => $update_callbacks) { | |
| 733 | - if (version_compare($current_db_version, $version, '<')) { | |
| 734 | - foreach ($update_callbacks as $update_callback) { | |
| 735 | - WC()->queue()->schedule_single( | |
| 736 | - time() + $loop, | |
| 737 | - 'woocommerce_run_update_callback', | |
| 738 | - array('update_callback' => $update_callback), | |
| 739 | - 'woocommerce-db-updates' | |
| 740 | - ); | |
| 741 | - $loop++; | |
| 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 | + } | |
| 742 | 981 | } |
| 743 | 982 | } |
| 744 | - } | |
| 745 | 983 | |
| 746 | - $current_wc_version = WC()->version; | |
| 747 | - if (version_compare($current_db_version, $current_wc_version, '<') && | |
| 748 | - !WC()->queue()->get_next('woocommerce_update_db_to_current_version')) { | |
| 749 | - WC()->queue()->schedule_single( | |
| 750 | - time() + $loop, | |
| 751 | - 'woocommerce_update_db_to_current_version', | |
| 752 | - array('version' => $current_wc_version), | |
| 753 | - 'woocommerce-db-updates' | |
| 754 | - ); | |
| 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()); | |
| 755 | 998 | } |
| 756 | - | |
| 757 | - return array('status' => 'Done'); | |
| 758 | 999 | } |
| 759 | 1000 | |
| 760 | 1001 | function upgrade_db(){ |
| 761 | 1002 | if (function_exists('wp_upgrade')) { |
| 762 | 1003 | wp_upgrade(); |
| 763 | - return "DONE"; | |
| 1004 | + return "Done"; | |
| 764 | 1005 | } else { |
| 765 | 1006 | return "NOUPGRADERFUNCTION"; |
| 766 | 1007 | } |
| 767 | 1008 | } |
| @@ -821,9 +1062,10 @@ | ||
| 821 | 1062 | case "atolgn": |
| 822 | 1063 | $isHttps = false; |
| 823 | 1064 | if (array_key_exists('https', $params)) |
| 824 | 1065 | $isHttps = true; |
| 825 | - $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)); | |
| 826 | 1068 | break; |
| 827 | 1069 | case "updatedb": |
| 828 | 1070 | $resp = array("status" => $this->upgrade_db()); |
| 829 | 1071 | break; |
| @@ -835,8 +1077,12 @@ | ||
| 835 | 1077 | switch ($file) { |
| 836 | 1078 | case "woocommerce/woocommerce.php": |
| 837 | 1079 | $resp[$file] = $this->upgradeWoocommerceDb(); |
| 838 | 1080 | break; |
| 1081 | + case "elementor/elementor.php": | |
| 1082 | + case "elementor-pro/elementor-pro.php": | |
| 1083 | + $resp[$file] = $this->upgradeElementorDB($file); | |
| 1084 | + break; | |
| 839 | 1085 | } |
| 840 | 1086 | } |
| 841 | 1087 | |
| 842 | 1088 | break; |
| @@ -848,5 +1094,5 @@ | ||
| 848 | 1094 | } |
| 849 | 1095 | return $resp; |
| 850 | 1096 | } |
| 851 | 1097 | } |
| 852 | -endif; | |
| 1098 | +endif; | |