diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php index 88e4a902a5..e18e257758 100644 --- a/wp-admin/includes/class-wp-filesystem-direct.php +++ b/wp-admin/includes/class-wp-filesystem-direct.php @@ -54,14 +54,13 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { /** * Write a string to a file * - * @param $file string Path to the file where to write the data. + * @param $file string Remote path to the file where to write the data. * @param $contents string The data to write. * @param $mode int (optional) The file permissions as octal number, usually 0644. - * @param $type string (optional) Specifies additional type of access you require to the file. * @return bool False upon failure. */ - function put_contents($file, $contents, $mode = false, $type = '') { - if ( ! ($fp = @fopen($file, 'w' . $type)) ) + function put_contents($file, $contents, $mode = false ) { + if ( ! ($fp = @fopen($file, 'w')) ) return false; @fwrite($fp, $contents); @fclose($fp); diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index b8d5c9ae6b..6b006fa335 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -111,10 +111,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { function get_contents_array($file) { return explode("\n", $this->get_contents($file)); } - function put_contents($file, $contents, $type = '' ) { - if ( empty($type) ) - $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; - + + function put_contents($file, $contents, $mode = false ) { $temp = tmpfile(); if ( ! $temp ) return false; @@ -122,9 +120,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { fwrite($temp, $contents); fseek($temp, 0); //Skip back to the start of the file being written to + $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; $ret = @ftp_fput($this->link, $file, $temp, $type); fclose($temp); + + $this->chmod($file, $mode); + return $ret; } function cwd() { diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index a72abaa766..e0480c5414 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -115,14 +115,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { return explode("\n", $this->get_contents($file) ); } - function put_contents($file, $contents, $type = '' ) { - if ( empty($type) ) - $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; - - $this->ftp->SetType($type); - + function put_contents($file, $contents, $mode = false ) { $temp = wp_tempnam( $file ); - if ( ! $temphandle = fopen($temp, 'w+') ) { + if ( ! $temphandle = @fopen($temp, 'w+') ) { unlink($temp); return false; } @@ -130,10 +125,16 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { fwrite($temphandle, $contents); fseek($temphandle, 0); //Skip back to the start of the file being written to + $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; + $this->ftp->SetType($type); + $ret = $this->ftp->fput($file, $temphandle); fclose($temphandle); unlink($temp); + + $this->chmod($file, $mode); + return $ret; } diff --git a/wp-admin/includes/class-wp-filesystem-ssh2.php b/wp-admin/includes/class-wp-filesystem-ssh2.php index 0337658c9d..41cfffbde5 100644 --- a/wp-admin/includes/class-wp-filesystem-ssh2.php +++ b/wp-admin/includes/class-wp-filesystem-ssh2.php @@ -160,9 +160,13 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { return file('ssh2.sftp://' . $this->sftp_link . '/' . $file); } - function put_contents($file, $contents, $type = '' ) { + function put_contents($file, $contents, $mode = false ) { $file = ltrim($file, '/'); - return false !== file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents); + $ret = file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents); + + $this->chmod($file, $mode); + + return false !== $ret; } function cwd() { diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 472812a95f..5fc773b98f 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -550,9 +550,8 @@ function unzip_file($file, $to) { // We've made sure the folders are there, so let's extract the file now: if ( ! $file['folder'] ) { - if ( !$fs->put_contents( $to . $file['filename'], $file['content']) ) + if ( !$fs->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) ) return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']); - $fs->chmod($to . $file['filename'], FS_CHMOD_FILE); } } return true;