+ $result = _copy_dir($from . $distro, $to, array('wp-content') );
+
+ // Custom Content Directory needs updating now.
+ // Copy Languages
+ if ( !is_wp_error($result) && $wp_filesystem->is_dir($from . $distro . 'wp-content/languages') ) {
+ if ( WP_LANG_DIR != ABSPATH . WPINC . '/languages' || @is_dir(WP_LANG_DIR) )
+ $lang_dir = WP_LANG_DIR;
+ else
+ $lang_dir = WP_CONTENT_DIR . '/languages';
+
+ if ( !@is_dir($lang_dir) && 0 === strpos($lang_dir, ABSPATH) ) { // Check the language directory exists first
+ $wp_filesystem->mkdir($to . str_replace($lang_dir, ABSPATH, ''), FS_CHMOD_DIR); // If it's within the ABSPATH we can handle it here, otherwise they're out of luck.
+ clearstatcache(); // for FTP, Need to clear the stat cache
+ }
+
+ if ( @is_dir($lang_dir) ) {
+ $wp_lang_dir = $wp_filesystem->find_folder($lang_dir);
+ if ( $wp_lang_dir )
+ $result = copy_dir($from . $distro . 'wp-content/languages/', $wp_lang_dir);
+ }
+ }
+
+ // Copy New bundled plugins & themes
+ // This gives us the ability to install new plugins & themes bundled with future versions of WordPress whilst avoiding the re-install upon upgrade issue.
+ if ( !is_wp_error($result) && ( ! defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
+ $old_version = $GLOBALS['wp_version']; // $wp_version in local scope == new version
+ foreach ( (array) $_new_bundled_files as $file => $introduced_version ) {
+ // If $introduced version is greater than what the site was previously running
+ if ( version_compare($introduced_version, $old_version, '>') ) {
+ $directory = ('/' == $file[ strlen($file)-1 ]);
+ list($type, $filename) = explode('/', $file, 2);
+
+ if ( 'plugins' == $type )
+ $dest = $wp_filesystem->wp_plugins_dir();
+ elseif ( 'themes' == $type )
+ $dest = trailingslashit($wp_filesystem->wp_themes_dir()); // Back-compat, ::wp_themes_dir() did not return trailingslash'd pre-3.2
+ else
+ continue;
+
+ if ( ! $directory ) {
+ if ( $wp_filesystem->exists($dest . $filename) )
+ continue;
+
+ if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE) )
+ $result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . $filename);
+ } else {
+ if ( $wp_filesystem->is_dir($dest . $filename) )
+ continue;
+
+ $wp_filesystem->mkdir($dest . $filename, FS_CHMOD_DIR);
+ $_result = copy_dir( $from . $distro . 'wp-content/' . $file, $dest . $filename);
+ if ( is_wp_error($_result) ) //If a error occurs partway through this final step, keep the error flowing through, but keep process going.
+ $result = $_result;
+ }
+ }
+ } //end foreach
+ }
+
+ // Handle $result error from the above blocks