PluginProbe
The WP Remote WordPress Plugin / 4.79
The WP Remote WordPress Plugin v4.79
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
← All changes | callback/wings/manage.php +75 -626 6.654.79 View file →
@@ -1,18 +1,16 @@
1 1 <?php
2 2
3 3 if (!defined('ABSPATH')) exit;
4 -if (!class_exists('WPRManageCallback')) :
5 -class WPRManageCallback extends WPRCallbackBase {
4 +if (!class_exists('BVManageCallback')) :
5 +class BVManageCallback extends BVCallbackBase {
6 6 public $settings;
7 7 public $skin;
8 - public $bvinfo;
9 8
10 - const MANAGE_WING_VERSION = 2.0;
9 + const MANAGE_WING_VERSION = 1.0;
11 10
12 11 public function __construct($callback_handler) {
13 12 $this->settings = $callback_handler->settings;
14 - $this->bvinfo = new WPRInfo($this->settings);
15 13 }
16 14
17 15 function getError($err) {
18 16 return $this->objectToArray($err);
@@ -33,30 +31,21 @@
33 31 return true;
34 32 }
35 33 }
36 34
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 -
46 35 function include_files() {
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');
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/user.php';
44 + @include_once ABSPATH.'wp-includes/registration.php';
45 + @include_once ABSPATH.'wp-admin/includes/upgrade.php';
46 + @include_once ABSPATH.'wp-admin/includes/update.php';
47 + @require_once ABSPATH.'wp-admin/includes/update-core.php';
59 48 }
60 49
61 50 function edit($args) {
62 51 $result = array();
@@ -196,16 +185,11 @@
196 185 return array('status' => "Error", 'message' => $this->getError($result));
197 186 }
198 187 }
199 188
200 - function upgrade($params = null, $has_bv_skin = false, $bv_bulk_upgrade = false) {
189 + function upgrade($params = null, $has_bv_skin = false) {
201 190 $result = array();
202 191 $premium_upgrades = array();
203 - if (array_key_exists('clear_filters', $params)) {
204 - $filters = $params['clear_filters'];
205 - foreach ($filters as $filter)
206 - remove_all_filters($filter);
207 - }
208 192 if (array_key_exists('core', $params) && !empty($params['core'])) {
209 193 $result['core'] = $this->upgradeCore($params['core']);
210 194 }
211 195 if (array_key_exists('translations', $params) && !empty($params['translations'])) {
@@ -211,12 +195,24 @@
211 195 if (array_key_exists('translations', $params) && !empty($params['translations'])) {
212 196 $result['translations'] = $this->upgradeTranslations($params['translations'], $has_bv_skin);
213 197 }
214 198 if (array_key_exists('plugins', $params) && !empty($params['plugins'])) {
215 - $result['plugins'] = $this->upgradePlugins($params['plugins'], $has_bv_skin, $bv_bulk_upgrade);
199 + $files = array();
200 + foreach ($params['plugins'] as $plugin) {
201 + $files[] = $plugin['file'];
202 + }
203 + if (!empty($files)) {
204 + $result['plugins'] = $this->upgradePlugins($files, $has_bv_skin);
205 + }
216 206 }
217 207 if (array_key_exists('themes', $params) && !empty($params['themes'])) {
218 - $result['themes'] = $this->upgradeThemes($params['themes'], $has_bv_skin, $bv_bulk_upgrade);
208 + $stylesheets = array();
209 + foreach ($params['themes'] as $theme) {
210 + $stylesheets[] = $theme['stylesheet'];
211 + }
212 + if (!empty($stylesheets)) {
213 + $result['themes'] = $this->upgradeThemes($stylesheets, $has_bv_skin);
214 + }
219 215 }
220 216 return $result;
221 217 }
222 218
@@ -249,9 +245,9 @@
249 245 if (!empty($valid_updates)) {
250 246 if (class_exists('Language_Pack_Upgrader')) {
251 247 if ($has_bv_skin) {
252 248 require_once( "bv_upgrader_skin.php" );
253 - $skin = new WPRUpgraderSkin("upgrade_translations");
249 + $skin = new BVUpgraderSkin("upgrade_translations");
254 250 $this->skin = $skin;
255 251 } else {
256 252 $skin = new Language_Pack_Upgrader_Skin(array());
257 253 }
@@ -272,54 +268,15 @@
272 268 }
273 269
274 270 function upgradeCore($args) {
275 271 global $wp_filesystem, $wp_version;
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 - }
272 + $core = $this->settings->getTransient('update_core');
273 + $core_update_index = intval($args['coreupdateindex']);
274 + if (isset($core->updates) && !empty($core->updates)) {
275 + $to_update = $core->updates[$core_update_index];
307 276 } 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) {
319 277 return array('status' => "Error", "message" => "Updates not available");
320 278 }
321 -
322 279 $resp = array("Core_Upgrader", class_exists('Core_Upgrader'));
323 280 if (version_compare($wp_version, '3.1.9', '>')) {
324 281 $core = new Core_Upgrader();
325 282 $result = $core->upgrade($to_update);
@@ -328,8 +285,18 @@
328 285 } else {
329 286 return array('status' => 'Done');
330 287 }
331 288 } else {
289 + $resp = array("wp_update_core", function_exists('wp_update_core'));
290 + if (function_exists('wp_update_core')) {
291 + $result = wp_update_core($to_update);
292 + if (is_wp_error($result)) {
293 + return array('status' => "Error", "message" => $this->getError($result));
294 + } else {
295 + return array('status' => 'Done');
296 + }
297 + }
298 +
332 299 $resp = array("WP_Upgrader", class_exists('WP_Upgrader'));
333 300 if (class_exists('WP_Upgrader')) {
334 301 $upgrader = new WP_Upgrader();
335 302
@@ -367,9 +334,8 @@
367 334 }
368 335
369 336 $wp_filesystem->chmod($wp_dir.'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
370 337
371 - $this->safe_require_once(ABSPATH.'wp-admin/includes/update-core.php');
372 338 $result = update_core($working_dir, $wp_dir);
373 339
374 340 if (is_wp_error($result)) {
375 341 return array('status' => "Error", "message" => $this->getError($result));
@@ -378,349 +344,56 @@
378 344 }
379 345 }
380 346 }
381 347
382 - function bv_plugin_bulk_upgrade($upgrader, $_plugins) {
383 - global $wp_version;
384 - $plugins = array_keys($_plugins);
385 - $current = get_site_transient('update_plugins');
386 - $args = array();
387 - $defaults = array(
388 - 'clear_update_cache' => true,
389 - );
390 - $parsed_args = wp_parse_args($args, $defaults);
391 - $upgrader->init();
392 - $upgrader->bulk = true;
393 - $upgrader->upgrade_strings();
394 - add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4);
395 - $upgrader->skin->header();
396 - $res = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
397 - if (!$res) {
398 - $upgrader->skin->footer();
399 - return false;
400 - }
401 - $upgrader->skin->bulk_header();
402 - $maintenance = (is_multisite() && ! empty($plugins));
403 - foreach ($plugins as $plugin) {
404 - $maintenance = $maintenance || (is_plugin_active($plugin));
405 - }
406 - if ($maintenance) {
407 - $upgrader->maintenance_mode(true);
408 - }
409 - $results = array();
410 - $upgrader->update_count = count($plugins);
411 - $upgrader->update_current = 0;
412 - foreach($plugins as $plugin) {
413 - $upgrader->update_current++;
414 - $upgrader->skin->plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin, false, true);
415 - $upgrader->skin->plugin_active = is_plugin_active($plugin);
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 - }
468 - $results[$plugin] = $result;
469 - if (false === $result) {
470 - break;
471 - }
472 - }
473 - $upgrader->maintenance_mode(false);
474 - wp_clean_plugins_cache($parsed_args['clear_update_cache']);
475 - do_action(
476 - 'upgrader_process_complete',
477 - $upgrader,
478 - array(
479 - 'action' => 'update',
480 - 'type' => 'plugin',
481 - 'bulk' => true,
482 - 'plugins' => $plugins,
483 - )
484 - );
485 - $upgrader->skin->bulk_footer();
486 - $upgrader->skin->footer();
487 - remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'));
488 - $past_failure_emails = get_option('auto_plugin_theme_update_emails', array());
489 - foreach ($results as $plugin => $result) {
490 - if (!$result || is_wp_error($result) || !isset($past_failure_emails[$plugin])) {
491 - continue;
492 - }
493 - unset($past_failure_emails[$plugin]);
494 - }
495 - update_option('auto_plugin_theme_update_emails', $past_failure_emails);
496 - return $results;
497 - }
498 -
499 - function upgradePlugins($plugins, $has_bv_skin = false, $bv_bulk_upgrade = false) {
348 + function upgradePlugins($plugins, $has_bv_skin = false) {
500 349 $result = array();
501 - $_plugins = array();
502 - $plugins_by_name = array();
503 - foreach ($plugins as $plugin) {
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'];
516 - }
517 - if (empty(array_keys($_plugins))) {
518 - return $result;
519 - }
520 350 if (class_exists('Plugin_Upgrader')) {
521 351 if ($has_bv_skin) {
522 352 require_once( "bv_upgrader_skin.php" );
523 - $skin = new WPRUpgraderSkin("plugin_upgrade", $plugins_by_name);
353 + $skin = new BVUpgraderSkin("plugin_upgrade");
524 354 $this->skin = $skin;
525 355 } else {
526 356 $skin = new Bulk_Plugin_Upgrader_Skin();
527 357 }
528 358 $upgrader = new Plugin_Upgrader($skin);
529 -
530 - if ($bv_bulk_upgrade) {
531 - $result = $this->bv_plugin_bulk_upgrade($upgrader, $_plugins);
532 - } else {
533 - $result = $upgrader->bulk_upgrade(array_keys($_plugins));
534 - }
535 - if (!is_array($result)) {
536 - return array('status' => "Error", 'message' =>'result is not an array');
537 - }
538 - foreach (array_keys($_plugins) as $file) {
539 - if (!array_key_exists($file, $result)) {
359 + $result = $upgrader->bulk_upgrade($plugins);
360 + }
361 + foreach($plugins as $file) {
362 + $res = $result[$file];
363 + if (!$res || is_wp_error($res)) {
540 364 $result[$file] = array('status' => "Error");
541 365 } else {
542 - $res = $result[$file];
543 - if (!$res || is_wp_error($res)) {
544 - $result[$file] = array('status' => "Error");
545 - } else {
546 - $result[$file] = array('status' => "Done");
547 - }
366 + $result[$file] = array('status' => "Done");
548 367 }
549 - }
550 368 }
551 369 return $result;
552 370 }
553 371
554 - function bv_theme_bulk_upgrade($upgrader, $_themes) {
555 - global $wp_version;
556 - $themes = array_keys($_themes);
557 - $current = get_site_transient('update_themes');
558 - $args = array();
559 - $defaults = array(
560 - 'clear_update_cache' => true,
561 - );
562 - $parsed_args = wp_parse_args($args, $defaults);
563 - $upgrader->init();
564 - $upgrader->bulk = true;
565 - $upgrader->upgrade_strings();
566 - add_filter('upgrader_pre_install', array($upgrader, 'current_before'), 10, 2);
567 - add_filter('upgrader_post_install', array( $upgrader, 'current_after'), 10, 2);
568 - add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_theme'), 10, 4);
569 - $upgrader->skin->header();
570 - $res = $upgrader->fs_connect(array(WP_CONTENT_DIR));
571 - if (!$res) {
572 - $upgrader->skin->footer();
573 - return false;
574 - }
575 - $upgrader->skin->bulk_header();
576 - $maintenance = (is_multisite() && !empty($themes));
577 - foreach ($themes as $theme) {
578 - $maintenance = $maintenance || get_stylesheet() === $theme || get_template() === $theme;
579 - }
580 - if ($maintenance) {
581 - $upgrader->maintenance_mode(true);
582 - }
583 - $results = array();
584 - $upgrader->update_count = count($themes);
585 - $upgrader->update_current = 0;
586 - foreach ($themes as $theme) {
587 - $upgrader->update_current++;
588 - $upgrader->skin->theme_info = $upgrader->theme_info($theme);
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 - );
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 - }
640 - $results[$theme] = $result;
641 - if (false === $result) {
642 - break;
643 - }
644 - }
645 - $upgrader->maintenance_mode(false);
646 - wp_clean_themes_cache($parsed_args['clear_update_cache']);
647 - do_action(
648 - 'upgrader_process_complete',
649 - $upgrader,
650 - array(
651 - 'action' => 'update',
652 - 'type' => 'theme',
653 - 'bulk' => true,
654 - 'themes' => $themes,
655 - )
656 - );
657 - $upgrader->skin->bulk_footer();
658 - $upgrader->skin->footer();
659 - remove_filter('upgrader_pre_install', array($upgrader, 'current_before'));
660 - remove_filter('upgrader_post_install', array($upgrader, 'current_after'));
661 - remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_theme'));
662 - $past_failure_emails = get_option('auto_plugin_theme_update_emails', array());
663 - foreach ($results as $theme => $result) {
664 - if (!$result || is_wp_error($result) || !isset($past_failure_emails[$theme])) {
665 - continue;
666 - }
667 - unset($past_failure_emails[$theme]);
668 - }
669 - update_option('auto_plugin_theme_update_emails', $past_failure_emails);
670 - return $results;
671 - }
672 -
673 - function upgradeThemes($themes, $has_bv_skin = false, $bv_bulk_upgrade = false) {
372 + function upgradeThemes($themes, $has_bv_skin = false) {
674 373 $result = array();
675 - $_themes = array();
676 - foreach ($themes as $theme) {
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 - }
686 - }
687 - if (empty(array_keys($_themes))) {
688 - return $result;
689 - }
690 374 if (class_exists('Theme_Upgrader')) {
691 375 if ($has_bv_skin) {
692 376 require_once( "bv_upgrader_skin.php" );
693 - $skin = new WPRUpgraderSkin("theme_upgrade");
377 + $skin = new BVUpgraderSkin("theme_upgrade");
694 378 $this->skin = $skin;
695 379 } else {
696 380 $skin = new Bulk_Theme_Upgrader_Skin();
697 381 }
698 382 $upgrader = new Theme_Upgrader($skin);
699 - if ($bv_bulk_upgrade) {
700 - $result = $this->bv_theme_bulk_upgrade($upgrader, $_themes);
383 + $result = $upgrader->bulk_upgrade($themes);
384 + }
385 + foreach($themes as $stylesheet) {
386 + $res = $result[$stylesheet];
387 + if (!$res || is_wp_error($res)) {
388 + $result[$stylesheet] = array('status' => "Error");
701 389 } else {
702 - $result = $upgrader->bulk_upgrade(array_keys($_themes));
390 + $result[$stylesheet] = array('status' => "Done");
703 391 }
704 - if (!is_array($result)) {
705 - return array('status' => "Error", 'message' =>'result is not an array');
706 - }
707 - foreach (array_keys($_themes) as $stylesheet) {
708 - if (!array_key_exists($stylesheet, $result)) {
709 - $result[$stylesheet] = array('status' => "Error");
710 - } else {
711 - $res = $result[$stylesheet];
712 - if (!$res || is_wp_error($res)) {
713 - $result[$stylesheet] = array('status' => "Error");
714 - } else {
715 - $result[$stylesheet] = array('status' => "Done");
716 - }
717 - }
718 - }
719 392 }
720 393 return $result;
721 394 }
722 -
395 +
723 396 function install($params, $has_bv_skin = false) {
724 397 $result = array();
725 398 if (isset($params['plugins'])) {
726 399 foreach ($params['plugins'] as $plugin) {
@@ -726,9 +399,9 @@
726 399 foreach ($params['plugins'] as $plugin) {
727 400 if (!array_key_exists('plugins', $result))
728 401 $result["plugins"] = array();
729 402 $plugin['dest'] = WP_PLUGIN_DIR;
730 - $res = $this->installPackage("plugin", $plugin, $has_bv_skin);
403 + $res = $this->installPackage($plugin, $has_bv_skin);
731 404 $pluginName = $plugin['package'];
732 405 $result["plugins"][$pluginName] = $res;
733 406 }
734 407 }
@@ -736,9 +409,9 @@
736 409 foreach ($params['themes'] as $theme) {
737 410 if (!array_key_exists('themes', $result))
738 411 $result["themes"] = array();
739 412 $theme['dest'] = WP_CONTENT_DIR.'/themes';
740 - $res = $this->installPackage("theme", $theme, $has_bv_skin);
413 + $res = $this->installPackage($theme, $has_bv_skin);
741 414 $themeName = $theme['package'];
742 415 $result["themes"][$themeName] = $res;
743 416 }
744 417 }
@@ -744,9 +417,9 @@
744 417 }
745 418 return $result;
746 419 }
747 420
748 - function installPackage($type, $params, $has_bv_skin = false) {
421 + function installPackage($params, $has_bv_skin = false) {
749 422 global $wp_filesystem;
750 423
751 424 if (!isset($params['package']) || empty($params['package'])) {
752 425 return array('status' => "Error", 'message' => "No package is sent");
@@ -751,35 +424,24 @@
751 424 if (!isset($params['package']) || empty($params['package'])) {
752 425 return array('status' => "Error", 'message' => "No package is sent");
753 426 }
754 427 $valid_domain_regex = "/^(http|https):\/\/[\-\w]*\.(blogvault\.net|w\.org|wp\.org|wordpress\.org)\//";
755 - if (WPRHelper::safePregMatch($valid_domain_regex, $params['package']) !== 1) {
428 + if (preg_match($valid_domain_regex, $params['package']) !== 1) {
756 429 return array('status' => "Error", 'message' => "Invalid package domain");
757 430 }
758 431 if ($has_bv_skin) {
759 432 require_once( "bv_upgrader_skin.php" );
760 - $skin = new WPRUpgraderSkin("installer", array(), $params['package']);
433 + $skin = new BVUpgraderSkin("installer", $params['package']);
761 434 $this->skin = $skin;
762 435 } else {
763 436 $skin = new WP_Upgrader_Skin();
764 437 }
765 - if ("plugin" === $type) {
766 - $upgrader = new Plugin_Upgrader($skin);
767 - } elseif ("theme" === $type) {
768 - $upgrader = new Theme_Upgrader($skin);
769 - } else {
770 - $upgrader = new WP_Upgrader($skin);
771 - }
438 + $upgrader = new WP_Upgrader($skin);
772 439 $upgrader->init();
773 440 $destination = $params['dest'];
774 441 $clear_destination = isset($params['cleardest']) ? $params['cleardest'] : false;
775 442 $package_url = $params['package'];
776 - $is_parent_theme_install_disabled = isset($params['is_parent_theme_install_disabled']) ? $params['is_parent_theme_install_disabled'] : false;
777 443 $key = basename($package_url);
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 - }
782 444 $res = $upgrader->run(
783 445 array(
784 446 'package' => $package_url,
785 447 'destination' => $destination,
@@ -784,18 +446,11 @@
784 446 'package' => $package_url,
785 447 'destination' => $destination,
786 448 'clear_destination' => $clear_destination,
787 449 'clear_working' => true,
788 - 'hook_extra' => array(
789 - "type" => $type,
790 - "action" => "install"
791 - ),
450 + 'hook_extra' => array(),
792 451 )
793 452 );
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 - }
798 453 if (is_wp_error($res)) {
799 454 $res = array('status' => "Error", 'message' => $this->getError($res));
800 455 } else {
801 456 $res = array( 'status' => "Done");
@@ -810,17 +465,9 @@
810 465 function getPremiumUpgradesInfo() {
811 466 return apply_filters( 'mwp_premium_perform_update', array() );
812 467 }
813 468
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 -
469 + function autoLogin($username, $isHttps) {
823 470 $user = get_user_by('login', $username);
824 471 if ($user != FALSE) {
825 472 wp_set_current_user( $user->ID );
826 473 if ($isHttps) {
@@ -835,174 +482,12 @@
835 482 exit;
836 483 }
837 484 }
838 485
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 -
1001 486 function upgrade_db(){
1002 487 if (function_exists('wp_upgrade')) {
1003 488 wp_upgrade();
1004 - return "Done";
489 + return "DONE";
1005 490 } else {
1006 491 return "NOUPGRADERFUNCTION";
1007 492 }
1008 493 }
@@ -1022,28 +507,10 @@
1022 507 $resp = array("adduser" => $this->addUser($params['args']));
1023 508 break;
1024 509 case "upgrde":
1025 510 $has_bv_skin = array_key_exists('bvskin', $params);
1026 - $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $params['args']);
1027 - $resp = array("upgrades" => $this->upgrade($params['args'], $has_bv_skin, $bv_bulk_upgrade));
511 + $resp = array("upgrades" => $this->upgrade($params['args'], $has_bv_skin));
1028 512 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;
1046 513 case "edt":
1047 514 $resp = array("edit" => $this->edit($params['args']));
1048 515 break;
1049 516 case "instl":
@@ -1062,31 +529,13 @@
1062 529 case "atolgn":
1063 530 $isHttps = false;
1064 531 if (array_key_exists('https', $params))
1065 532 $isHttps = true;
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));
533 + $resp = array("autologin" => $this->autoLogin($params['username'], $isHttps));
1068 534 break;
1069 535 case "updatedb":
1070 536 $resp = array("status" => $this->upgrade_db());
1071 537 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;
1089 538 default:
1090 539 $resp = false;
1091 540 }
1092 541 if ($this->skin && is_array($resp)) {
@@ -1094,5 +543,5 @@
1094 543 }
1095 544 return $resp;
1096 545 }
1097 546 }
1098 -endif;
547 +endif;