Make WordPress Core

Changeset 17576


Ignore:
Timestamp:
03/31/2011 01:28:36 PM (14 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

Location:
trunk/wp-admin/includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-filesystem-base.php

    r14810 r17576  
    8383     */
    8484    function wp_themes_dir() {
    85         return $this->wp_content_dir() . '/themes';
     85        return $this->wp_content_dir() . 'themes/';
     86    }
     87    /**
     88     * Returns the path on the remote filesystem of WP_LANG_DIR
     89     *
     90     * @since 3.2
     91     * @access public
     92     *
     93     * @return string The location of the remote path.
     94     */
     95    function wp_lang_dir() {
     96        return $this->find_folder(WP_LANG_DIR);
    8697    }
    8798
  • trunk/wp-admin/includes/file.php

    r17555 r17576  
    717717 * @param string $from source directory
    718718 * @param string $to destination directory
     719 * @param array $skip_list a list of files/folders to skip copying
    719720 * @return mixed WP_Error on failure, True on success.
    720721 */
    721 function copy_dir($from, $to) {
     722function copy_dir($from, $to, $skip_list = array() ) {
    722723    global $wp_filesystem;
    723724
     
    727728    $to = trailingslashit($to);
    728729
     730    $skip_regex = '';
     731    foreach ( (array)$skip_list as $key => $skip_file )
     732        $skip_regex .= preg_quote($skip_file, '!') . '|';
     733
     734    if ( !empty($skip_regex) )
     735        $skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
     736
    729737    foreach ( (array) $dirlist as $filename => $fileinfo ) {
     738        if ( !empty($skip_regex) )
     739            if ( preg_match($skip_regex, $from . $filename) )
     740                continue;
     741
    730742        if ( 'f' == $fileinfo['type'] ) {
    731743            if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
     
    740752                    return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
    741753            }
    742             $result = copy_dir($from . $filename, $to . $filename);
     754            $result = copy_dir($from . $filename, $to . $filename, $skip_list);
    743755            if ( is_wp_error($result) )
    744756                return $result;
  • 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.