0

I just upgraded a site to WordPress version 4.4, and now whenever I try to upgrade any plugin or theme I get a message like this:

An error occurred while updating <plugin/theme name>: Could not create directory. <plugin/theme directory>

I have set the permission on the wp-content directory (and even all subdirectories) to 777, but I still get the above message whenever I try to upgrade a plugin or theme.

What gives?

I am able to install new plugins, so it doesn't seem to be a permission issue in the plugins folder.

More research:

In wp-admin/includes/class-wp-uploader.php, lines 531-535:

//Create destination if needed
if ( ! $wp_filesystem->exists( $remote_destination ) ) {
    if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
        return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
    }
}

The exists call is returning false when I try to update a plugin. This is wrong. I am able to see the directory referred to by $remote_destination in my OS shell, and it obviously does exist because the failure occurs on the mkdir call—it is unable to make the directory because it already exists.

Digging deeper, in wp-admin/includes/class-wp-filesystem-ftpext.php, lines 329-338:

public function exists( $file ) {
    $path = dirname( $file );
    $filename = basename( $file );    

    $file_list = @ftp_nlist( $this->link, '-a ' . $path );
    if ( $file_list ) {
        $file_list = array_map( 'basename', $file_list );
    }
    return $file_list && in_array( $filename, $file_list );
}

If I add the following line just before the return statement...

error_log(debug_backtrace()[1]['function'] . ": \npath: $path\nfilename: $filename\nfile list:\n" . print_r($file_list, true) . "\n");

... I see this output for the relevant call ...

[11-Dec-2015 18:42:19 UTC] install_package:
path: <the expected path>
filename: <the expected filename>
file list: 
Array
(
)

The file list is empty! It should not be. What's going on here?

  • As an additional note: I have verified that reverting my WordPress install to 4.3 fixes this issue, and I am able to upgrade plugins and themes just fine. – ralbatross Dec 11 '15 at 19:09
  • This is a WP bug. – ralbatross Dec 11 '15 at 20:11
-1

In file wp-admin/includes/class-wp-filesystem-ftpext.php, line 333:

Replace

$file_list = @ftp_nlist( $this->link, '-a ' . $path );

With

$file_list = @ftp_nlist( $this->link, $path );
  • 1
    This isn't really an acceptable answer. If you modify core files such as this they will be overwritten whenever WordPress upgrades. Never a good idea to modify core. – Howdy_McGee Dec 22 '15 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.