diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php
index 2cae7da03..85ff48ab0 100644
--- a/wp-admin/includes/file.php
+++ b/wp-admin/includes/file.php
@@ -408,8 +408,10 @@ function copy_dir($from, $to) {
return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename);
$wp_filesystem->chmod($to . $filename, 0644);
} elseif ( 'd' == $fileinfo['type'] ) {
- if ( !$wp_filesystem->mkdir($to . $filename, 0755) )
- return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename);
+ if ( !$wp_filesystem->is_dir($to . $filename) ) {
+ if ( !$wp_filesystem->mkdir($to . $filename, 0755) )
+ return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename);
+ }
$result = copy_dir($from . $filename, $to . $filename);
if ( is_wp_error($result) )
return $result;
diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php
new file mode 100644
index 000000000..60b0b8862
--- /dev/null
+++ b/wp-admin/includes/update-core.php
@@ -0,0 +1,50 @@
+delete($from, true);
+ return new WP_Error('insane_distro', __('The update could not be unpacked') );
+ }
+
+ apply_filters('update_feedback', __('Installing the latest version'));
+
+ // Create maintenance file to signal that we are upgrading
+ $maintenance_string = '';
+ $maintenance_file = $to . '.maintenance';
+ $wp_filesystem->delete($maintenance_file);
+ $wp_filesystem->put_contents($maintenance_file, $maintenance_string, 0644);
+
+ // Copy new versions of WP files into place.
+ $result = copy_dir($from . '/wordpress', $to);
+ if ( is_wp_error($result) ) {
+ $wp_filesystem->delete($maintenance_file);
+ //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
+ return $result;
+ }
+
+ // Might have to do upgrade in a separate step.
+ apply_filters('update_feedback', __('Upgrading database'));
+ // Get new db version
+ global $wp_db_version;
+ require (ABSPATH . WPINC . '/version.php');
+ // Upgrade db
+ define('WP_INSTALLING', true);
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
+ wp_upgrade();
+
+ // Remove working directory
+ $wp_filesystem->delete($from, true);
+
+ // Remove maintenance file, we're done.
+ $wp_filesystem->delete($maintenance_file);
+
+ // Force refresh of update information
+ delete_option('update_core');
+}
+
+?>
\ No newline at end of file
diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php
index fbc64a31e..3edfa702b 100644
--- a/wp-admin/includes/update.php
+++ b/wp-admin/includes/update.php
@@ -15,18 +15,18 @@ function core_update_footer( $msg = '' ) {
switch ( $cur->response ) {
case 'development' :
- return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please stay updated.' ), $GLOBALS['wp_version'], $cur->url, $cur->current );
+ return sprintf( '| '.__( 'You are using a development version (%1$s). Cool! Please stay updated.' ), $GLOBALS['wp_version'], wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core'));
break;
case 'upgrade' :
if ( current_user_can('manage_options') ) {
- return sprintf( '| '.__( 'Get Version %3$s' ).'', $GLOBALS['wp_version'], $cur->url, $cur->current );
+ return sprintf( '| '.__( 'Get Version %2$s' ).'', wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core'), $cur->current);
break;
}
case 'latest' :
default :
- return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'], $cur->url, $cur->current );
+ return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
break;
}
}
@@ -39,9 +39,9 @@ function update_nag() {
return false;
if ( current_user_can('manage_options') )
- $msg = sprintf( __('WordPress %2$s is available! Please update now.'), $cur->url, $cur->current );
+ $msg = sprintf( __('WordPress %1$s is available! Please update now.'), $cur->current, wp_nonce_url('update.php?action=upgrade-core', 'upgrade-core') );
else
- $msg = sprintf( __('WordPress %2$s is available! Please notify the site administrator.'), $cur->url, $cur->current );
+ $msg = sprintf( __('WordPress %1$s is available! Please notify the site administrator.'), $cur->current );
echo "
$msg
";
}
@@ -53,7 +53,7 @@ function update_right_now_message() {
$msg = sprintf( __('This is WordPress version %s.'), $GLOBALS['wp_version'] );
if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') )
- $msg .= " " . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '';
+ $msg .= " " . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '';
echo "$msg";
}
@@ -193,4 +193,77 @@ function wp_update_plugin($plugin, $feedback = '') {
return $folder . '/' . $pluginfiles[0];
}
+function wp_update_core($feedback = '') {
+ global $wp_filesystem;
+
+ if ( !empty($feedback) )
+ add_filter('update_feedback', $feedback);
+
+ // Is an update available?
+ $current = get_option( 'update_core' );
+ if ( !isset( $current->response ) || $current->response == 'latest' )
+ return new WP_Error('up_to_date', __('WordPress is at the latest version.'));
+
+ // Is a filesystem accessor setup?
+ if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
+ WP_Filesystem();
+
+ if ( ! is_object($wp_filesystem) )
+ return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
+
+ if ( $wp_filesystem->errors->get_error_code() )
+ return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
+
+ // Get the base WP folder
+ $wp_dir = $wp_filesystem->abspath();
+ if ( empty($wp_dir) )
+ return new WP_Error('fs_no_wp_dir', __('Unable to locate WordPress directory.'));
+
+ // And the same for the Content directory.
+ $content_dir = $wp_filesystem->wp_content_dir();
+ if( empty($content_dir) )
+ return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
+
+ $wp_dir = trailingslashit( $wp_dir );
+ $content_dir = trailingslashit( $content_dir );
+
+ // Get the URL to the zip file
+ $package = $current->package;
+
+ // Download the package
+ apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
+ $download_file = download_url($package);
+
+ if ( is_wp_error($download_file) )
+ return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());
+
+ $working_dir = $content_dir . 'upgrade/core';
+
+ // Clean up working directory
+ if ( $wp_filesystem->is_dir($working_dir) )
+ $wp_filesystem->delete($working_dir, true);
+
+ apply_filters('update_feedback', __('Unpacking the update'));
+ // Unzip package to working directory
+ $result = unzip_file($download_file, $working_dir);
+
+ // Once extracted, delete the package
+ unlink($download_file);
+
+ if ( is_wp_error($result) ) {
+ $wp_filesystem->delete($working_dir, true);
+ return $result;
+ }
+
+ // Copy update-core.php from the new version into place.
+ if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
+ $wp_filesystem->delete($working_dir, true);
+ return new WP_Error('copy_failed', __('Could not copy files'));
+ }
+
+ require(ABSPATH . 'wp-admin/includes/update-core.php');
+
+ return update_core($working_dir, $wp_dir);
+}
+
?>
diff --git a/wp-admin/update.php b/wp-admin/update.php
index b01e1d44e..d25b4c539 100644
--- a/wp-admin/update.php
+++ b/wp-admin/update.php
@@ -44,6 +44,39 @@ function do_plugin_upgrade($plugin) {
echo '';
}
+function do_core_upgrade() {
+ global $wp_filesystem;
+
+ $url = wp_nonce_url("update.php?action=upgrade-core", "upgrade-core");
+ if ( false === ($credentials = request_filesystem_credentials($url)) )
+ return;
+
+ if ( ! WP_Filesystem($credentials) ) {
+ request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
+ return;
+ }
+
+ echo '';
+ echo '
' . __('Upgrade WordPress') . '
';
+ if ( $wp_filesystem->errors->get_error_code() ) {
+ foreach ( $wp_filesystem->errors->get_error_messages() as $message )
+ show_message($message);
+ echo '';
+ return;
+ }
+
+ $result = wp_update_core('show_message');
+
+ if ( is_wp_error($result) ) {
+ show_message($result);
+ if ('up_to_date' != $result->get_error_code() )
+ show_message( __('Installation Failed') );
+ } else {
+ show_message( __('WordPress upgraded successfully') );
+ }
+ echo '';
+}
+
if ( isset($_GET['action']) ) {
$plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : '';
@@ -84,6 +117,13 @@ wp_admin_css( 'colors', true );
include(WP_PLUGIN_DIR . '/' . $plugin);
}
echo "