Make WordPress Core

Opened 10 years ago

Last modified 15 months ago

#28300 new defect (bug)

Two issues in the code for auto-uploading to subfolders

Reported by: wiziapp's profile wiziapp Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Upgrade/Install Keywords: needs-patch
Focuses: Cc:

Description (last modified by ocean90)

There are two issues in the code for auto-uploading to subfolders within a change rooted FTP (wp-admin/includes/class-wp-filesystem-base.php).

First, it adds a "/" to the replacement expression when the source replacement already contains a "/" (Note that ABSPATH has a trailing slash):

$potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );

This should be:

$potential_folder = preg_replace( '#^' . preg_quote( trailingslashit($dir), '#' ) . '#i', trailingslashit( constant( $constant ) ), $folder );

Second, it checks that the directory exists. This is not the case during theme and plugin installs, where the not existing directory is specified. Instead, only the parent should be checked.


if ( $this->is_dir( $potential_folder ) ) {
    $this->cache[ $folder ] = $potential_folder;
    return $potential_folder;


else {
      $potential_parent_folder = trailingslashit(preg_replace('#[^/]*/$#', '', $potential_folder));
      if ( $this->is_dir( $potential_parent_folder ) ) {
            $this->cache[ $folder ] = $potential_folder;
            return $potential_folder;

Would test for a valid parent, instead. (E.g. wp-content/themes instead of wp-content/themes/newtheme)

Change History (3)

#1 @ocean90
10 years ago

  • Description modified (diff)

#2 @chriscct7
8 years ago

  • Keywords needs-patch added

This ticket was mentioned in Slack in #core-upgrade-install by costdev. View the logs.

15 months ago

Note: See TracTickets for help on using tickets.