PageRenderTime 45ms CodeModel.GetById 24ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/includes/update-core.php

https://github.com/wowfrank/WordPress
PHP | 651 lines | 480 code | 43 blank | 128 comment | 54 complexity | 4551f0623b79e1b721029de306b08dd0 MD5 | raw file
  1<?php
  2/**
  3 * WordPress core upgrade functionality.
  4 *
  5 * @package WordPress
  6 * @subpackage Administration
  7 * @since 2.7.0
  8 */
  9
 10/**
 11 * Stores files to be deleted.
 12 *
 13 * @since 2.7.0
 14 * @global array $_old_files
 15 * @var array
 16 * @name $_old_files
 17 */
 18global $_old_files;
 19
 20$_old_files = array(
 21'wp-admin/bookmarklet.php',
 22'wp-admin/css/upload.css',
 23'wp-admin/css/upload-rtl.css',
 24'wp-admin/css/press-this-ie.css',
 25'wp-admin/css/press-this-ie-rtl.css',
 26'wp-admin/edit-form.php',
 27'wp-admin/link-import.php',
 28'wp-admin/images/box-bg-left.gif',
 29'wp-admin/images/box-bg-right.gif',
 30'wp-admin/images/box-bg.gif',
 31'wp-admin/images/box-butt-left.gif',
 32'wp-admin/images/box-butt-right.gif',
 33'wp-admin/images/box-butt.gif',
 34'wp-admin/images/box-head-left.gif',
 35'wp-admin/images/box-head-right.gif',
 36'wp-admin/images/box-head.gif',
 37'wp-admin/images/heading-bg.gif',
 38'wp-admin/images/login-bkg-bottom.gif',
 39'wp-admin/images/login-bkg-tile.gif',
 40'wp-admin/images/notice.gif',
 41'wp-admin/images/toggle.gif',
 42'wp-admin/images/comment-stalk-classic.gif',
 43'wp-admin/images/comment-stalk-fresh.gif',
 44'wp-admin/images/comment-stalk-rtl.gif',
 45'wp-admin/images/comment-pill.gif',
 46'wp-admin/images/del.png',
 47'wp-admin/images/media-button-gallery.gif',
 48'wp-admin/images/media-buttons.gif',
 49'wp-admin/images/tail.gif',
 50'wp-admin/images/gear.png',
 51'wp-admin/images/tab.png',
 52'wp-admin/images/postbox-bg.gif',
 53'wp-admin/includes/upload.php',
 54'wp-admin/js/dbx-admin-key.js',
 55'wp-admin/js/link-cat.js',
 56'wp-admin/js/forms.js',
 57'wp-admin/js/upload.js',
 58'wp-admin/js/set-post-thumbnail-handler.js',
 59'wp-admin/js/set-post-thumbnail-handler.dev.js',
 60'wp-admin/js/page.js',
 61'wp-admin/js/page.dev.js',
 62'wp-admin/js/slug.js',
 63'wp-admin/js/slug.dev.js',
 64'wp-admin/profile-update.php',
 65'wp-admin/templates.php',
 66'wp-includes/images/audio.png',
 67'wp-includes/images/css.png',
 68'wp-includes/images/default.png',
 69'wp-includes/images/doc.png',
 70'wp-includes/images/exe.png',
 71'wp-includes/images/html.png',
 72'wp-includes/images/js.png',
 73'wp-includes/images/pdf.png',
 74'wp-includes/images/swf.png',
 75'wp-includes/images/tar.png',
 76'wp-includes/images/text.png',
 77'wp-includes/images/video.png',
 78'wp-includes/images/zip.png',
 79'wp-includes/js/dbx.js',
 80'wp-includes/js/fat.js',
 81'wp-includes/js/list-manipulation.js',
 82'wp-includes/js/jquery/jquery.dimensions.min.js',
 83'wp-includes/js/tinymce/langs/en.js',
 84'wp-includes/js/tinymce/plugins/autosave/editor_plugin_src.js',
 85'wp-includes/js/tinymce/plugins/autosave/langs',
 86'wp-includes/js/tinymce/plugins/directionality/images',
 87'wp-includes/js/tinymce/plugins/directionality/langs',
 88'wp-includes/js/tinymce/plugins/inlinepopups/css',
 89'wp-includes/js/tinymce/plugins/inlinepopups/images',
 90'wp-includes/js/tinymce/plugins/inlinepopups/jscripts',
 91'wp-includes/js/tinymce/plugins/paste/images',
 92'wp-includes/js/tinymce/plugins/paste/jscripts',
 93'wp-includes/js/tinymce/plugins/paste/langs',
 94'wp-includes/js/tinymce/plugins/spellchecker/classes/HttpClient.class.php',
 95'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyGoogleSpell.class.php',
 96'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspell.class.php',
 97'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspellShell.class.php',
 98'wp-includes/js/tinymce/plugins/spellchecker/css/spellchecker.css',
 99'wp-includes/js/tinymce/plugins/spellchecker/images',
100'wp-includes/js/tinymce/plugins/spellchecker/langs',
101'wp-includes/js/tinymce/plugins/spellchecker/tinyspell.php',
102'wp-includes/js/tinymce/plugins/wordpress/images',
103'wp-includes/js/tinymce/plugins/wordpress/langs',
104'wp-includes/js/tinymce/plugins/wordpress/popups.css',
105'wp-includes/js/tinymce/plugins/wordpress/wordpress.css',
106'wp-includes/js/tinymce/plugins/wphelp',
107'wp-includes/js/tinymce/themes/advanced/css',
108'wp-includes/js/tinymce/themes/advanced/images',
109'wp-includes/js/tinymce/themes/advanced/jscripts',
110'wp-includes/js/tinymce/themes/advanced/langs',
111'wp-includes/js/tinymce/tiny_mce_gzip.php',
112'wp-includes/js/wp-ajax.js',
113'wp-admin/admin-db.php',
114'wp-admin/cat.js',
115'wp-admin/categories.js',
116'wp-admin/custom-fields.js',
117'wp-admin/dbx-admin-key.js',
118'wp-admin/edit-comments.js',
119'wp-admin/install-rtl.css',
120'wp-admin/install.css',
121'wp-admin/upgrade-schema.php',
122'wp-admin/upload-functions.php',
123'wp-admin/upload-rtl.css',
124'wp-admin/upload.css',
125'wp-admin/upload.js',
126'wp-admin/users.js',
127'wp-admin/widgets-rtl.css',
128'wp-admin/widgets.css',
129'wp-admin/xfn.js',
130'wp-includes/js/tinymce/license.html',
131'wp-admin/cat-js.php',
132'wp-admin/edit-form-ajax-cat.php',
133'wp-admin/execute-pings.php',
134'wp-admin/import/b2.php',
135'wp-admin/import/btt.php',
136'wp-admin/import/jkw.php',
137'wp-admin/inline-uploading.php',
138'wp-admin/link-categories.php',
139'wp-admin/list-manipulation.js',
140'wp-admin/list-manipulation.php',
141'wp-includes/comment-functions.php',
142'wp-includes/feed-functions.php',
143'wp-includes/functions-compat.php',
144'wp-includes/functions-formatting.php',
145'wp-includes/functions-post.php',
146'wp-includes/js/dbx-key.js',
147'wp-includes/js/tinymce/plugins/autosave/langs/cs.js',
148'wp-includes/js/tinymce/plugins/autosave/langs/sv.js',
149'wp-includes/js/tinymce/themes/advanced/editor_template_src.js',
150'wp-includes/links.php',
151'wp-includes/pluggable-functions.php',
152'wp-includes/template-functions-author.php',
153'wp-includes/template-functions-category.php',
154'wp-includes/template-functions-general.php',
155'wp-includes/template-functions-links.php',
156'wp-includes/template-functions-post.php',
157'wp-includes/wp-l10n.php',
158'wp-admin/import-b2.php',
159'wp-admin/import-blogger.php',
160'wp-admin/import-greymatter.php',
161'wp-admin/import-livejournal.php',
162'wp-admin/import-mt.php',
163'wp-admin/import-rss.php',
164'wp-admin/import-textpattern.php',
165'wp-admin/quicktags.js',
166'wp-images/fade-butt.png',
167'wp-images/get-firefox.png',
168'wp-images/header-shadow.png',
169'wp-images/smilies',
170'wp-images/wp-small.png',
171'wp-images/wpminilogo.png',
172'wp.php',
173'wp-includes/gettext.php',
174'wp-includes/streams.php',
175// MU
176'wp-admin/wpmu-admin.php',
177'wp-admin/wpmu-blogs.php',
178'wp-admin/wpmu-edit.php',
179'wp-admin/wpmu-options.php',
180'wp-admin/wpmu-themes.php',
181'wp-admin/wpmu-upgrade-site.php',
182'wp-admin/wpmu-users.php',
183'wp-includes/wpmu-default-filters.php',
184'wp-includes/wpmu-functions.php',
185'wpmu-settings.php',
186'index-install.php',
187'README.txt',
188'htaccess.dist',
189'wp-admin/css/mu-rtl.css',
190'wp-admin/css/mu.css',
191'wp-admin/images/site-admin.png',
192'wp-admin/includes/mu.php',
193'wp-includes/images/wordpress-mu.png',
194// 3.0
195'wp-admin/categories.php',
196'wp-admin/edit-category-form.php',
197'wp-admin/edit-page-form.php',
198'wp-admin/edit-pages.php',
199'wp-admin/images/wp-logo.gif',
200'wp-admin/js/wp-gears.dev.js',
201'wp-admin/js/wp-gears.js',
202'wp-admin/options-misc.php',
203'wp-admin/page-new.php',
204'wp-admin/page.php',
205'wp-admin/rtl.css',
206'wp-admin/rtl.dev.css',
207'wp-admin/update-links.php',
208'wp-admin/wp-admin.css',
209'wp-admin/wp-admin.dev.css',
210'wp-includes/js/codepress',
211'wp-includes/js/jquery/autocomplete.dev.js',
212'wp-includes/js/jquery/interface.js',
213'wp-includes/js/jquery/autocomplete.js',
214'wp-includes/js/scriptaculous/prototype.js',
215'wp-includes/js/tinymce/wp-tinymce.js',
216'wp-admin/import',
217'wp-admin/images/ico-edit.png',
218'wp-admin/images/fav-top.png',
219'wp-admin/images/ico-close.png',
220'wp-admin/images/admin-header-footer.png',
221'wp-admin/images/screen-options-left.gif',
222'wp-admin/images/ico-add.png',
223'wp-admin/images/browse-happy.gif',
224'wp-admin/images/ico-viewpage.png',
225// 3.1
226'wp-includes/js/tinymce/blank.htm',
227'wp-includes/js/tinymce/plugins/safari',
228'wp-admin/edit-link-categories.php',
229'wp-admin/edit-post-rows.php',
230'wp-admin/edit-attachment-rows.php',
231'wp-admin/link-category.php',
232'wp-admin/edit-link-category-form.php',
233'wp-admin/sidebar.php',
234'wp-admin/images/list-vs.png',
235'wp-admin/images/button-grad-vs.png',
236'wp-admin/images/button-grad-active-vs.png',
237'wp-admin/images/fav-arrow-vs.gif',
238'wp-admin/images/fav-arrow-vs-rtl.gif',
239'wp-admin/images/fav-top-vs.gif',
240'wp-admin/images/screen-options-right.gif',
241'wp-admin/images/screen-options-right-up.gif',
242'wp-admin/images/visit-site-button-grad-vs.gif',
243'wp-admin/images/visit-site-button-grad.gif',
244'wp-includes/classes.php',
245// 3.2
246'wp-includes/default-embeds.php',
247'wp-includes/js/tinymce/plugins/media/img',
248'wp-includes/js/tinymce/plugins/wordpress/img/more.gif',
249'wp-includes/js/tinymce/plugins/wordpress/img/toolbars.gif',
250'wp-includes/js/tinymce/plugins/wordpress/img/help.gif',
251'wp-includes/js/tinymce/themes/advanced/img/fm.gif',
252'wp-includes/js/tinymce/themes/advanced/img/sflogo.png',
253'wp-admin/js/list-table.js',
254'wp-admin/js/list-table.dev.js',
255'wp-admin/images/logo-login.gif',
256'wp-admin/images/star.gif',
257// 3.3
258'wp-admin/css/colors-classic-rtl.css',
259'wp-admin/css/colors-classic-rtl.dev.css',
260'wp-admin/css/colors-fresh-rtl.css',
261'wp-admin/css/colors-fresh-rtl.dev.css',
262'wp-admin/css/dashboard-rtl.css',
263'wp-admin/css/dashboard-rtl.dev.css',
264'wp-admin/css/dashboard.css',
265'wp-admin/css/dashboard.dev.css',
266'wp-admin/css/farbtastic-rtl.css',
267'wp-admin/css/global-rtl.css',
268'wp-admin/css/global-rtl.dev.css',
269'wp-admin/css/global.css',
270'wp-admin/css/global.dev.css',
271'wp-admin/css/install-rtl.css',
272'wp-admin/css/install-rtl.dev.css',
273'wp-admin/css/login-rtl.css',
274'wp-admin/css/login-rtl.dev.css',
275'wp-admin/css/login.css',
276'wp-admin/css/login.dev.css',
277'wp-admin/css/ms.css',
278'wp-admin/css/ms.dev.css',
279'wp-admin/css/nav-menu-rtl.css',
280'wp-admin/css/nav-menu-rtl.dev.css',
281'wp-admin/css/nav-menu.css',
282'wp-admin/css/nav-menu.dev.css',
283'wp-admin/css/plugin-install-rtl.css',
284'wp-admin/css/plugin-install-rtl.dev.css',
285'wp-admin/css/plugin-install.css',
286'wp-admin/css/plugin-install.dev.css',
287'wp-admin/css/press-this-rtl.css',
288'wp-admin/css/press-this-rtl.dev.css',
289'wp-admin/css/press-this.css',
290'wp-admin/css/press-this.dev.css',
291'wp-admin/css/theme-editor-rtl.css',
292'wp-admin/css/theme-editor-rtl.dev.css',
293'wp-admin/css/theme-editor.css',
294'wp-admin/css/theme-editor.dev.css',
295'wp-admin/css/theme-install-rtl.css',
296'wp-admin/css/theme-install-rtl.dev.css',
297'wp-admin/css/theme-install.css',
298'wp-admin/css/theme-install.dev.css',
299'wp-admin/css/widgets-rtl.css',
300'wp-admin/css/widgets-rtl.dev.css',
301'wp-admin/css/widgets.css',
302'wp-admin/css/widgets.dev.css',
303'wp-admin/includes/internal-linking.php',
304'wp-includes/images/admin-bar-sprite-rtl.png',
305'wp-includes/js/jquery/ui.button.js',
306'wp-includes/js/jquery/ui.core.js',
307'wp-includes/js/jquery/ui.dialog.js',
308'wp-includes/js/jquery/ui.draggable.js',
309'wp-includes/js/jquery/ui.droppable.js',
310'wp-includes/js/jquery/ui.mouse.js',
311'wp-includes/js/jquery/ui.position.js',
312'wp-includes/js/jquery/ui.resizable.js',
313'wp-includes/js/jquery/ui.selectable.js',
314'wp-includes/js/jquery/ui.sortable.js',
315'wp-includes/js/jquery/ui.tabs.js',
316'wp-includes/js/jquery/ui.widget.js',
317'wp-includes/js/l10n.dev.js',
318'wp-includes/js/l10n.js',
319'wp-includes/js/tinymce/plugins/wplink/css',
320'wp-includes/js/tinymce/plugins/wplink/img',
321'wp-includes/js/tinymce/plugins/wplink/js',
322'wp-includes/js/tinymce/themes/advanced/img/wpicons.png',
323'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/butt2.png',
324'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/button_bg.png',
325'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/down_arrow.gif',
326'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/fade-butt.png',
327'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/separator.gif',
328// 3.4
329'wp-admin/images/logo-login.png',
330'wp-admin/index-extra.php',
331'wp-admin/network/index-extra.php',
332'wp-admin/user/index-extra.php',
333);
334
335/**
336 * Stores new files in wp-content to copy
337 *
338 * The contents of this array indicate any new bundled plugins/themes which
339 * should be installed with the WordPress Upgrade. These items will not be
340 * re-installed in future upgrades, this behaviour is controlled by the
341 * introduced version present here being older than the current installed version.
342 *
343 * The content of this array should follow the following format:
344 * Filename (relative to wp-content) => Introduced version
345 * Directories should be noted by suffixing it with a trailing slash (/)
346 *
347 * @since 3.2.0
348 * @global array $_new_bundled_files
349 * @var array
350 * @name $_new_bundled_files
351 */
352global $_new_bundled_files;
353
354$_new_bundled_files = array(
355'plugins/akismet/' => '2.0',
356'themes/twentyten/' => '3.0',
357'themes/twentyeleven/' => '3.2'
358);
359
360/**
361 * Upgrade the core of WordPress.
362 *
363 * This will create a .maintenance file at the base of the WordPress directory
364 * to ensure that people can not access the web site, when the files are being
365 * copied to their locations.
366 *
367 * The files in the {@link $_old_files} list will be removed and the new files
368 * copied from the zip file after the database is upgraded.
369 *
370 * The files in the {@link $_new_bundled_files} list will be added to the installation
371 * if the version is greater than or equal to the old version being upgraded.
372 *
373 * The steps for the upgrader for after the new release is downloaded and
374 * unzipped is:
375 *   1. Test unzipped location for select files to ensure that unzipped worked.
376 *   2. Create the .maintenance file in current WordPress base.
377 *   3. Copy new WordPress directory over old WordPress files.
378 *   4. Upgrade WordPress to new version.
379 *     4.1. Copy all files/folders other than wp-content
380 *     4.2. Copy any language files to WP_LANG_DIR (which may differ from WP_CONTENT_DIR
381 *     4.3. Copy any new bundled themes/plugins to their respective locations
382 *   5. Delete new WordPress directory path.
383 *   6. Delete .maintenance file.
384 *   7. Remove old files.
385 *   8. Delete 'update_core' option.
386 *
387 * There are several areas of failure. For instance if PHP times out before step
388 * 6, then you will not be able to access any portion of your site. Also, since
389 * the upgrade will not continue where it left off, you will not be able to
390 * automatically remove old files and remove the 'update_core' option. This
391 * isn't that bad.
392 *
393 * If the copy of the new WordPress over the old fails, then the worse is that
394 * the new WordPress directory will remain.
395 *
396 * If it is assumed that every file will be copied over, including plugins and
397 * themes, then if you edit the default theme, you should rename it, so that
398 * your changes remain.
399 *
400 * @since 2.7.0
401 *
402 * @param string $from New release unzipped path.
403 * @param string $to Path to old WordPress installation.
404 * @return WP_Error|null WP_Error on failure, null on success.
405 */
406function update_core($from, $to) {
407	global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;
408
409	@set_time_limit( 300 );
410
411	$php_version    = phpversion();
412	$mysql_version  = $wpdb->db_version();
413	$required_php_version = '5.2.4';
414	$required_mysql_version = '5.0';
415	$wp_version = '3.4';
416	$php_compat     = version_compare( $php_version, $required_php_version, '>=' );
417	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
418		$mysql_compat = true;
419	else
420		$mysql_compat = version_compare( $mysql_version, $required_mysql_version, '>=' );
421
422	if ( !$mysql_compat || !$php_compat )
423		$wp_filesystem->delete($from, true);
424
425	if ( !$mysql_compat && !$php_compat )
426		return new WP_Error( 'php_mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ) );
427	elseif ( !$php_compat )
428		return new WP_Error( 'php_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version ) );
429	elseif ( !$mysql_compat )
430		return new WP_Error( 'mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version ) );
431
432	// Sanity check the unzipped distribution
433	apply_filters('update_feedback', __('Verifying the unpacked files&#8230;'));
434	$distro = '';
435	$roots = array( '/wordpress/', '/wordpress-mu/' );
436	foreach( $roots as $root ) {
437		if ( $wp_filesystem->exists($from . $root . 'readme.html') && $wp_filesystem->exists($from . $root . 'wp-includes/version.php') ) {
438			$distro = $root;
439			break;
440		}
441	}
442	if ( !$distro ) {
443		$wp_filesystem->delete($from, true);
444		return new WP_Error('insane_distro', __('The update could not be unpacked') );
445	}
446
447	apply_filters('update_feedback', __('Installing the latest version&#8230;'));
448
449	// Create maintenance file to signal that we are upgrading
450	$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
451	$maintenance_file = $to . '.maintenance';
452	$wp_filesystem->delete($maintenance_file);
453	$wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
454
455	// Copy new versions of WP files into place.
456	$result = _copy_dir($from . $distro, $to, array('wp-content') );
457
458	// Custom Content Directory needs updating now.
459	// Copy Languages
460	if ( !is_wp_error($result) && $wp_filesystem->is_dir($from . $distro . 'wp-content/languages') ) {
461		if ( WP_LANG_DIR != ABSPATH . WPINC . '/languages' || @is_dir(WP_LANG_DIR) )
462			$lang_dir = WP_LANG_DIR;
463		else
464			$lang_dir = WP_CONTENT_DIR . '/languages';
465
466		if ( !@is_dir($lang_dir) && 0 === strpos($lang_dir, ABSPATH) ) { // Check the language directory exists first
467			$wp_filesystem->mkdir($to . str_replace(ABSPATH, '', $lang_dir), FS_CHMOD_DIR); // If it's within the ABSPATH we can handle it here, otherwise they're out of luck.
468			clearstatcache(); // for FTP, Need to clear the stat cache
469		}
470
471		if ( @is_dir($lang_dir) ) {
472			$wp_lang_dir = $wp_filesystem->find_folder($lang_dir);
473			if ( $wp_lang_dir )
474				$result = copy_dir($from . $distro . 'wp-content/languages/', $wp_lang_dir);
475		}
476	}
477
478	// Copy New bundled plugins & themes
479	// This gives us the ability to install new plugins & themes bundled with future versions of WordPress whilst avoiding the re-install upon upgrade issue.
480	if ( !is_wp_error($result) && ( ! defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
481		$old_version = $GLOBALS['wp_version']; // $wp_version in local scope == new version
482		foreach ( (array) $_new_bundled_files as $file => $introduced_version ) {
483			// If $introduced version is greater than what the site was previously running
484			if ( version_compare($introduced_version, $old_version, '>') ) {
485				$directory = ('/' == $file[ strlen($file)-1 ]);
486				list($type, $filename) = explode('/', $file, 2);
487
488				if ( 'plugins' == $type )
489					$dest = $wp_filesystem->wp_plugins_dir();
490				elseif ( 'themes' == $type )
491					$dest = trailingslashit($wp_filesystem->wp_themes_dir()); // Back-compat, ::wp_themes_dir() did not return trailingslash'd pre-3.2
492				else
493					continue;
494
495				if ( ! $directory ) {
496					if ( $wp_filesystem->exists($dest . $filename) )
497						continue;
498
499					if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE) )
500						$result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . $filename);
501				} else {
502					if ( $wp_filesystem->is_dir($dest . $filename) )
503						continue;
504
505					$wp_filesystem->mkdir($dest . $filename, FS_CHMOD_DIR);
506					$_result = copy_dir( $from . $distro . 'wp-content/' . $file, $dest . $filename);
507					if ( is_wp_error($_result) ) //If a error occurs partway through this final step, keep the error flowing through, but keep process going.
508						$result = $_result;
509				}
510			}
511		} //end foreach
512	}
513
514	// Handle $result error from the above blocks
515	if ( is_wp_error($result) ) {
516		$wp_filesystem->delete($maintenance_file);
517		$wp_filesystem->delete($from, true);
518		return $result;
519	}
520
521	// Remove old files
522	foreach ( $_old_files as $old_file ) {
523		$old_file = $to . $old_file;
524		if ( !$wp_filesystem->exists($old_file) )
525			continue;
526		$wp_filesystem->delete($old_file, true);
527	}
528
529	// Upgrade DB with separate request
530	apply_filters('update_feedback', __('Upgrading database&#8230;'));
531	$db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
532	wp_remote_post($db_upgrade_url, array('timeout' => 60));
533
534	// Remove working directory
535	$wp_filesystem->delete($from, true);
536
537	// Force refresh of update information
538	if ( function_exists('delete_site_transient') )
539		delete_site_transient('update_core');
540	else
541		delete_option('update_core');
542
543	// Remove maintenance file, we're done.
544	$wp_filesystem->delete($maintenance_file);
545
546	// If we made it this far:
547	do_action( '_core_updated_successfully', $wp_version );
548
549	return $wp_version;
550}
551
552/**
553 * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
554 * Assumes that WP_Filesystem() has already been called and setup.
555 *
556 * This is a temporary function for the 3.1 -> 3.2 upgrade only and will be removed in 3.3
557 *
558 * @ignore
559 * @since 3.2.0
560 * @see copy_dir()
561 *
562 * @param string $from source directory
563 * @param string $to destination directory
564 * @param array $skip_list a list of files/folders to skip copying
565 * @return mixed WP_Error on failure, True on success.
566 */
567function _copy_dir($from, $to, $skip_list = array() ) {
568	global $wp_filesystem;
569
570	$dirlist = $wp_filesystem->dirlist($from);
571
572	$from = trailingslashit($from);
573	$to = trailingslashit($to);
574
575	$skip_regex = '';
576	foreach ( (array)$skip_list as $key => $skip_file )
577		$skip_regex .= preg_quote($skip_file, '!') . '|';
578
579	if ( !empty($skip_regex) )
580		$skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
581
582	foreach ( (array) $dirlist as $filename => $fileinfo ) {
583		if ( !empty($skip_regex) )
584			if ( preg_match($skip_regex, $from . $filename) )
585				continue;
586
587		if ( 'f' == $fileinfo['type'] ) {
588			if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
589				// If copy failed, chmod file to 0644 and try again.
590				$wp_filesystem->chmod($to . $filename, 0644);
591				if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
592					return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
593			}
594		} elseif ( 'd' == $fileinfo['type'] ) {
595			if ( !$wp_filesystem->is_dir($to . $filename) ) {
596				if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
597					return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
598			}
599			$result = _copy_dir($from . $filename, $to . $filename, $skip_list);
600			if ( is_wp_error($result) )
601				return $result;
602		}
603	}
604	return true;
605}
606
607/**
608 * Redirect to the About WordPress page after a successful upgrade.
609 *
610 * This function is only needed when the existing install is older than 3.3.0 (3.4.0 for multisite).
611 *
612 * @since 3.3.0
613 *
614 */
615function _redirect_to_about_wordpress( $new_version ) {
616	global $wp_version, $pagenow, $action;
617
618	if ( is_multisite() ) {
619		// Change to self_admin_url().
620		if ( version_compare( $wp_version, '3.4-alpha', '>=' ) )
621			return;
622	} elseif ( version_compare( $wp_version, '3.3', '>=' ) ) {
623		return;
624	}
625
626	// Ensure we only run this on the update-core.php page. wp_update_core() could be called in other contexts.
627	if ( 'update-core.php' != $pagenow )
628		return;
629
630 	if ( 'do-core-upgrade' != $action && 'do-core-reinstall' != $action )
631 		return;
632
633	// Load the updated default text localization domain for new strings
634	load_default_textdomain();
635
636	// See do_core_upgrade()
637	show_message( __('WordPress updated successfully') );
638	show_message( '<span class="hide-if-no-js">' . sprintf( __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%s">here</a>.' ), $new_version, esc_url( self_admin_url( 'about.php?updated' ) ) ) . '</span>' );
639	show_message( '<span class="hide-if-js">' . sprintf( __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ), $new_version, esc_url( self_admin_url( 'about.php?updated' ) ) ) . '</span>' );
640	echo '</div>';
641	?>
642<script type="text/javascript">
643window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
644</script>
645	<?php
646
647	// Include admin-footer.php and exit
648	include(ABSPATH . 'wp-admin/admin-footer.php');
649	exit();
650}
651add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );