From 1b9ab9f66f858a89fc500fd2e10da33190117c23 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 20 Aug 2013 06:47:08 +0000 Subject: [PATCH] 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 Built from https://develop.svn.wordpress.org/trunk@25057 git-svn-id: http://core.svn.wordpress.org/trunk@25043 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-filesystem-base.php | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/class-wp-filesystem-base.php b/wp-admin/includes/class-wp-filesystem-base.php index 9d7d6e8c19..495d60139f 100644 --- a/wp-admin/includes/class-wp-filesystem-base.php +++ b/wp-admin/includes/class-wp-filesystem-base.php @@ -147,11 +147,39 @@ class WP_Filesystem_Base { */ function find_folder($folder) { - if ( strpos($this->method, 'ftp') !== false ) { - $constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR, 'FTP_LANG_DIR' => WP_LANG_DIR ); - foreach ( $constant_overrides as $constant => $dir ) - if ( defined($constant) && $folder === $dir ) - return trailingslashit(constant($constant)); + if ( isset( $this->cache[ $folder ] ) ) + return $this->cache[ $folder ]; + + if ( stripos($this->method, 'ftp') !== false ) { + $constant_overrides = array( + 'FTP_BASE' => ABSPATH, + 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, + 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR, + 'FTP_LANG_DIR' => WP_LANG_DIR + ); + + // Direct matches ( folder = CONSTANT/ ) + foreach ( $constant_overrides as $constant => $dir ) { + if ( ! defined( $constant ) ) + continue; + if ( $folder === $dir ) + return trailingslashit( constant( $constant ) ); + } + + // Prefix Matches ( folder = CONSTANT/subdir ) + foreach ( $constant_overrides as $constant => $dir ) { + if ( ! defined( $constant ) ) + continue; + if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir + $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder ); + $potential_folder = trailingslashit( $potential_folder ); + + if ( $this->is_dir( $potential_folder ) ) { + $this->cache[ $folder ] = $potential_folder; + return $potential_folder; + } + } + } } elseif ( 'direct' == $this->method ) { $folder = str_replace('\\', '/', $folder); //Windows path sanitisation return trailingslashit($folder);