Make WordPress Core


Ignore:
Timestamp:
03/31/2011 01:28:36 PM (15 years ago)
Author:
dd32
Message:

Be a party-pooper; No more Akismet Dancing upon upgrade; Respect custom WP_CONTENT_DIR for bundled plugins/theme installation; Respect custom WP_CONTENT_DIR/WP_LANG_DIR for Language files when upgrading; Standardise WP_Filesystem path method returns (They're trailing slash'd). Adds an exclusion list to copy_dir() as well as WP_Filesystem_Base::wp_lang_dir(). See #14484 See #11495

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/update-core.php

    r17561 r17576  
    247247
    248248/**
     249 * Stores new files in wp-content to copy
     250 *
     251 * The contents of this array indicate any new bundled plugins/themes which
     252 * should be installed with the WordPress Upgrade. These items will not be
     253 * re-installed in future upgrades, this behaviour is controlled by the
     254 * introduced version present here being older than the current installed version.
     255 *
     256 * The content of this array should follow the following format:
     257 *  Filename (relative to wp-content) => Introduced version
     258 * Directories should be noted by suffixing it with a trailing slash (/)
     259 *
     260 * @since 3.2
     261 * @global array $_new_bundled_files
     262 * @var array
     263 * @name $_new_bundled_files
     264 */
     265global $_new_bundled_files;
     266
     267$_new_bundled_files = array(
     268'plugins/akismet/' => '2.0',
     269'themes/twentyten/' => '3.2',
     270);
     271
     272/**
    249273 * Upgrade the core of WordPress.
    250274 *
     
    255279 * The files in the {@link $_old_files} list will be removed and the new files
    256280 * copied from the zip file after the database is upgraded.
     281 *
     282 * The files in the {@link $_new_bundled_files} list will be added to the installation
     283 * if the version is greater than or equal to the old version being upgraded.
    257284 *
    258285 * The steps for the upgrader for after the new release is downloaded and
     
    262289 *   3. Copy new WordPress directory over old WordPress files.
    263290 *   4. Upgrade WordPress to new version.
     291 *     4.1. Copy all files/folders other than wp-content
     292 *     4.2. Copy any language files to WP_LANG_DIR (which may differ from WP_CONTENT_DIR
     293 *     4.3. Copy any new bundled themes/plugins to their respective locations
    264294 *   5. Delete new WordPress directory path.
    265295 *   6. Delete .maintenance file.
     
    287317 */
    288318function update_core($from, $to) {
    289         global $wp_filesystem, $_old_files, $wpdb;
     319        global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;
    290320
    291321        @set_time_limit( 300 );
     
    312342        apply_filters('update_feedback', __('Verifying the unpacked files…'));
    313343        $distro = '';
    314         $roots = array( '/wordpress', '/wordpress-mu' );
     344        $roots = array( '/wordpress/', '/wordpress-mu/' );
    315345        foreach( $roots as $root ) {
    316                 if ( $wp_filesystem->exists($from . $root . '/wp-settings.php') && $wp_filesystem->exists($from . $root . '/wp-admin/admin.php') &&
    317                         $wp_filesystem->exists($from . $root . '/wp-includes/functions.php') ) {
     346                if ( $wp_filesystem->exists($from . $root . 'wp-settings.php') && $wp_filesystem->exists($from . $root . 'wp-admin/admin.php') &&
     347                        $wp_filesystem->exists($from . $root . 'wp-includes/functions.php') ) {
    318348                        $distro = $root;
    319349                        break;
     
    334364
    335365        // Copy new versions of WP files into place.
    336         $result = copy_dir($from . $distro, $to);
     366        $result = copy_dir($from . $distro, $to, array('wp-content') );
     367
     368        // Custom Content Directory needs updating now.
     369        // Copy Languages
     370        if ( !is_wp_error($result) && $wp_filesystem->is_dir($from . $distro . 'wp-content/languages') ) {
     371                if ( !@is_dir(WP_LANG_DIR) && 0 === strpos(WP_LANG_DIR, ABSPATH) ) { // Check the language directory exists first
     372                        $wp_filesystem->mkdir($to . str_replace(WP_LANG_DIR, ABSPATH, ''), FS_CHMOD_DIR); // If it's within the ABSPATH we can handle it here, otherwise they're out of luck.
     373                        clearstatcache(); // for FTP, Need to clear the stat cache
     374                }
     375
     376                if ( @is_dir(WP_LANG_DIR) ) {
     377                        $wp_lang_dir = $wp_filesystem->wp_lang_dir();
     378                        $result = copy_dir($from . $distro . 'wp-content/languages/', $wp_lang_dir);
     379                }
     380        }
     381
     382        // Copy New bundled plugins & themes
     383        // This gives us the ability to install new plugins & themes bundled with future versions of WordPress whilst avoiding the re-install upon upgrade issue.
     384        if ( !is_wp_error($result) && ( ! defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
     385                $old_version = $GLOBALS['wp_version']; // $wp_version in local scope == new version
     386                foreach ( (array) $_new_bundled_files as $file => $introduced_version ) {
     387                        // If $introduced version is greater than what the site was previously running
     388                        if ( version_compare($introduced_version, $old_version, '>') ) {
     389                                $directory = ('/' == $file[ strlen($file)-1 ]);
     390                                list($type, $filename) = explode('/', $file, 2);
     391                                if ( 'plugins' == $type )
     392                                        $dest = $wp_filesystem->wp_plugins_dir();
     393                                elseif ( 'themes' == $type )
     394                                        $dest = $wp_filesystem->wp_themes_dir();
     395
     396                                if ( ! $directory ) {
     397                                        if ( $wp_filesystem->exists($dest . '/' . $filename) )
     398                                                continue;
     399
     400                                        if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . '/' . $filename, FS_CHMOD_FILE) )
     401                                                $result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . '/' . $filename);
     402                                } else {
     403                                        if ( $wp_filesystem->is_dir($dest . '/' . $filename) )
     404                                                continue;
     405
     406                                        $wp_filesystem->mkdir($dest . $filename, FS_CHMOD_DIR);
     407                                        $_result = copy_dir( $from . $distro . 'wp-content/' . $file, $dest . $filename);
     408                                        if ( is_wp_error($_result) ) //If a error occurs partway through this final step, keep the error flowing through, but keep process going.
     409                                                $result = $_result;
     410                                }
     411                        }
     412                } //end foreach
     413        }
     414
     415        // Handle $result error from the above blocks
    337416        if ( is_wp_error($result) ) {
    338417                $wp_filesystem->delete($maintenance_file);
Note: See TracChangeset for help on using the changeset viewer.