PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

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