| 1 | <?php | 
|---|
| 2 | include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | 
|---|
| 3 |  | 
|---|
| 4 | class Xpress_Upgrader extends WP_Upgrader { | 
|---|
| 5 |  | 
|---|
| 6 | function upgrade_strings() { | 
|---|
| 7 | $this->strings['up_to_date'] = __('XPressME Integration Kit is at the latest version.', 'xpressme'); | 
|---|
| 8 | $this->strings['no_package'] = __('Upgrade package not available.', 'xpressme'); | 
|---|
| 9 | $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…', 'xpressme'); | 
|---|
| 10 | $this->strings['unpack_package'] = __('Unpacking the update…', 'xpressme'); | 
|---|
| 11 | $this->strings['copy_failed'] = __('Could not copy files.', 'xpressme'); | 
|---|
| 12 | $this->strings['make_config'] = __('Delete source wp-config.php.', 'xpressme'); | 
|---|
| 13 | $this->strings['delete_failed'] = __('Could not delete files.', 'xpressme'); | 
|---|
| 14 | $this->strings['package_wrong'] = __('The structure of the package is wrong. ', 'xpressme'); | 
|---|
| 15 | } | 
|---|
| 16 |  | 
|---|
| 17 | function upgrade($current) { | 
|---|
| 18 | global $wp_filesystem; | 
|---|
| 19 |  | 
|---|
| 20 | $this->init(); | 
|---|
| 21 | $this->upgrade_strings(); | 
|---|
| 22 |  | 
|---|
| 23 | if ( !empty($feedback) ) | 
|---|
| 24 | add_filter('update_feedback', $feedback); | 
|---|
| 25 |  | 
|---|
| 26 | // Is an update available? | 
|---|
| 27 | if ( !isset( $current->response ) || $current->response == 'latest' ) | 
|---|
| 28 | return new WP_Error('up_to_date', $this->strings['up_to_date']); | 
|---|
| 29 |  | 
|---|
| 30 | $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) ); | 
|---|
| 31 | if ( is_wp_error($res) ) | 
|---|
| 32 | return $res; | 
|---|
| 33 |  | 
|---|
| 34 | $wp_dir = trailingslashit($wp_filesystem->abspath()); | 
|---|
| 35 |  | 
|---|
| 36 | $download = $this->download_package( $current->package ); | 
|---|
| 37 | if ( is_wp_error($download) ) | 
|---|
| 38 | return $download; | 
|---|
| 39 |  | 
|---|
| 40 | $working_dir = $this->unpack_package( $download ); | 
|---|
| 41 | if ( is_wp_error($working_dir) ) | 
|---|
| 42 | return $working_dir; | 
|---|
| 43 | $kit_dir = $working_dir .'/xpressme_integration_kit/'; | 
|---|
| 44 | if (!$wp_filesystem->exists($kit_dir)){ // search sub dir. | 
|---|
| 45 | $kit_dir = ''; | 
|---|
| 46 | $subdirs = $wp_filesystem->dirlist($working_dir,false); | 
|---|
| 47 | foreach($subdirs as $subdir){ | 
|---|
| 48 | if ($wp_filesystem->exists($working_dir .'/' .$subdir['name'] .'/xpressme_integration_kit/')){ | 
|---|
| 49 | $kit_dir = $working_dir .'/' .$subdir['name'] .'/xpressme_integration_kit/'; | 
|---|
| 50 | continue; | 
|---|
| 51 | } | 
|---|
| 52 | } | 
|---|
| 53 | if (empty($kit_dir)){ | 
|---|
| 54 | $wp_filesystem->delete($working_dir, true); | 
|---|
| 55 | return new WP_Error('package_wrong', $this->strings['package_wrong']); | 
|---|
| 56 | } | 
|---|
| 57 | } | 
|---|
| 58 | // Copy update-core.php from the new version into place. | 
|---|
| 59 | $update_xpress_file = 'wp-content/plugins/xpressme/include/update_xpress.php'; | 
|---|
| 60 | if ( !$wp_filesystem->copy($kit_dir . $update_xpress_file, $wp_dir . $update_xpress_file, true) ) { | 
|---|
| 61 | $wp_filesystem->delete($working_dir, true); | 
|---|
| 62 | return new WP_Error('copy_failed', $this->strings['copy_failed']); | 
|---|
| 63 | } | 
|---|
| 64 | $wp_filesystem->chmod($wp_dir . $update_xpress_file, FS_CHMOD_FILE); | 
|---|
| 65 |  | 
|---|
| 66 | require(ABSPATH . $update_xpress_file); | 
|---|
| 67 | return update_xpress($kit_dir, $wp_dir); | 
|---|
| 68 | } | 
|---|
| 69 | } | 
|---|
| 70 | ?> | 
|---|