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