PluginProbe
The WP Remote WordPress Plugin / 6.36
The WP Remote WordPress Plugin v6.36
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / callback / wings / manage.php

manage.php in The WP Remote WordPress Plugin 6.36, at callback/wings/manage.php

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