PluginProbe
InfiniteWP Client / trunk
InfiniteWP Client vtrunk
1.13.10 1.13.7 trunk 0.1.4 0.1.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.11.0 1.11.1 1.12.1 1.12.3 All 92 releases
iwp-client / installer.class.php

installer.class.php in InfiniteWP Client trunk, at installer.class.php

1,341 lines 55.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /************************************************************
3 * This plugin was modified by Revmakx *
4 * Copyright (c) 2012 Revmakx *
5 * www.revmakx.com *
6 * *
7 ************************************************************/
8 /*************************************************************
9 *
10 * installer.class.php
11 *
12 * Upgrade WordPress
13 *
14 *
15 * Copyright (c) 2011 Prelovac Media
16 * www.prelovac.com
17 **************************************************************/
18 if ( ! defined('ABSPATH') )
19 die();
20 class IWP_MMB_Installer extends IWP_MMB_Core
21 {
22 protected $upgrade_error_keys;
23 protected $upgrade_wp_flow_keys;
24 protected $upgrade_success_keys;
25 function __construct()
26 {
27 @set_time_limit(600);
28 parent::__construct();
29 @include_once(ABSPATH . 'wp-admin/includes/file.php');
30 @include_once(ABSPATH . 'wp-admin/includes/plugin.php');
31 @include_once(ABSPATH . 'wp-includes/plugin.php');
32 @include_once(ABSPATH . 'wp-admin/includes/theme.php');
33 @include_once(ABSPATH . 'wp-admin/includes/misc.php');
34 @include_once(ABSPATH . 'wp-admin/includes/template.php');
35 @include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
36 $this->upgrade_error_keys = array
37 (
38 'bad_request',
39 'fs_unavailable',
40 'fs_error',
41 'fs_no_root_dir',
42 'fs_no_content_dir',
43 'fs_no_plugins_dir',
44 'fs_no_themes_dir',
45 'fs_no_folder',
46 'download_failed',
47 'no_package',
48 'no_files',
49 'folder_exists',
50 'mkdir_failed',
51 'incompatible_archive',
52 'files_not_writable',
53 'process_failed',
54 'remove_old_failed'
55 );
56 $this->upgrade_wp_flow_keys = array
57 (
58 'installing_package',
59 'maintenance_start',
60 'maintenance_end',
61 'downloading_package',
62 'unpack_package',
63 'remove_old'
64 );
65 $this->upgrade_success_keys = array(
66 'up_to_date',
67 'process_success'
68 );
69
70 global $wp_filesystem;
71 if (!$wp_filesystem)
72 WP_Filesystem();
73 }
74
75 function iwp_mmb_maintenance_mode($enable = false, $maintenance_message = '')
76 {
77 global $wp_filesystem;
78
79 $maintenance_message .= '<?php $upgrading = ' . time() . '; ?>';
80
81 $file = $wp_filesystem->abspath() . '.maintenance';
82 if ($enable) {
83 $wp_filesystem->delete($file);
84 $wp_filesystem->put_contents($file, $maintenance_message, FS_CHMOD_FILE);
85 } else {
86 $wp_filesystem->delete($file);
87 }
88 }
89
90 function bypass_url_validation($r,$url){
91 // $username = parse_url($url, PHP_URL_USER);
92 // $password = parse_url($url, PHP_URL_PASS);
93 // $r['headers'] = array('Authorization'=>'Basic'. base64_encode( $username . ':' . $password ) );
94 $r['reject_unsafe_urls'] = false;
95 $r['sslverify'] = false;
96 return $r;
97 }
98
99 function install_remote_file($params)
100 {
101
102 global $wp_filesystem;
103 extract($params);
104
105 if (!isset($package) || empty($package))
106 return array(
107 'error' => '<p>No files received. Internal error.</p>', 'error_code' => 'no_files_receive_internal_error'
108 );
109
110 if (!$this->define_ftp_constants($params)) {
111 return array(
112 'error' => 'FTP constant define failed', 'error_code' => 'ftp constant define failed'
113 );
114 }
115 if (!$this->is_server_writable()) {
116 return array(
117 'error' => 'Failed, please add FTP details', 'error_code' => 'failed_please_add_ftp_install_remote_file'
118 );
119 }
120
121
122 if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
123 return array(
124 'error' => '<p>Site under maintanace.</p>','error_code' => 'site_under_maintanace'
125 );
126
127 if (!class_exists('WP_Upgrader'))
128 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
129
130 require_once $GLOBALS['iwp_mmb_plugin_dir'].'/updaterSkin.php';
131 $upgrader_skin = new IWP_Updater_TraceableUpdaterSkin;
132
133 $upgrader = new WP_Upgrader($upgrader_skin);
134 $destination = $type == 'themes' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR;
135 $clear_destination = isset($clear_destination) ? $clear_destination : false;
136
137 add_filter( 'http_request_args',array( $this, 'bypass_url_validation' ), 10, 2 );
138 foreach ($package as $package_url) {
139 $key = basename($package_url);
140 $install_info[$key] = @$upgrader->run(array(
141 'package' => $package_url,
142 'destination' => $destination,
143 'clear_destination' => $clear_destination, //Do not overwrite files.
144 'clear_working' => true,
145 'hook_extra' => array()
146 ));
147 }
148
149 // if (defined('WP_ADMIN') && WP_ADMIN) {
150 // global $wp_current_filter;
151 // $wp_current_filter[] = 'load-update-core.php';
152
153 // if (function_exists('wp_clean_update_cache')) {
154 // /** @handled function */
155 // wp_clean_update_cache();
156 // }
157
158 // /** @handled function */
159 // wp_update_plugins();
160
161 // array_pop($wp_current_filter);
162
163 // /** @handled function */
164 // set_current_screen();
165 // do_action('load-update-core.php');
166
167 // /** @handled function */
168 // wp_version_check();
169
170 // /** @handled function */
171 // wp_version_check(array(), true);
172 // }
173
174 if ($activate) {
175 if ($type == 'plugins') {
176 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
177
178 wp_cache_delete( 'plugins', 'plugins' );
179
180 $all_plugins = get_plugins();
181 foreach ($all_plugins as $plugin_slug => $plugin) {
182 $plugin_dir = preg_split('/\//', $plugin_slug);
183 foreach ($install_info as $key => $install) {
184 if (!$install || is_wp_error($install))
185 continue;
186 if ($install['destination_name'] == $plugin_dir[0]) {
187 $install_info[$key]['activated'] = activate_plugin($plugin_slug, '', false);
188 }
189 }
190 }
191 } else if (count($install_info) == 1) {
192 global $wp_themes;
193 include_once(ABSPATH . 'wp-includes/theme.php');
194
195 $wp_themes = null;
196 unset($wp_themes); //prevent theme data caching
197 if(function_exists('wp_get_themes')){
198 $all_themes = wp_get_themes();
199 foreach ($all_themes as $theme_name => $theme_data) {
200 foreach ($install_info as $key => $install) {
201 if (!$install || is_wp_error($install))
202 continue;
203
204 if ($theme_data->Template == $install['destination_name']) {
205 $install_info[$key]['activated'] = switch_theme($theme_data->Template, $theme_data->Stylesheet);
206 }
207 }
208 }
209 }else{
210 $all_themes = get_themes();
211 foreach ($all_themes as $theme_name => $theme_data) {
212 foreach ($install_info as $key => $install) {
213 if (!$install || is_wp_error($install))
214 continue;
215
216 if ($theme_data['Template'] == $install['destination_name']) {
217 $install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']);
218 }
219 }
220 }
221 }
222 }
223 }
224 $this->iwp_mmb_maintenance_mode(false);
225 return $install_info;
226 }
227
228 function do_upgrade($params = null)
229 {
230 global $iwp_mmb_activities_log;
231
232 if ($params == null || empty($params))
233 return array(
234 'error' => 'No upgrades passed.', 'error_code' => 'no_upgrades_passed'
235 );
236 if (!$this->define_ftp_constants($params)) {
237 return array(
238 'error' => 'FTP constant define failed', 'error_code' => 'ftp constant define failed'
239 );
240 }
241 if (!$this->is_server_writable()) {
242 return array(
243 'error' => 'Failed, please add FTP details', 'error_code' => 'failed_please_add_ftp_do_upgrade'
244 );
245 }
246 $WPTC_response = apply_filters('backup_and_update_wptc', $params);
247 if ($WPTC_response == 'WPTC_TAKES_CARE_OF_IT') {
248 return array('success' => 'The update will now be handled by WP Time Capsule. Check the WPTC page for its status.', 'success_code' => 'WPTC_TAKES_CARE_OF_IT');
249 }elseif (!empty($WPTC_response['error_code'])) {
250 return $WPTC_response;
251 }elseif (!empty($WPTC_response['success'])) {
252 return $WPTC_response;
253 }
254 $params = isset($params['upgrades_all']) ? $params['upgrades_all'] : $params;
255
256 $core_upgrade = isset($params['wp_upgrade']) ? $params['wp_upgrade'] : array();
257 $upgrade_plugins = isset($params['upgrade_plugins']) ? $params['upgrade_plugins'] : array();
258 $upgrade_themes = isset($params['upgrade_themes']) ? $params['upgrade_themes'] : array();
259 $upgrade_translations = isset($params['upgrade_translations']) ? $params['upgrade_translations'] : array();
260 $upgrades = array();
261 $premium_upgrades = array();
262 $user = get_user_by( 'login', $params['username'] );
263 $userid = $user->data->ID;
264
265 if (!empty($core_upgrade) || !empty($upgrade_plugins) || !empty($upgrade_themes) || !empty($upgrade_translations)) {
266 $iwp_mmb_activities_log->iwp_mmb_do_remove_upgrader_process_complete_action();
267 $iwp_mmb_activities_log->iwp_mmb_do_remove_theme_filters();
268 $iwp_mmb_activities_log->iwp_mmb_do_remove_upgrader_post_install_filter();
269 }
270 if (!empty($core_upgrade) || !empty($upgrade_plugins) || !empty($upgrade_themes)) {
271 $GLOBALS['iwp_client_plugin_ptc_updates'] = 1;
272 }
273
274 if (!empty($core_upgrade)) {
275 $iwp_mmb_activities_log->iwp_mmb_do_remove_core_updated_successfully();
276 $upgrades['core'] = $this->upgrade_core($core_upgrade,$userid);
277 }
278 if (!empty($upgrade_plugins)) {
279 $plugin_files = $plugin_details = $premium_plugin_details = array();
280 $this->IWP_ithemes_updater_compatiblity();
281 foreach ($upgrade_plugins as $plugin) {
282 $file_path = $plugin['file'];
283 $plugin_name = $plugin['name'];
284 if (isset($file_path)) {
285 $plugin_details[] = $plugin;
286 $plugin_files[$file_path] = $plugin['old_version'];
287 } else {
288 $premium_plugin_details[] = $plugin;
289 $premium_upgrades[md5($plugin_name)] = $plugin;
290 }
291 }
292 if (!empty($plugin_files)) {
293 $upgrades['plugins'] = $this->upgrade_plugins($plugin_files,$plugin_details,$userid);
294 }
295 $this->IWP_ithemes_updater_compatiblity();
296 }
297
298 if (!empty($upgrade_themes)) {
299 $theme_temps = $theme_details = $premium_theme_details = array();
300 foreach ($upgrade_themes as $theme) {
301 if (isset($theme['theme_tmp'])) {
302 $theme_details[] = $theme;
303 $theme_temps[] = $theme['theme_tmp'];
304 } else {
305 $premium_theme_details[] = $theme;
306 $premium_upgrades[md5($theme['name'])] = $theme;
307 }
308 }
309
310 if (!empty($theme_temps))
311 $upgrades['themes'] = $this->upgrade_themes($theme_temps,$theme_details,$userid);
312
313 }
314
315 if (!empty($premium_upgrades)) {
316 $premium_upgrades = $this->upgrade_premium($premium_upgrades,$premium_plugin_details,$premium_theme_details,$userid);
317 if (!empty($premium_upgrades)) {
318 if (!empty($upgrades)) {
319 foreach ($upgrades as $key => $val) {
320 if (isset($premium_upgrades[$key])) {
321 $upgrades[$key] = array_merge_recursive($upgrades[$key], $premium_upgrades[$key]);
322 }
323 }
324 } else {
325 $upgrades = $premium_upgrades;
326 }
327 }
328 }
329 if (!empty($upgrade_translations)) {
330 $upgrades['translations'] = $this->upgrade_translations($upgrade_translations,$userid);
331 }
332 $this->iwp_mmb_maintenance_mode(false);
333 return $upgrades;
334 }
335
336 /**
337 * Upgrades WordPress locally
338 *
339 */
340 function upgrade_translations($current,$userid){
341 global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
342 $GLOBALS['iwp_client_plugin_translations'] = 1;
343 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
344 require_once $GLOBALS['iwp_mmb_plugin_dir'].'/updaterSkin.php';
345 $upgrader = new Language_Pack_Upgrader( new IWP_Updater_TraceableUpdaterSkin() );
346 $result = $upgrader->bulk_upgrade();
347 $upgradeFailed = false;
348 if (!empty($result)) {
349 foreach ($result as $translate_tmp => $translate_info) {
350 if (is_wp_error($translate_info) || empty($translate_info)) {
351 $upgradeFailed = true;
352 $return = array('error' => $this->parse_upgrade_response($upgrader->skin->get_upgrade_messages()), 'error_code' => 'upgrade_translations_wp_error');
353 break;
354 }
355 }
356 if(!$upgradeFailed){
357 $details = array();
358 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('translations', 'update', $iwp_activities_log_post_type, (object)$details, $userid);
359 $return = 'updated';
360 }
361 return array('upgraded' => $return);
362 } else {
363 return array(
364 'error' => 'Upgrade failed.', 'error_code' => 'unable_to_update_translations_files'
365 );
366 }
367 }
368
369 function upgrade_core($current,$userid)
370 {
371 global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
372 ob_start();
373 $current = (object)$current;
374
375 include_once(ABSPATH . '/wp-admin/includes/update.php');
376
377 @wp_version_check();
378
379 $current_update = false;
380 ob_end_flush();
381 ob_end_clean();
382 $core = $this->iwp_mmb_get_transient('update_core');
383
384 if (isset($core->updates) && !empty($core->updates)) {
385 $updates = $core->updates[0];
386 $updated = $core->updates[0];
387 if (!isset($updated->response) || $updated->response == 'latest')
388 return array(
389 'upgraded' => 'updated'
390 );
391
392 if ($updated->response == "development" && $current->response == "upgrade") {
393 return array(
394 'error' => '<font color="#900">Unexpected error. Please upgrade manually.</font>', 'error_code' => 'unexpected_error_please_upgrade_manually'
395 );
396 } else if ($updated->response == $current->response || ($updated->response == "upgrade" && $current->response == "development")) {
397 if ($updated->locale != $current->locale) {
398 foreach ($updates as $update) {
399 if ($update->locale == $current->locale) {
400 $current_update = $update;
401 break;
402 }
403 }
404 if ($current_update == false)
405 return array(
406 'error' => ' Localization mismatch. Try again.', 'error_code' => 'localization_mismatch'
407 );
408 } else {
409 $current_update = $updated;
410 }
411 } else
412 return array(
413 'error' => ' Transient mismatch. Try again.', 'error_code' => 'transient_mismatch'
414 );
415 } else
416 return array(
417 'error' => ' Refresh transient failed. Try again.', 'error_code' => 'refresh_transient_failed'
418 );
419 if ($current_update != false) {
420 global $iwp_mmb_wp_version, $wp_filesystem, $wp_version;
421
422 if (version_compare($wp_version, '3.1.9', '>')) {
423 if (!class_exists('Core_Upgrader'))
424 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
425 require_once $GLOBALS['iwp_mmb_plugin_dir'].'/updaterSkin.php';
426 $core = new Core_Upgrader(new IWP_Updater_TraceableUpdaterSkin());
427 $result = $core->upgrade($current_update);
428 $this->iwp_mmb_maintenance_mode(false);
429 if (is_wp_error($result)) {
430 return array(
431 'error' => $this->iwp_mmb_get_error($result), 'error_code' => 'maintenance_mode_upgrade_core'
432 );
433 } else {
434 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('core', 'update', $iwp_activities_log_post_type, $current, $userid);
435 return array(
436 'upgraded' => 'updated'
437 );
438 }
439 } else {
440 if (!class_exists('WP_Upgrader')) {
441 include_once(ABSPATH . 'wp-admin/includes/update.php');
442 if (function_exists('wp_update_core')) {
443 $result = wp_update_core($current_update);
444 if (is_wp_error($result)) {
445 return array(
446 'error' => $this->iwp_mmb_get_error($result), 'error_code' => 'wp_update_core_upgrade_core'
447 );
448 } else {
449 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('core', 'update', $iwp_activities_log_post_type, $current, $userid);
450 return array(
451 'upgraded' => 'updated'
452 );
453 }
454 }
455 }
456
457 if (class_exists('WP_Upgrader')) {
458 $upgrader_skin = new WP_Upgrader_Skin();
459 $upgrader_skin->done_header = true;
460
461 $upgrader = new WP_Upgrader($upgrader_skin);
462
463 // Is an update available?
464 if (!isset($current_update->response) || $current_update->response == 'latest')
465 return array(
466 'upgraded' => 'updated'
467 );
468
469 $res = $upgrader->fs_connect(array(
470 ABSPATH,
471 WP_CONTENT_DIR
472 ));
473 if (is_wp_error($res))
474 return array(
475 'error' => $this->iwp_mmb_get_error($res), 'error_code' => 'upgrade_core_wp_error_res'
476 );
477
478 $wp_dir = trailingslashit($wp_filesystem->abspath());
479
480 $core_package = false;
481 if (isset($current_update->package) && !empty($current_update->package))
482 $core_package = $current_update->package;
483 elseif (isset($current_update->packages->full) && !empty($current_update->packages->full))
484 $core_package = $current_update->packages->full;
485
486 $download = $upgrader->download_package($core_package);
487 if (is_wp_error($download))
488 return array(
489 'error' => $this->iwp_mmb_get_error($download), 'error_code' => 'download_upgrade_core'
490 );
491
492 $working_dir = $upgrader->unpack_package($download);
493 if (is_wp_error($working_dir))
494 return array(
495 'error' => $this->iwp_mmb_get_error($working_dir), 'error_code' => 'working_dir_upgrade_core'
496 );
497
498 if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
499 $wp_filesystem->delete($working_dir, true);
500 return array(
501 'error' => 'Unable to move update files.', 'error_code' => 'unable_to_move_update_files'
502 );
503 }
504
505 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
506
507 require(ABSPATH . 'wp-admin/includes/update-core.php');
508
509
510 $update_core = update_core($working_dir, $wp_dir);
511
512 $this->iwp_mmb_maintenance_mode(false);
513 if (is_wp_error($update_core))
514 return array(
515 'error' => $this->iwp_mmb_get_error($update_core), 'error_code' => 'upgrade_core_wp_error'
516 );
517 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('core', 'update', $iwp_activities_log_post_type, $current, $userid);
518 return array(
519 'upgraded' => 'updated'
520 );
521 } else {
522 return array(
523 'error' => 'failed', 'error_code' => 'failed_WP_Upgrader_class_not_exists'
524 );
525 }
526 }
527 } else {
528 return array(
529 'error' => 'failed', 'error_code' => 'failed_current_update_false'
530 );
531 }
532 }
533
534 function upgrade_plugins($plugins = array(),$plugin_details = false,$userid = false)
535 {
536 global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
537 if ($plugin_details == false) {
538 $plugin_details = array();
539 }
540 if (!$plugins || empty($plugins))
541 return array(
542 'error' => 'No plugin files for upgrade.', 'error_code' => 'no_plugin_files_for_upgrade'
543 );
544 $current = $this->iwp_mmb_get_transient('update_plugins');
545 $versions = array();
546 if(!empty($current)){
547 foreach($plugins as $plugin => $data){
548 if(isset($current->checked[$plugin])){
549 $versions[$current->checked[$plugin]] = $plugin;
550 }
551 }
552 }
553 $return = array();
554 $upgrade_msg = array();
555 if (class_exists('Plugin_Upgrader')) {
556
557 if (!function_exists('wp_update_plugins'))
558 include_once(ABSPATH . 'wp-includes/update.php');
559
560 require_once $GLOBALS['iwp_mmb_plugin_dir'].'/updaterSkin.php';
561
562 @wp_update_plugins();
563 $upgrader = new Plugin_Upgrader(new IWP_Updater_TraceableUpdaterSkin());
564 $result = $upgrader->bulk_upgrade(array_keys($plugins));
565 $current = $this->iwp_mmb_get_transient('update_plugins');
566 if (!empty($result)) {
567 foreach ($result as $plugin_slug => $plugin_info) {
568 $upgrade_msg[$plugin_slug] = $upgrader->skin->get_upgrade_messages();
569
570 if ($this->is_up_to_date_issue($upgrade_msg[$plugin_slug])) {
571 $return[$plugin_slug] = array('error' => 'We are unable to update the plugin. Please perform the update again.', 'error_code' => 'up_to_date');
572 }elseif (!$plugin_info || is_wp_error($plugin_info)) {
573 $return[$plugin_slug] = array('error' => $this->parse_upgrade_response($upgrader->skin->get_upgrade_messages()), 'error_code' => 'upgrade_plugins_wp_error');
574 } else {
575 if(
576 !empty($result[$plugin_slug])
577 || (
578 isset($current->checked[$plugin_slug])
579 && version_compare(array_search($plugin_slug, $versions), $current->checked[$plugin_slug], '<') == true
580 )
581 ){
582 foreach($plugin_details as $key=>$plugin_detail) {
583 /* the following "if" is used to detect premium plugin properties.*/
584 if(is_array($plugin_detail)) {
585 $plugin_detail = (object) $plugin_detail;
586 }
587 /* the above "if" is used to detect premium plugin properties.*/
588
589 if(
590 (
591 isset($plugin_detail->plugin)
592 && $plugin_slug==$plugin_detail->plugin
593 )
594 || ( // This condition is used to detect premium plugin properties.
595 isset($plugin_detail->slug)
596 && $plugin_slug==$plugin_detail->slug
597 )
598 ) {
599 $current_plugin = array();
600 $current_plugin['name'] = isset($plugin_detail->name)?$plugin_detail->name:'';
601
602 if(isset($plugin_detail->textdomain)) { // this "if" is used to detect premium plugin properties.
603 $current_plugin['slug'] = $plugin_detail->textdomain;
604 } else if(isset($plugin_detail->slug)) {
605 $current_plugin['slug'] = $plugin_detail->slug;
606 } else {
607 $current_plugin['slug'] = '';
608 }
609
610 if(isset($plugin_detail->old_version)) {
611 $current_plugin['old_version'] = $plugin_detail->old_version;
612 } else if(isset($plugin_detail->version)) {
613 $current_plugin['old_version'] = $plugin_detail->version;
614 } else {
615 $current_plugin['old_version'] = '';
616 }
617
618 $current_plugin['updated_version'] = isset($plugin_detail->new_version) ? $plugin_detail->new_version : '';
619 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('plugins', 'update', $iwp_activities_log_post_type, (object)$current_plugin, $userid);
620 unset($current_plugin);
621 break;
622 }
623 }
624 $return[$plugin_slug] = 1;
625 } else {
626 update_option('iwp_client_forcerefresh', true);
627 $return[$plugin_slug] = array('error' => 'Could not refresh upgrade transients, please reload website data', 'error_code' => 'upgrade_plugins_could_not_refresh_upgrade_transients_please_reload_website_data');
628 }
629 }
630 }
631 return array(
632 'upgraded' => $return,
633 'upgraded_msg' => $upgrade_msg
634 );
635 } else
636 return array(
637 'error' => 'Upgrade failed.', 'error_code' => 'upgrade_failed_upgrade_plugins'
638 );
639 } else {
640 return array(
641 'error' => 'WordPress update required first.', 'error_code' => 'upgrade_plugins_wordPress_update_required_first'
642 );
643 }
644 }
645
646 public function is_up_to_date_issue( $error_message ){
647 if (empty($error_message)) {
648 return false;
649 }
650
651 foreach ($error_message as $key => $value) {
652 if ( $value['key'] == 'up_to_date') {
653 return true;
654 }
655 }
656
657 return false;
658 }
659
660 function upgrade_themes($themes = false,$theme_details = false,$userid = false)
661 {
662 if ($themes == false) {
663 $themes = array();
664 }
665 if ($theme_details == false) {
666 $theme_details = array();
667 }
668 global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
669 if (!$themes || empty($themes))
670 return array(
671 'error' => 'No theme files for upgrade.', 'error_code' => 'no_theme_files_for_upgrade'
672 );
673
674 $current = $this->iwp_mmb_get_transient('update_themes');
675 $versions = array();
676 if(!empty($current)){
677 foreach($themes as $theme){
678 if(isset($current->checked[$theme])){
679 $versions[$current->checked[$theme]] = $theme;
680 }
681 }
682 }
683 if (class_exists('Theme_Upgrader')) {
684 require_once $GLOBALS['iwp_mmb_plugin_dir'].'/updaterSkin.php';
685 $upgrader = new Theme_Upgrader(new IWP_Updater_TraceableUpdaterSkin());
686 $result = $upgrader->bulk_upgrade($themes);
687
688 if (!function_exists('wp_update_themes'))
689 include_once(ABSPATH . 'wp-includes/update.php');
690
691 @wp_update_themes();
692 $current = $this->iwp_mmb_get_transient('update_themes');
693 $return = array();
694 if (!empty($result)) {
695 foreach ($result as $theme_tmp => $theme_info) {
696 $upgrade_msg[$theme_tmp] = $upgrader->skin->get_upgrade_messages();
697 if ($this->is_up_to_date_issue($upgrade_msg[$theme_tmp])) {
698 $return[$theme_tmp] = array('error' => 'We are unable to update the theme. Please perform the update again.', 'error_code' => 'up_to_date');
699 }elseif (is_wp_error($theme_info) || empty($theme_info)) {
700 $return[$theme_tmp] = array('error' => $this->parse_upgrade_response($upgrader->skin->get_upgrade_messages()), 'error_code' => 'upgrade_plugins_wp_error');
701 } else {
702 if(!empty($result[$theme_tmp]) || (isset($current->checked[$theme_tmp]) && version_compare(array_search($theme_tmp, $versions), $current->checked[$theme_tmp], '<') == true)){
703 foreach($theme_details as $key=>$theme_detail) {
704 if($theme_tmp==$theme_detail['theme_tmp']) {
705 $current_theme = array();
706 $current_theme['name'] = $theme_detail['name'];
707 if (isset($theme_detail['theme_tmp'])) {
708 $current_theme['slug'] = $theme_detail['theme_tmp'];// slug is used to get short description. Here theme name as slug.
709 }
710 $current_theme['old_version'] = $theme_detail['old_version'];
711 $current_theme['updated_version'] = $theme_detail['new_version'];
712 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('themes', 'update', $iwp_activities_log_post_type, (object)$current_theme, $userid);
713 unset($current_theme);
714 break;
715 }
716 }
717 $return[$theme_tmp] = 1;
718 } else {
719 update_option('iwp_client_forcerefresh', true);
720 $return[$theme_tmp] = array('error' => 'Could not refresh upgrade transients, please reload website data', 'error_code' => 'upgrade_themes_could_not_refresh_upgrade_transients_reload_website');
721 }
722 }
723 }
724 return array(
725 'upgraded' => $return,
726 'upgraded_msg' => $upgrade_msg
727 );
728 } else
729 return array(
730 'error' => 'Upgrade failed.', 'error_code' => 'upgrade_failed_upgrade_themes'
731 );
732 } else {
733 return array(
734 'error' => 'WordPress update required first', 'error_code' => 'wordPress_update_required_first_upgrade_themes'
735 );
736 }
737 }
738
739 function upgrade_premium($premium = false,$premium_plugin_details = false,$premium_theme_details = false,$userid = false)
740 {
741 global $iwp_mmb_plugin_url;
742
743 if (!class_exists('WP_Upgrader'))
744 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
745
746 if (!$premium || empty($premium))
747 $premium = array();
748 return array(
749 'error' => 'No premium files for upgrade.', 'error_code' => 'no_premium_files_for_upgrade'
750 );
751
752 $upgrader = false;
753 $pr_update = array();
754 $themes = array();
755 $plugins = array();
756 $result = array();
757 $premium_update = array();
758 $premium_update = apply_filters('mwp_premium_perform_update', $premium_update);
759 if (!empty($premium_update)) {
760
761 foreach ($premium as $pr) {
762 foreach ($premium_update as $key => $update) {
763 $update = array_change_key_case($update, CASE_LOWER);
764 if ($update['name'] == $pr['name']) {
765
766 // prepare bulk updates for premiums that use WordPress upgrader
767 if(isset($update['type'])){
768 if($update['type'] == 'plugin'){
769 if(isset($update['slug']) && !empty($update['slug']))
770 $plugins[$update['slug']] = $update;
771 }
772
773 if($update['type'] == 'theme'){
774 if(isset($update['template']) && !empty($update['template']))
775 $themes[$update['template']] = $update;
776 }
777 }
778 } else {
779 unset($premium_update[$key]);
780 }
781 }
782 }
783
784 // try default wordpress upgrader
785 if(!empty($plugins)){
786 $updateplugins = $this->upgrade_plugins($plugins,$premium_plugin_details,$userid);
787 if(!empty($updateplugins) && isset($updateplugins['upgraded'])){
788 foreach ($premium_update as $key => $update) {
789 $update = array_change_key_case($update, CASE_LOWER);
790 foreach($updateplugins['upgraded'] as $slug => $upgrade){
791 if( isset($update['slug']) && $update['slug'] == $slug){
792 if( $upgrade == 1 )
793 unset($premium_update[$key]);
794
795 $pr_update['plugins']['upgraded'][md5($update['name'])] = $upgrade;
796 }
797 }
798 }
799 }
800 }
801
802 if(!empty($themes)){
803 $updatethemes = $this->upgrade_themes(array_keys($themes),$premium_theme_details,$userid);
804 if(!empty($updatethemes) && isset($updatethemes['upgraded'])){
805 foreach ($premium_update as $key => $update) {
806 $update = array_change_key_case($update, CASE_LOWER);
807 foreach($updatethemes['upgraded'] as $template => $upgrade){
808 if( isset($update['template']) && $update['template'] == $template) {
809 if( $upgrade == 1 )
810 unset($premium_update[$key]);
811
812 $pr_update['themes']['upgraded'][md5($update['name'])] = $upgrade;
813 }
814 }
815 }
816 }
817 }
818
819 //try direct install with overwrite
820 if (!empty($premium_update)) {
821 foreach ($premium_update as $update) {
822 $update = array_change_key_case($update, CASE_LOWER);
823 $update_result = false;
824 if (isset($update['url'])) {
825 if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
826 $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = 'Site under maintanace.';
827
828 $upgrader_skin = new WP_Upgrader_Skin();
829 $upgrader_skin->done_header = true;
830 $upgrader = new WP_Upgrader();
831 @$update_result = $upgrader->run(array(
832 'package' => $update['url'],
833 'destination' => isset($update['type']) && $update['type'] == 'theme' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR,
834 'clear_destination' => true,
835 'clear_working' => true,
836 'is_multi' => true,
837 'hook_extra' => array()
838 ));
839 $update_result = !$update_result || is_wp_error($update_result) ? $this->iwp_mmb_get_error($update_result) : 1;
840
841 } else if (isset($update['callback'])) {
842 if (is_array($update['callback'])) {
843 $update_result = call_user_func(array( $update['callback'][0], $update['callback'][1] ));
844 } else if (is_string($update['callback'])) {
845 $update_result = call_user_func($update['callback']);
846 } else {
847 $update_result = array('error' => 'Upgrade function "' . $update['callback'] . '" does not exists.', 'error_code' => 'upgrade_func_callback_does_not_exists');
848 }
849
850 $update_result = $update_result !== true ? array('error' => $this->iwp_mmb_get_error($update_result), 'error_code' => 'upgrade_premium_wp_error') : 1;
851 } else
852 $update_result = array('error' => 'Bad update params.', 'error_code' => 'bad_update_params');
853
854 $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = $update_result;
855 }
856 }
857 return $pr_update;
858 } else {
859 foreach ($premium as $pr) {
860 $result[$pr['type'] . 's']['upgraded'][md5($pr['name'])] = array('error' => 'This premium plugin/theme update is not registered with the InfiniteWP update mechanism. Please contact the plugin/theme developer to get this issue fixed.', 'error_code' => 'premium_update_not_registered');
861 }
862 return $result;
863 }
864 }
865
866 function get_upgradable_plugins( $filter = array() )
867 {
868 if (!function_exists('wp_update_plugins'))
869 include_once(ABSPATH . 'wp-includes/update.php');
870 @wp_update_plugins();
871 $current = $this->iwp_mmb_get_transient('update_plugins');
872
873 $upgradable_plugins = array();
874 if (!empty($current->response)) {
875 if (!function_exists('get_plugin_data'))
876 include_once ABSPATH . 'wp-admin/includes/plugin.php';
877 foreach ($current->response as $plugin_path => $plugin_data) {
878 if ($plugin_path == 'iwp-client/init.php')
879 continue;
880
881 $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
882 if(isset($data['Name']) && in_array($data['Name'], $filter))
883 continue;
884
885 if (strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
886 $current->response[$plugin_path]->name = $data['Name'];
887 $current->response[$plugin_path]->old_version = $data['Version'];
888 $current->response[$plugin_path]->file = $plugin_path;
889 unset($current->response[$plugin_path]->upgrade_notice);
890 $upgradable_plugins[] = $current->response[$plugin_path];
891 }
892 }
893 return $upgradable_plugins;
894 } else
895 return array();
896 }
897 function get_upgradable_translations() {
898 if (!function_exists('wp_get_translation_updates')){
899 include_once(ABSPATH . 'wp-includes/update.php');
900 }
901
902 if (function_exists('wp_get_translation_updates')) {
903 $translations_object = wp_get_translation_updates();
904 $translations_object = array_filter($translations_object);
905 }
906
907 if (isset($translations_object) && !empty($translations_object)){
908 return true;
909 } else{
910 return false;
911 }
912 }
913
914 function get_upgradable_themes($filter = array()) {
915 if (function_exists('wp_get_themes')) {
916 $all_themes = wp_get_themes();
917 $upgrade_themes = array();
918
919 $current = $this->iwp_mmb_get_transient('update_themes');
920 if (!empty($current->response)) {
921 foreach ((array) $all_themes as $theme_template => $theme_data) {
922 foreach ($current->response as $current_themes => $theme) {
923 if ($theme_data->Stylesheet !== $current_themes) {
924 continue;
925 }
926
927 if (strlen($theme_data->Name) === 0 || strlen($theme_data->Version) === 0) {
928 continue;
929 }
930 // WP can store theme update data as array or object; normalize to array.
931 $theme_update = isset($current->response[$current_themes]) ? $current->response[$current_themes] : array();
932 if (is_object($theme_update)) {
933 $theme_update = (array) $theme_update;
934 }
935 if (!is_array($theme_update)) {
936 $theme_update = array();
937 }
938 $theme_update['name'] = $theme_data->Name;
939 $theme_update['old_version'] = $theme_data->Version;
940 $theme_update['theme_tmp'] = $theme_data->Stylesheet;
941
942 $current->response[$current_themes] = $theme_update;
943 $upgrade_themes[] = $theme_update;
944 }
945 }
946 }
947 } else {
948 $all_themes = get_themes();
949
950 $upgrade_themes = array();
951
952 $current = $this->iwp_mmb_get_transient('update_themes');
953
954 if (!empty($current->response)) {
955 foreach ((array) $all_themes as $theme_template => $theme_data) {
956 if (isset($theme_data['Parent Theme']) && !empty($theme_data['Parent Theme'])) {
957 continue;
958 }
959
960 if (isset($theme_data['Name']) && in_array($theme_data['Name'], $filter)) {
961 continue;
962 }
963
964 if (method_exists($theme_data,'parent') && !$theme_data->parent()) {
965 foreach ($current->response as $current_themes => $theme) {
966 if ($theme_data['Template'] == $current_themes) {
967 if (strlen($theme_data['Name']) > 0 && strlen($theme_data['Version']) > 0) {
968 // WP can store theme update data as array or object; normalize to array.
969 $theme_update = isset($current->response[$current_themes]) ? $current->response[$current_themes] : array();
970 if (is_object($theme_update)) {
971 $theme_update = (array) $theme_update;
972 }
973 if (!is_array($theme_update)) {
974 $theme_update = array();
975 }
976 $theme_update['name'] = $theme_data['Name'];
977 $theme_update['old_version'] = $theme_data['Version'];
978 $theme_update['theme_tmp'] = $theme_data['Template'];
979
980 $current->response[$current_themes] = $theme_update;
981 $upgrade_themes[] = $theme_update;
982 }
983 }
984 }
985 }
986 }
987 }
988
989 }
990
991 return $upgrade_themes;
992 }
993
994 function get($args)
995 {
996 if (empty($args))
997 return false;
998
999 //Args: $items('plugins,'themes'), $type (active || inactive), $search(name string)
1000
1001 $return = array();
1002 if (is_array($args['items']) && in_array('plugins', $args['items'])) {
1003 $return['plugins'] = $this->get_plugins($args);
1004 }
1005 if (is_array($args['items']) && in_array('themes', $args['items'])) {
1006 $return['themes'] = $this->get_themes($args);
1007 }
1008
1009 return $return;
1010 }
1011
1012 function get_plugins($args)
1013 {
1014 if (empty($args))
1015 return false;
1016
1017 extract($args);
1018
1019 if (!function_exists('get_plugins')) {
1020 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
1021 }
1022 $all_plugins = get_plugins();
1023 $plugins = array(
1024 'active' => array(),
1025 'inactive' => array()
1026 );
1027 if (is_array($all_plugins) && !empty($all_plugins)) {
1028
1029 $br_a = 0;
1030 $br_i = 0;
1031 foreach ($all_plugins as $path => $plugin) {
1032 if ($plugin['Name'] != 'InfiniteWP - Client') {
1033 if($this->check_plugin_activated($path) == true){
1034 $plugins['active'][$br_a]['path'] = $path;
1035 $plugins['active'][$br_a]['name'] = strip_tags($plugin['Name']);
1036 $plugins['active'][$br_a]['version'] = $plugin['Version'];
1037 $plugins['active'][$br_a]['network'] = $plugin['Network'];
1038 $br_a++;
1039 }
1040
1041 if ($this->check_plugin_activated($path) == false) {
1042 $plugins['inactive'][$br_i]['path'] = $path;
1043 $plugins['inactive'][$br_i]['name'] = strip_tags($plugin['Name']);
1044 $plugins['inactive'][$br_i]['version'] = $plugin['Version'];
1045 $plugins['inactive'][$br_i]['network'] = $plugin['Network'];
1046 $br_i++;
1047 }
1048
1049 }
1050
1051 if ($search) {
1052 foreach ($plugins['active'] as $k => $plugin) {
1053 if (!stristr($plugin['name'], $search)) {
1054 unset($plugins['active'][$k]);
1055 }
1056 }
1057
1058 foreach ($plugins['inactive'] as $k => $plugin) {
1059 if (!stristr($plugin['name'], $search)) {
1060 unset($plugins['inactive'][$k]);
1061 }
1062 }
1063 }
1064 }
1065 }
1066 return $plugins;
1067 }
1068
1069
1070 function get_themes($args)
1071 {
1072 if (empty($args))
1073 return false;
1074
1075 extract($args);
1076
1077 if (!function_exists('wp_get_themes')) {
1078 include_once(ABSPATH . WPINC . '/theme.php');
1079 }
1080 if(function_exists('wp_get_themes')){
1081 $all_themes = wp_get_themes();
1082 $themes = array(
1083 'active' => array(),
1084 'inactive' => array()
1085 );
1086 if (is_array($all_themes) && !empty($all_themes)) {
1087 $current_theme = wp_get_theme();
1088
1089 $br_a = 0;
1090 $br_i = 0;
1091 foreach ($all_themes as $theme_name => $theme) {
1092 if ($current_theme == strip_tags($theme->Name)) {
1093 $themes['active'][$br_a]['path'] = $theme->Template;
1094 $themes['active'][$br_a]['name'] = strip_tags($theme->Name);
1095 $themes['active'][$br_a]['version'] = $theme->Version;
1096 $themes['active'][$br_a]['stylesheet'] = $theme->Stylesheet;
1097 $br_a++;
1098 }
1099
1100 if ($current_theme != strip_tags($theme->Name)) {
1101 $themes['inactive'][$br_i]['path'] = $theme->Template;
1102 $themes['inactive'][$br_i]['name'] = strip_tags($theme->Name);
1103 $themes['inactive'][$br_i]['version'] = $theme->Version;
1104 $themes['inactive'][$br_i]['stylesheet'] = $theme->Stylesheet;
1105 $br_i++;
1106 }
1107
1108 }
1109
1110 if (!empty($search)) {
1111 foreach ($themes['active'] as $k => $theme) {
1112 if (!stristr($theme['name'], $search)) {
1113 unset($themes['active'][$k]);
1114 }
1115 }
1116
1117 foreach ($themes['inactive'] as $k => $theme) {
1118 if (!stristr($theme['name'], $search)) {
1119 unset($themes['inactive'][$k]);
1120 }
1121 }
1122 }
1123 }
1124 }else{
1125 $all_themes = get_themes();
1126 $themes = array(
1127 'active' => array(),
1128 'inactive' => array()
1129 );
1130
1131 if (is_array($all_themes) && !empty($all_themes)) {
1132 $current_theme = get_current_theme();
1133
1134 $br_a = 0;
1135 $br_i = 0;
1136 foreach ($all_themes as $theme_name => $theme) {
1137 if ($current_theme == $theme_name) {
1138 $themes['active'][$br_a]['path'] = $theme['Template'];
1139 $themes['active'][$br_a]['name'] = strip_tags($theme['Name']);
1140 $themes['active'][$br_a]['version'] = $theme['Version'];
1141 $themes['active'][$br_a]['stylesheet'] = $theme['Stylesheet'];
1142 $br_a++;
1143 }
1144
1145 if ($current_theme != $theme_name) {
1146 $themes['inactive'][$br_i]['path'] = $theme['Template'];
1147 $themes['inactive'][$br_i]['name'] = strip_tags($theme['Name']);
1148 $themes['inactive'][$br_i]['version'] = $theme['Version'];
1149 $themes['inactive'][$br_i]['stylesheet'] = $theme['Stylesheet'];
1150 $br_i++;
1151 }
1152
1153 }
1154
1155 if ($search) {
1156 foreach ($themes['active'] as $k => $theme) {
1157 if (!stristr($theme['name'], $search)) {
1158 unset($themes['active'][$k]);
1159 }
1160 }
1161
1162 foreach ($themes['inactive'] as $k => $theme) {
1163 if (!stristr($theme['name'], $search)) {
1164 unset($themes['inactive'][$k]);
1165 }
1166 }
1167 }
1168 }
1169
1170 }
1171
1172 return $themes;
1173 }
1174
1175 function edit($args)
1176 {
1177 extract($args);
1178 $return = array();
1179 if (!$this->define_ftp_constants($args)) {
1180 return array(
1181 'error' => 'FTP constant define failed', 'error_code' => 'ftp constant define failed'
1182 );
1183 }
1184 if ($type == 'plugins') {
1185 $return['plugins'] = $this->edit_plugins($args);
1186 } elseif ($type == 'themes') {
1187 $return['themes'] = $this->edit_themes($args);
1188 }
1189 return $return;
1190 }
1191
1192 function edit_plugins($args)
1193 {
1194 extract($args);
1195 $return = array();
1196 foreach ($items as $item) {
1197 switch ($item['action']) {//switch ($items_edit_action) => switch ($item['action'])
1198 case 'activate':
1199 $network_activate = false;
1200 if(!empty($item['network_activate']) && $item['network_activate'] == true){
1201 $network_activate = true;
1202 }
1203 $result = activate_plugin($item['path'],'',$network_activate);
1204 break;
1205 case 'deactivate':
1206 $result = deactivate_plugins(array(
1207 $item['path']
1208 ));
1209 break;
1210 case 'delete':
1211 $result = delete_plugins(array(
1212 $item['path']
1213 ));
1214 break;
1215 default:
1216 break;
1217 }
1218
1219 if (is_wp_error($result)) {
1220 $result = array(
1221 'error' => $result->get_error_message(), 'error_code' => 'wp_error_edit_plugins'
1222 );
1223 } elseif ($result === false) {
1224 $result = array(
1225 'error' => "Failed to perform action.", 'error_code' => 'failed_to_perform_action_edit_plugins'
1226 );
1227 } else {
1228 $result = "OK";
1229 }
1230 $return[$item['name']] = $result;
1231 }
1232
1233 return $return;
1234 }
1235
1236 function edit_themes($args)
1237 {
1238 extract($args);
1239 $return = array();
1240 foreach ($items as $item) {
1241 switch ($item['action']) {//switch ($items_edit_action) => switch ($item['action'])
1242 case 'activate':
1243 switch_theme($item['path'], $item['stylesheet']);
1244 break;
1245 case 'delete':
1246 $result = delete_theme($item['path']);
1247 break;
1248 default:
1249 break;
1250 }
1251
1252 if (is_wp_error($result)) {
1253 $result = array(
1254 'error' => $result->get_error_message(), 'error_code' => 'wp_error_edit_themes'
1255 );
1256 } elseif ($result === false) {
1257 $result = array(
1258 'error' => "Failed to perform action.", 'error_code' => 'failed_to_perform_action_edit_themes'
1259 );
1260 } else {
1261 $result = "OK";
1262 }
1263 $return[$item['name']] = $result;
1264 }
1265
1266 return $return;
1267
1268 }
1269
1270 function IWP_ithemes_updater_compatiblity()
1271 {
1272 // Check for the iThemes updater class
1273 if (empty($GLOBALS['ithemes_updater_path']) ||
1274 !file_exists($GLOBALS['ithemes_updater_path'].'/settings.php')
1275 ) {
1276 return;
1277 }
1278
1279 // Include iThemes updater
1280 require_once $GLOBALS['ithemes_updater_path'].'/settings.php';
1281
1282 // Check if the updater is instantiated
1283 if (empty($GLOBALS['ithemes-updater-settings'])) {
1284 return;
1285 }
1286
1287 // Update the download link
1288 $GLOBALS['ithemes-updater-settings']->flush('forced');
1289 }
1290 function get_additional_plugin_updates()
1291 {
1292
1293 $additional_updates = array();
1294
1295 if (is_plugin_active('woocommerce/woocommerce.php') && $this->has_woocommerce_db_update()) {
1296 $additional_updates['woocommerce/woocommerce.php'] = 1;
1297 }
1298
1299 return $additional_updates;
1300 }
1301
1302 function has_woocommerce_db_update()
1303 {
1304 $current_db_version = get_option('woocommerce_db_version', null);
1305 $current_wc_version = get_option('woocommerce_version');
1306 if (version_compare($current_wc_version, '3.0.0', '<')) {
1307 return true;
1308 }
1309
1310 if (!is_callable('WC_Install::get_db_update_callbacks')) {
1311 return false;
1312 }
1313
1314 /** @handled static */
1315 $updates = WC_Install::get_db_update_callbacks();
1316
1317 return !is_null($current_db_version) && version_compare($current_db_version, max(array_keys($updates)), '<');
1318 }
1319
1320 function parse_upgrade_response($response = null , $parse_error = true){
1321 $error_message = '';
1322 foreach ($response as $key => $message) {
1323 if(in_array($message['key'], $this->upgrade_wp_flow_keys) !== false){
1324 continue;
1325 }
1326 if(in_array($message['key'], $this->upgrade_success_keys) !== false){
1327 break;
1328 }
1329 if(in_array($message['key'], $this->upgrade_error_keys) !== false){
1330 $error_message = $message['message'];
1331 break;
1332 }
1333 $error_message = $message['message'];
1334 break;
1335 }
1336 if ($parse_error) {
1337 return !empty($error_message) ? $error_message : 'Could not find error from response : ' . serialize($response);
1338 }
1339 }
1340 }
1341 ?>