| | 191 | function wp_update_core($feedback = '') { |
| | 192 | global $wp_filesystem; |
| | 193 | |
| | 194 | if ( !empty($feedback) ) |
| | 195 | add_filter('update_feedback', $feedback); |
| | 196 | |
| | 197 | // Is an update available? |
| | 198 | $current = get_option( 'update_core' ); |
| | 199 | //if ( !isset( $current->response ) || $current->response != 'upgrade' ) |
| | 200 | // return new WP_Error('up_to_date', __('WordPress is at the latest version.')); |
| | 201 | |
| | 202 | // Is a filesystem accessor setup? |
| | 203 | if ( ! $wp_filesystem || ! is_object($wp_filesystem) ) |
| | 204 | WP_Filesystem(); |
| | 205 | |
| | 206 | if ( ! is_object($wp_filesystem) ) |
| | 207 | return new WP_Error('fs_unavailable', __('Could not access filesystem.')); |
| | 208 | |
| | 209 | if ( $wp_filesystem->errors->get_error_code() ) |
| | 210 | return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); |
| | 211 | |
| | 212 | // Get the base WP folder |
| | 213 | $wp_dir = $wp_filesystem->abspath(); |
| | 214 | if ( empty($wp_dir) ) |
| | 215 | return new WP_Error('fs_no_wp_dir', __('Unable to locate WordPress directory.')); |
| | 216 | |
| | 217 | // And the same for the Content directory. |
| | 218 | $content_dir = $wp_filesystem->wp_content_dir(); |
| | 219 | if( empty($content_dir) ) |
| | 220 | return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).')); |
| | 221 | |
| | 222 | $wp_dir = trailingslashit( $wp_dir ); |
| | 223 | $content_dir = trailingslashit( $content_dir ); |
| | 224 | |
| | 225 | // Get the URL to the zip file |
| | 226 | //$pacakge = "http://wordpress.org/wordpress-{$current->current}.zip"; |
| | 227 | $package = "http://wordpress.org/wordpress-2.6.zip"; |
| | 228 | |
| | 229 | // Download the package |
| | 230 | apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); |
| | 231 | $download_file = download_url($package); |
| | 232 | |
| | 233 | if ( is_wp_error($download_file) ) |
| | 234 | return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message()); |
| | 235 | |
| | 236 | $working_dir = $content_dir . 'upgrade/core'; |
| | 237 | |
| | 238 | // Clean up working directory |
| | 239 | if ( $wp_filesystem->is_dir($working_dir) ) |
| | 240 | $wp_filesystem->delete($working_dir, true); |
| | 241 | |
| | 242 | apply_filters('update_feedback', __('Unpacking the update')); |
| | 243 | // Unzip package to working directory |
| | 244 | $result = unzip_file($download_file, $working_dir); |
| | 245 | |
| | 246 | // Once extracted, delete the package |
| | 247 | unlink($download_file); |
| | 248 | |
| | 249 | if ( is_wp_error($result) ) { |
| | 250 | $wp_filesystem->delete($working_dir, true); |
| | 251 | return $result; |
| | 252 | } |
| | 253 | |
| | 254 | apply_filters('update_feedback', __('Installing the latest version')); |
| | 255 | // Copy new versions of WP files into place. |
| | 256 | $result = copy_dir($working_dir . '/wordpress', $wp_dir); |
| | 257 | if ( is_wp_error($result) ) { |
| | 258 | //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. |
| | 259 | return $result; |
| | 260 | } |
| | 261 | |
| | 262 | // Might have to do upgrade in a separate step. |
| | 263 | apply_filters('update_feedback', __('Upgrading database')); |
| | 264 | // Get new db version |
| | 265 | global $wp_db_version; |
| | 266 | require (ABSPATH . WPINC . '/version.php'); |
| | 267 | // Upgrade db |
| | 268 | define('WP_INSTALLING', true); |
| | 269 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| | 270 | wp_upgrade(); |
| | 271 | |
| | 272 | // Remove working directory |
| | 273 | $wp_filesystem->delete($working_dir, true); |
| | 274 | |
| | 275 | // Force refresh of update information |
| | 276 | delete_option('update_core'); |
| | 277 | } |
| | 278 | |