PluginProbe
ManageWP Worker / 3.9.21
ManageWP Worker v3.9.21
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 / installer.class.php

installer.class.php in ManageWP Worker 3.9.21, at installer.class.php

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