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?