PluginProbe
ManageWP Worker / 3.9.24
ManageWP Worker v3.9.24
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.24, at installer.class.php

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