Make WordPress Core

Changeset 25057


Ignore:
Timestamp:
08/20/2013 06:46:37 AM (13 years ago)
Author:
dd32
Message:

WP_Filesystem: Use the FTP_* path override constants during upgrades for prefixed paths, ie. use FTP_BASE for ABSPATH/sub-dir as well as just for ABSPATH/. Props vericgar for initial patch. See #14401

File:
1 edited

Legend:

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

    r25024 r25057  
    148148        function find_folder($folder) {
    149149
    150                 if ( strpos($this->method, 'ftp') !== false ) {
    151                         $constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR, 'FTP_LANG_DIR' => WP_LANG_DIR );
    152                         foreach ( $constant_overrides as $constant => $dir )
    153                                 if ( defined($constant) && $folder === $dir )
    154                                         return trailingslashit(constant($constant));
     150                if ( isset( $this->cache[ $folder ] ) )
     151                        return $this->cache[ $folder ];
     152
     153                if ( stripos($this->method, 'ftp') !== false ) {
     154                        $constant_overrides = array(
     155                                'FTP_BASE' => ABSPATH,
     156                                'FTP_CONTENT_DIR' => WP_CONTENT_DIR,
     157                                'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR,
     158                                'FTP_LANG_DIR' => WP_LANG_DIR
     159                        );
     160
     161                        // Direct matches ( folder = CONSTANT/ )
     162                        foreach ( $constant_overrides as $constant => $dir ) {
     163                                if ( ! defined( $constant ) )
     164                                        continue;
     165                                if ( $folder === $dir )
     166                                        return trailingslashit( constant( $constant ) );
     167                        }
     168
     169                        // Prefix Matches ( folder = CONSTANT/subdir )
     170                        foreach ( $constant_overrides as $constant => $dir ) {
     171                                if ( ! defined( $constant ) )
     172                                        continue;
     173                                if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir
     174                                        $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );
     175                                        $potential_folder = trailingslashit( $potential_folder );
     176
     177                                        if ( $this->is_dir( $potential_folder ) ) {
     178                                                $this->cache[ $folder ] = $potential_folder;
     179                                                return $potential_folder;
     180                                        }
     181                                }
     182                        }
    155183                } elseif ( 'direct' == $this->method ) {
    156184                        $folder = str_replace('\\', '/', $folder); //Windows path sanitisation
Note: See TracChangeset for help on using the changeset viewer.