Ticket #10889: 10889.3.diff

File 10889.3.diff, 4.5 KB (added by dd32, 3 years ago)
  • wp-admin/includes/class-wp-filesystem-direct.php

     
    5454        /** 
    5555         * Write a string to a file 
    5656         * 
    57          * @param $file string Path to the file where to write the data. 
     57         * @param $file string Remote path to the file where to write the data. 
    5858         * @param $contents string The data to write. 
    5959         * @param $mode int (optional) The file permissions as octal number, usually 0644. 
    60          * @param $type string (optional) Specifies additional type of access you require to the file. 
    6160         * @return bool False upon failure. 
    6261         */ 
    63         function put_contents($file, $contents, $mode = false, $type = '') { 
    64                 if ( ! ($fp = @fopen($file, 'w' . $type)) ) 
     62        function put_contents($file, $contents, $mode = false ) { 
     63                if ( ! ($fp = @fopen($file, 'w')) ) 
    6564                        return false; 
    6665                @fwrite($fp, $contents); 
    6766                @fclose($fp); 
  • wp-admin/includes/class-wp-filesystem-ftpext.php

     
    111111        function get_contents_array($file) { 
    112112                return explode("\n", $this->get_contents($file)); 
    113113        } 
    114         function put_contents($file, $contents, $type = '' ) { 
    115                 if ( empty($type) ) 
    116                         $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 
    117  
     114         
     115        function put_contents($file, $contents, $mode = false ) { 
    118116                $temp = tmpfile(); 
    119117                if ( ! $temp ) 
    120118                        return false; 
     
    122120                fwrite($temp, $contents); 
    123121                fseek($temp, 0); //Skip back to the start of the file being written to 
    124122 
     123                $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 
    125124                $ret = @ftp_fput($this->link, $file, $temp, $type); 
    126125 
    127126                fclose($temp); 
     127 
     128                $this->chmod($file, $mode); 
     129 
    128130                return $ret; 
    129131        } 
    130132        function cwd() { 
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php

     
    115115                return explode("\n", $this->get_contents($file) ); 
    116116        } 
    117117 
    118         function put_contents($file, $contents, $type = '' ) { 
    119                 if ( empty($type) ) 
    120                         $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 
    121  
    122                 $this->ftp->SetType($type); 
    123  
     118        function put_contents($file, $contents, $mode = false ) { 
    124119                $temp = wp_tempnam( $file ); 
    125                 if ( ! $temphandle = fopen($temp, 'w+') ) { 
     120                if ( ! $temphandle = @fopen($temp, 'w+') ) { 
    126121                        unlink($temp); 
    127122                        return false; 
    128123                } 
     
    130125                fwrite($temphandle, $contents); 
    131126                fseek($temphandle, 0); //Skip back to the start of the file being written to 
    132127 
     128                $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; 
     129                $this->ftp->SetType($type); 
     130 
    133131                $ret = $this->ftp->fput($file, $temphandle); 
    134132 
    135133                fclose($temphandle); 
    136134                unlink($temp); 
     135 
     136                $this->chmod($file, $mode); 
     137 
    137138                return $ret; 
    138139        } 
    139140 
  • wp-admin/includes/class-wp-filesystem-ssh2.php

     
    160160                return file('ssh2.sftp://' . $this->sftp_link . '/' . $file); 
    161161        } 
    162162 
    163         function put_contents($file, $contents, $type = '' ) { 
     163        function put_contents($file, $contents, $mode = false ) { 
    164164                $file = ltrim($file, '/'); 
    165                 return false !== file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents); 
     165                $ret = file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents); 
     166                 
     167                $this->chmod($file, $mode); 
     168                 
     169                return false !== $ret; 
    166170        } 
    167171 
    168172        function cwd() { 
  • wp-admin/includes/file.php

     
    546546 
    547547                // We've made sure the folders are there, so let's extract the file now: 
    548548                if ( ! $file['folder'] ) { 
    549                         if ( !$fs->put_contents( $to . $file['filename'], $file['content']) ) 
     549                        if ( !$fs->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) ) 
    550550                                return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']); 
    551                         $fs->chmod($to . $file['filename'], FS_CHMOD_FILE); 
    552551                } 
    553552        } 
    554553        return true;