PluginProbe
ManageWP Worker / 4.9.25
ManageWP Worker v4.9.25
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MMB / Installer.php

Installer.php in ManageWP Worker 4.9.25, at src/MMB/Installer.php

903 lines 31.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*************************************************************
4 * installer.class.php
5 * Upgrade WordPress
6 * Copyright (c) 2011 Prelovac Media
7 * www.prelovac.com
8 **************************************************************/
9 class MMB_Installer extends MMB_Core
10 {
11 public function __construct()
12 {
13 @set_time_limit(600);
14 parent::__construct();
15 @include_once ABSPATH.'wp-admin/includes/file.php';
16 @include_once ABSPATH.'wp-admin/includes/plugin.php';
17 @include_once ABSPATH.'wp-admin/includes/theme.php';
18 @include_once ABSPATH.'wp-admin/includes/misc.php';
19 @include_once ABSPATH.'wp-admin/includes/template.php';
20 @include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
21
22 global $wp_filesystem;
23
24 if (!$this->check_if_pantheon() && !$wp_filesystem) {
25 WP_Filesystem();
26 }
27 }
28
29 public function mmb_maintenance_mode($enable = false, $maintenance_message = '')
30 {
31 global $wp_filesystem;
32
33 $maintenance_message .= '<?php $upgrading = '.time().'; ?>';
34
35 $file = $wp_filesystem->abspath().'.maintenance';
36 if ($enable) {
37 $wp_filesystem->delete($file);
38 $wp_filesystem->put_contents($file, $maintenance_message, FS_CHMOD_FILE);
39 } else {
40 $wp_filesystem->delete($file);
41 }
42 }
43
44 public function install_remote_file($params)
45 {
46 global $wp_filesystem;
47 extract($params);
48 $network_activate = isset($params['network_activate']) ? $params['network_activate'] : false;
49
50 if (!isset($package) || empty($package)) {
51 return array(
52 'error' => '<p>No files received. Internal error.</p>',
53 );
54 }
55
56 if (!$this->is_server_writable()) {
57 return array(
58 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide/faq/my-pluginsthemes-fail-to-update-or-i-receive-a-yellow-ftp-warning">add FTP details</a>',
59 );
60 }
61
62 if (defined('WP_INSTALLING') && file_exists(ABSPATH.'.maintenance')) {
63 return array(
64 'error' => '<p>Site under maintanace.</p>',
65 );
66 }
67
68 if (!class_exists('WP_Upgrader')) {
69 include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
70 }
71
72 /** @handled class */
73 $upgrader = new WP_Upgrader(mwp_container()->getUpdaterSkin());
74 $upgrader->init();
75 $destination = $type == 'themes' ? WP_CONTENT_DIR.'/themes' : WP_PLUGIN_DIR;
76 $clear_destination = isset($clear_destination) ? $clear_destination : false;
77
78 foreach ($package as $package_url) {
79 $key = basename($package_url);
80 $install_info[$key] = @$upgrader->run(
81 array(
82 'package' => $package_url,
83 'destination' => $destination,
84 'clear_destination' => $clear_destination, //Do not overwrite files.
85 'clear_working' => true,
86 'hook_extra' => array(),
87 )
88 );
89 }
90
91 if (defined('WP_ADMIN') && WP_ADMIN) {
92 global $wp_current_filter;
93 $wp_current_filter[] = 'load-update-core.php';
94
95 if (function_exists('wp_clean_update_cache')) {
96 /** @handled function */
97 wp_clean_update_cache();
98 }
99
100 /** @handled function */
101 wp_update_plugins();
102
103 array_pop($wp_current_filter);
104
105 /** @handled function */
106 set_current_screen();
107 do_action('load-update-core.php');
108
109 /** @handled function */
110 wp_version_check();
111
112 /** @handled function */
113 wp_version_check(array(), true);
114 }
115
116 $wrongFileType = false;
117 if ($type == 'plugins') {
118 $wrongFileType = true;
119 include_once ABSPATH.'wp-admin/includes/plugin.php';
120 $all_plugins = get_plugins();
121 foreach ($all_plugins as $plugin_slug => $plugin) {
122 $plugin_dir = preg_split('/\//', $plugin_slug);
123 foreach ($install_info as $key => $install) {
124 if (!$install || is_wp_error($install)) {
125 continue;
126 }
127 if ($install['destination_name'] == $plugin_dir[0]) {
128 $wrongFileType = false;
129 if ($activate) {
130 $install_info[$key]['activated'] = activate_plugin($plugin_slug, '', $network_activate);
131 }
132
133 $install_info[$key]['basename'] = $plugin_slug;
134 $install_info[$key]['full_name'] = $plugin['Name'];
135 $install_info[$key]['version'] = $plugin['Version'];
136 }
137 }
138 }
139 }
140
141 if ($type == 'themes') {
142 $wrongFileType = true;
143 if (count($install_info) == 1) {
144 global $wp_themes;
145 include_once ABSPATH.'wp-includes/theme.php';
146
147 $wp_themes = null;
148 unset($wp_themes); //prevent theme data caching
149 if (function_exists('wp_get_theme')) {
150 foreach ($install_info as $key => $install) {
151 if (!$install || is_wp_error($install)) {
152 continue;
153 }
154
155 $theme = wp_get_theme($install['destination_name']);
156 if ($theme->errors() !== false) {
157 $install_info[$key] = $theme->errors();
158 continue;
159 }
160
161 $wrongFileType = false;
162 if ($activate) {
163 $install_info[$key]['activated'] = switch_theme($theme->Template, $theme->Stylesheet);
164 }
165
166 $install_info[$key]['full_name'] = $theme->name;
167 $install_info[$key]['version'] = $theme->version;
168 }
169 } else {
170 $all_themes = get_themes();
171 foreach ($all_themes as $theme_name => $theme_data) {
172 foreach ($install_info as $key => $install) {
173 if (!$install || is_wp_error($install)) {
174 continue;
175 }
176
177 if ($theme_data['Template'] == $install['destination_name'] || $theme_data['Stylesheet'] == $install['destination_name']) {
178 $wrongFileType = false;
179 if ($activate) {
180 $install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']);
181 }
182 $install_info[$key]['full_name'] = $theme_data->name;
183 $install_info[$key]['version'] = $theme_data->version;
184 }
185 }
186 }
187 }
188 }
189 }
190
191 // Can generate "E_NOTICE: ob_clean(): failed to delete buffer. No buffer to delete."
192 @ob_clean();
193 $this->mmb_maintenance_mode(false);
194
195 if (mwp_container()->getRequestStack()->getMasterRequest()->getProtocol() >= 1) {
196 // WP_Error won't get JSON encoded, so unwrap the error here.
197 foreach ($install_info as $key => $value) {
198 if ($value instanceof WP_Error) {
199 $install_info[$key] = array(
200 'error' => $value->get_error_message(),
201 'code' => $value->get_error_code(),
202 );
203 } elseif ($wrongFileType) {
204 $otherType = $type === 'themes' ? 'plugins' : $type;
205 $install_info[$key] = array(
206 'error' => 'You can\'t install '.$type.' on '.$otherType.' page.',
207 'code' => 'wrong_type_of_file',
208 );
209 }
210 }
211 }
212
213 return $install_info;
214 }
215
216 private function ithemes_updater_compatiblity()
217 {
218 // Check for the iThemes updater class
219 if (empty($GLOBALS['ithemes_updater_path']) ||
220 !file_exists($GLOBALS['ithemes_updater_path'].'/settings.php')
221 ) {
222 return;
223 }
224
225 // Include iThemes updater
226 require_once $GLOBALS['ithemes_updater_path'].'/settings.php';
227
228 // Check if the updater is instantiated
229 if (empty($GLOBALS['ithemes-updater-settings'])) {
230 return;
231 }
232
233 // Update the download link
234 $GLOBALS['ithemes-updater-settings']->flush('forced');
235 }
236
237 public function do_upgrade($params = null)
238 {
239 if ($params == null || empty($params)) {
240 return array(
241 'error' => 'No upgrades passed.',
242 );
243 }
244
245 if (!$this->is_server_writable()) {
246 return array(
247 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide/faq/my-pluginsthemes-fail-to-update-or-i-receive-a-yellow-ftp-warning">add FTP details</a>',
248 );
249 }
250
251 $params = isset($params['upgrades_all']) ? $params['upgrades_all'] : $params;
252
253 $core_upgrade = isset($params['wp_upgrade']) ? $params['wp_upgrade'] : array();
254 $upgrade_plugins = isset($params['upgrade_plugins']) ? $params['upgrade_plugins'] : array();
255 $upgrade_themes = isset($params['upgrade_themes']) ? $params['upgrade_themes'] : array();
256 $upgrade_translations = isset($params['upgrade_translations']) ? $params['upgrade_translations'] : false;
257
258 $upgrades = array();
259 $premium_upgrades = array();
260 if (!empty($core_upgrade)) {
261 $upgrades['core'] = $this->upgrade_core($core_upgrade);
262 }
263
264 if (!empty($upgrade_plugins)) {
265 $plugin_files = array();
266 $this->ithemes_updater_compatiblity();
267 foreach ($upgrade_plugins as $plugin) {
268 if (isset($plugin['envatoPlugin']) && $plugin['envatoPlugin'] === true) {
269 $upgrades['plugins'] = $this->upgrade_envato_component($plugin);
270 continue;
271 }
272
273 if (isset($plugin['file'])) {
274 $plugin_files[$plugin['file']] = $plugin['old_version'];
275 } else {
276 $premium_upgrades[md5($plugin['name'])] = $plugin;
277 }
278 }
279 if (!empty($plugin_files)) {
280 $upgrades['plugins'] = $this->upgrade_plugins($plugin_files);
281 }
282 $this->ithemes_updater_compatiblity();
283 }
284
285 if (!empty($upgrade_themes)) {
286 $theme_temps = array();
287 foreach ($upgrade_themes as $theme) {
288 if (isset($theme['envatoTheme']) && $theme['envatoTheme'] === true) {
289 $upgrades['themes'] = $this->upgrade_envato_component($theme);
290 continue;
291 }
292
293 if (isset($theme['theme_tmp'])) {
294 $theme_temps[] = $theme['theme_tmp'];
295 } else {
296 $premium_upgrades[md5($theme['name'])] = $theme;
297 }
298 }
299
300 if (!empty($theme_temps)) {
301 $upgrades['themes'] = $this->upgrade_themes($theme_temps);
302 }
303 }
304
305 if (!empty($upgrade_translations)) {
306 $upgrades['translations'] = $this->upgrade_translations();
307 }
308
309 @ob_clean();
310 $this->mmb_maintenance_mode(false);
311
312 return $upgrades;
313 }
314
315 /**
316 * @param array $component
317 *
318 * @return array
319 */
320 private function upgrade_envato_component(array $component)
321 {
322 $result = $this->install_remote_file($component);
323 $return = array();
324
325 if (empty($result)) {
326 return array(
327 'error' => 'Upgrade failed.',
328 );
329 }
330
331 foreach ($result as $component_slug => $component_info) {
332 if (!$component_info || is_wp_error($component_info)) {
333 $return[$component_slug] = $this->mmb_get_error($component_info);
334 continue;
335 }
336
337 $return[$component_info['destination_name']] = 1;
338 }
339
340 return array(
341 'upgraded' => $return,
342 );
343 }
344
345 /**
346 * Upgrades WordPress locally
347 */
348 public function upgrade_core($current)
349 {
350 ob_start();
351
352 if (file_exists(ABSPATH.'/wp-admin/includes/update.php')) {
353 include_once ABSPATH.'/wp-admin/includes/update.php';
354 }
355
356 $current_update = false;
357 ob_end_flush();
358 ob_end_clean();
359 $core = $this->mmb_get_transient('update_core');
360
361 if (isset($core->updates) && !empty($core->updates)) {
362 $updates = $core->updates[0];
363 $updated = $core->updates[0];
364 if (!isset($updated->response) || $updated->response == 'latest') {
365 return array(
366 'upgraded' => ' updated',
367 );
368 }
369
370 if ($updated->response == "development" && $current['response'] == "upgrade") {
371 return array(
372 'error' => '<font color="#900">Unexpected error. Please upgrade manually.</font>',
373 );
374 } else {
375 if ($updated->response == $current['response'] || ($updated->response == "upgrade" && $current['response'] == "development")) {
376 if ($updated->locale != $current['locale']) {
377 foreach ($updates as $update) {
378 if ($update->locale == $current['locale']) {
379 $current_update = $update;
380 break;
381 }
382 }
383 if ($current_update == false) {
384 return array(
385 'error' => ' Localization mismatch. Try again.',
386 );
387 }
388 } else {
389 $current_update = $updated;
390 }
391 } else {
392 return array(
393 'error' => ' Transient mismatch. Try again.',
394 );
395 }
396 }
397 } else {
398 return array(
399 'error' => ' Refresh transient failed. Try again.',
400 );
401 }
402 if ($current_update != false) {
403 global $wp_filesystem, $wp_version;
404
405 if (version_compare($wp_version, '3.1.9', '>')) {
406 if (!class_exists('Core_Upgrader')) {
407 include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
408 }
409
410 /** @handled class */
411 $core = new Core_Upgrader(mwp_container()->getUpdaterSkin());
412 $result = $core->upgrade($current_update);
413 $this->mmb_maintenance_mode(false);
414 if (is_wp_error($result)) {
415 return array(
416 'error' => $this->mmb_get_error($result),
417 );
418 } else {
419 return array(
420 'upgraded' => ' updated',
421 );
422 }
423 } else {
424 if (!class_exists('WP_Upgrader')) {
425 include_once ABSPATH.'wp-admin/includes/update.php';
426 if (function_exists('wp_update_core')) {
427 $result = wp_update_core($current_update);
428 if (is_wp_error($result)) {
429 return array(
430 'error' => $this->mmb_get_error($result),
431 );
432 } else {
433 return array(
434 'upgraded' => ' updated',
435 );
436 }
437 }
438 }
439
440 if (class_exists('WP_Upgrader')) {
441 /** @handled class */
442 $upgrader_skin = new WP_Upgrader_Skin();
443 $upgrader_skin->done_header = true;
444
445 /** @handled class */
446 $upgrader = new WP_Upgrader($upgrader_skin);
447
448 // Is an update available?
449 if (!isset($current_update->response) || $current_update->response == 'latest') {
450 return array(
451 'upgraded' => ' updated',
452 );
453 }
454
455 $res = $upgrader->fs_connect(
456 array(
457 ABSPATH,
458 WP_CONTENT_DIR,
459 )
460 );
461 if (is_wp_error($res)) {
462 return array(
463 'error' => $this->mmb_get_error($res),
464 );
465 }
466
467 $wp_dir = trailingslashit($wp_filesystem->abspath());
468
469 $core_package = false;
470 if (isset($current_update->package) && !empty($current_update->package)) {
471 $core_package = $current_update->package;
472 } elseif (isset($current_update->packages->full) && !empty($current_update->packages->full)) {
473 $core_package = $current_update->packages->full;
474 }
475
476 $download = $upgrader->download_package($core_package);
477 if (is_wp_error($download)) {
478 return array(
479 'error' => $this->mmb_get_error($download),
480 );
481 }
482
483 $working_dir = $upgrader->unpack_package($download);
484 if (is_wp_error($working_dir)) {
485 return array(
486 'error' => $this->mmb_get_error($working_dir),
487 );
488 }
489
490 if (!$wp_filesystem->copy($working_dir.'/wordpress/wp-admin/includes/update-core.php', $wp_dir.'wp-admin/includes/update-core.php', true)) {
491 $wp_filesystem->delete($working_dir, true);
492
493 return array(
494 'error' => 'Unable to move update files.',
495 );
496 }
497
498 $wp_filesystem->chmod($wp_dir.'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
499
500 require ABSPATH.'wp-admin/includes/update-core.php';
501
502 $update_core = update_core($working_dir, $wp_dir);
503 ob_end_clean();
504
505 $this->mmb_maintenance_mode(false);
506 if (is_wp_error($update_core)) {
507 return array(
508 'error' => $this->mmb_get_error($update_core),
509 );
510 }
511 ob_end_flush();
512
513 return array(
514 'upgraded' => 'updated',
515 );
516 } else {
517 return array(
518 'error' => 'failed',
519 );
520 }
521 }
522 } else {
523 return array(
524 'error' => 'failed',
525 );
526 }
527 }
528
529 public function upgrade_plugins($plugins = false)
530 {
531 if (!$plugins || empty($plugins)) {
532 return array(
533 'error' => 'No plugin files for upgrade.',
534 );
535 }
536
537 if (!function_exists('wp_update_plugins')) {
538 include_once ABSPATH.'wp-includes/update.php';
539 }
540
541 $return = array();
542
543 if (class_exists('Plugin_Upgrader')) {
544 /** @handled class */
545 $upgrader = new Plugin_Upgrader(mwp_container()->getUpdaterSkin());
546 $result = $upgrader->bulk_upgrade(array_keys($plugins));
547
548 if (!empty($result)) {
549 foreach ($result as $plugin_slug => $plugin_info) {
550 if (!$plugin_info || is_wp_error($plugin_info)) {
551 $return[$plugin_slug] = $this->mmb_get_error($plugin_info);
552 continue;
553 }
554
555 $return[$plugin_slug] = 1;
556 }
557
558 return array(
559 'upgraded' => $return,
560 'additional_updates' => $this->get_additional_plugin_updates($result),
561 );
562 } else {
563 return array(
564 'error' => 'Upgrade failed.',
565 );
566 }
567 } else {
568 return array(
569 'error' => 'WordPress update required first.',
570 );
571 }
572 }
573
574 private function get_additional_plugin_updates($plugin_upgrades)
575 {
576 if (empty($plugin_upgrades)) {
577 return array();
578 }
579
580 $additional_updates = array();
581
582 if (array_key_exists('woocommerce/woocommerce.php', $plugin_upgrades) && is_plugin_active('woocommerce/woocommerce.php') && $this->has_woocommerce_db_update()) {
583 $additional_updates['woocommerce/woocommerce.php'] = 1;
584 }
585
586 return $additional_updates;
587 }
588
589 private function has_woocommerce_db_update()
590 {
591 $current_db_version = get_option('woocommerce_db_version', null);
592 $current_wc_version = get_option('woocommerce_version');
593 if (version_compare($current_wc_version, '3.0.0', '<')) {
594 return true;
595 }
596
597 $latestUpdate = $this->get_wc_db_latest_update();
598
599 return !is_null($current_db_version) && !is_null($latestUpdate) &&
600 version_compare($current_db_version, $latestUpdate, '<');
601 }
602
603 private function get_wc_db_latest_update()
604 {
605 $regexp = "{'(\d+\.)(\d+\.)(\d+)'}"; // version in single quote '1.0.0', '2.1.3', '3.1.22' etc
606 $fileName = WP_PLUGIN_DIR.'/woocommerce/includes/class-wc-install.php';
607
608 if (file_exists($fileName)) {
609 $fileContent = file_get_contents($fileName);
610 preg_match_all($regexp, $fileContent, $matches);
611
612 if (!empty($matches[0])) {
613 $latestUpdate = trim(end($matches[0]), "'");
614 return $latestUpdate;
615 }
616 }
617 return null;
618 }
619
620 public function upgrade_themes($themes = false)
621 {
622 if (!$themes || empty($themes)) {
623 return array(
624 'error' => 'No theme files for upgrade.',
625 );
626 }
627
628 if (!function_exists('wp_update_themes')) {
629 include_once ABSPATH.'wp-includes/update.php';
630 }
631
632 if (class_exists('Theme_Upgrader')) {
633 /** @handled class */
634 $upgrader = new Theme_Upgrader(mwp_container()->getUpdaterSkin());
635 $result = $upgrader->bulk_upgrade($themes);
636
637 $return = array();
638 if (!empty($result)) {
639 foreach ($result as $theme_tmp => $theme_info) {
640 if (is_wp_error($theme_info) || empty($theme_info)) {
641 $return[$theme_tmp] = $this->mmb_get_error($theme_info);
642 continue;
643 }
644
645 $return[$theme_tmp] = 1;
646 }
647
648 return array(
649 'upgraded' => $return,
650 );
651 } else {
652 return array(
653 'error' => 'Upgrade failed.',
654 );
655 }
656 } else {
657 return array(
658 'error' => 'WordPress update required first',
659 );
660 }
661 }
662
663 public function upgrade_translations()
664 {
665 include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
666
667 if (class_exists('Language_Pack_Upgrader')) {
668 /** @handled class */
669 $upgrader = new Language_Pack_Upgrader(mwp_container()->getUpdaterSkin());
670 $result = $upgrader->bulk_upgrade();
671
672 if (!empty($result)) {
673 $return = 1;
674
675 if (is_array($result)) {
676 foreach ($result as $translate_tmp => $translate_info) {
677 if (is_wp_error($translate_info) || empty($translate_info)) {
678 $return = $this->mmb_get_error($translate_info);
679 break;
680 }
681 }
682 }
683
684 return array('upgraded' => $return);
685 } else {
686 return array(
687 'error' => 'Upgrade failed.',
688 );
689 }
690 } else {
691 return array(
692 'error' => 'WordPress update required first',
693 );
694 }
695 }
696
697 public function get_upgradable_plugins()
698 {
699 $current = $this->mmb_get_transient('update_plugins');
700
701 $upgradable_plugins = array();
702 if (!empty($current->response)) {
703 if (!function_exists('get_plugin_data')) {
704 include_once ABSPATH.'wp-admin/includes/plugin.php';
705 }
706 foreach ($current->response as $plugin_path => $plugin_data) {
707 $data = get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin_path, false, false);
708
709 if (strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
710 $current->response[$plugin_path]->name = $data['Name'];
711 $current->response[$plugin_path]->old_version = $data['Version'];
712 $current->response[$plugin_path]->file = $plugin_path;
713 unset($current->response[$plugin_path]->upgrade_notice);
714 $upgradable_plugins[] = $current->response[$plugin_path];
715 }
716 }
717
718 return $upgradable_plugins;
719 } else {
720 return array();
721 }
722 }
723
724 public function get_upgradable_themes()
725 {
726 if (function_exists('wp_get_themes')) {
727 $all_themes = wp_get_themes();
728 $upgrade_themes = array();
729
730 $current = $this->mmb_get_transient('update_themes');
731
732 if (empty($current->response)) {
733 return $upgrade_themes;
734 }
735
736 foreach ((array)$all_themes as $theme_template => $theme_data) {
737 foreach ($current->response as $current_themes => $theme) {
738 if ($theme_data->Stylesheet !== $current_themes) {
739 continue;
740 }
741
742 if (strlen($theme_data->Name) === 0 || strlen($theme_data->Version) === 0) {
743 continue;
744 }
745
746 $current->response[$current_themes]['name'] = $theme_data->Name;
747 $current->response[$current_themes]['old_version'] = $theme_data->Version;
748 $current->response[$current_themes]['theme_tmp'] = $theme_data->Stylesheet;
749
750 $upgrade_themes[] = $current->response[$current_themes];
751 }
752 }
753 } else {
754 $all_themes = get_themes();
755
756 $upgrade_themes = array();
757
758 $current = $this->mmb_get_transient('update_themes');
759 if (!empty($current->response)) {
760 foreach ((array)$all_themes as $theme_template => $theme_data) {
761 if (isset($theme_data['Parent Theme']) && !empty($theme_data['Parent Theme'])) {
762 continue;
763 }
764
765 if (isset($theme_data['Name']) && in_array($theme_data['Name'], $filter)) {
766 continue;
767 }
768
769 foreach ($current->response as $current_themes => $theme) {
770 if ($theme_data['Template'] == $current_themes) {
771 if (strlen($theme_data['Name']) > 0 && strlen($theme_data['Version']) > 0) {
772 $current->response[$current_themes]['name'] = $theme_data['Name'];
773 $current->response[$current_themes]['old_version'] = $theme_data['Version'];
774 $current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
775 $upgrade_themes[] = $current->response[$current_themes];
776 }
777 }
778 }
779 }
780 }
781 }
782
783 return $upgrade_themes;
784 }
785
786 public function get_upgradable_translations()
787 {
788 $updates = array(
789 'core' => array(),
790 'plugins' => array(),
791 'themes' => array(),
792 );
793
794 $transients = array('update_core' => 'core', 'update_plugins' => 'plugins', 'update_themes' => 'themes');
795
796 foreach ($transients as $transient => $type) {
797 $transient = get_site_transient($transient);
798
799 if (empty($transient->translations)) {
800 continue;
801 }
802
803 foreach ($transient->translations as $translation) {
804 $updates[$type][] = (object)$translation;
805 }
806 }
807
808 return $updates;
809 }
810
811 public function edit($args)
812 {
813 extract($args);
814 $return = array();
815 if ($type == 'plugins') {
816 $return['plugins'] = $this->edit_plugins($args);
817 } elseif ($type == 'themes') {
818 $return['themes'] = $this->edit_themes($args);
819 }
820
821 return $return;
822 }
823
824 public function edit_plugins($args)
825 {
826 extract($args);
827 $return = array();
828 foreach ($items as $item) {
829 switch ($items_edit_action) {
830 case 'activate':
831 $result = activate_plugin($item['path'], '', $item['networkWide']);
832 break;
833 case 'deactivate':
834 $result = deactivate_plugins(
835 array(
836 $item['path'],
837 ),
838 false,
839 $item['networkWide']
840 );
841 break;
842 case 'delete':
843 $result = delete_plugins(
844 array(
845 $item['path'],
846 )
847 );
848 break;
849 default:
850 break;
851 }
852
853 if (is_wp_error($result)) {
854 $result = array(
855 'error' => $result->get_error_message(),
856 );
857 } elseif ($result === false) {
858 $result = array(
859 'error' => "Failed to perform action.",
860 );
861 } else {
862 $result = "OK";
863 }
864 $return[$item['name']] = $result;
865 }
866
867 return $return;
868 }
869
870 public function edit_themes($args)
871 {
872 extract($args);
873 $return = array();
874 foreach ($items as $item) {
875 switch ($items_edit_action) {
876 case 'activate':
877 switch_theme($item['path'], $item['stylesheet']);
878 break;
879 case 'delete':
880 $result = delete_theme($item['stylesheet']);
881 break;
882 default:
883 break;
884 }
885
886 if (is_wp_error($result)) {
887 $result = array(
888 'error' => $result->get_error_message(),
889 );
890 } elseif ($result === false) {
891 $result = array(
892 'error' => "Failed to perform action.",
893 );
894 } else {
895 $result = "OK";
896 }
897 $return[$item['name']] = $result;
898 }
899
900 return $return;
901 }
902 }
903