Ticket #5586: 5586.9.diff

File 5586.9.diff, 9.6 KB (added by DD32, 4 years ago)
  • wp-admin/includes/class-wp-filesystem-direct.php

     
    271271                foreach($filelist as $filename=>$det){ 
    272272                        if ( '/' == substr($filename,-1,1) ) 
    273273                                $this->rmdir($path.'/'.$filename,$recursive); 
    274                         @rmdir($entry); 
     274                        @rmdir($filename); 
    275275                } 
    276276                return @rmdir($path); 
    277277        } 
     
    333333                return; 
    334334        } 
    335335} 
    336 ?> 
    337  No newline at end of file 
     336?> 
  • wp-admin/includes/class-wp-filesystem-ftpext.php

     
    132132        } 
    133133        function get_contents($file,$type='',$resumepos=0){ 
    134134                if( empty($type) ){ 
    135                         $extension = substr(strrchr($filename, "."), 1); 
     135                        $extension = substr(strrchr($file, "."), 1); 
    136136                        $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; 
    137137                } 
    138138                $temp = tmpfile(); 
     
    348348        } 
    349349        function rmdir($path,$recursive=false){ 
    350350                if( ! $recursive ) 
    351                         return @ftp_rmdir($this->link, $file); 
     351                        return @ftp_rmdir($this->link, $path); 
    352352 
    353353                //TODO: Recursive Directory delete, Have to delete files from the folder first. 
    354354                //$dir = $this->dirlist($path); 
  • wp-admin/includes/class-wp-filesystem-ftpsockets.php

     
    139139                        return false; 
    140140 
    141141                if( empty($type) ){ 
    142                         $extension = substr(strrchr($filename, "."), 1); 
     142                        $extension = substr(strrchr($file, "."), 1); 
    143143                        $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII; 
    144144                } 
    145145                $this->ftp->SetType($type); 
     
    376376 
    377377        function rmdir($path,$recursive=false){ 
    378378                if( ! $recursive ) 
    379                         return $this->ftp->rmdir($file); 
     379                        return $this->ftp->rmdir($path); 
    380380 
    381381                return $this->ftp->mdel($path); 
    382382        } 
  • wp-admin/includes/file.php

     
    231231 
    232232        // Is the archive valid? 
    233233        if ( false == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING)) ) 
    234                 return new WP_Error('incompatible_archive', __('Incompatible archive'), $archive->error_string); 
     234                return new WP_Error('incompatible_archive', __('Incompatible archive'), $archive->errorInfo(true)); 
    235235 
    236236        if ( 0 == count($archive_files) ) 
    237237                return new WP_Error('empty_archive', __('Empty archive')); 
     
    240240        $path = explode('/', $to); 
    241241        $tmppath = ''; 
    242242        for ( $j = 0; $j < count($path) - 1; $j++ ) { 
    243                 $prevpath = $tmppath; 
    244243                $tmppath .= $path[$j] . '/'; 
    245                 if ( ! $fs->is_dir($tmppath) ) { 
    246                         //$fs->setDefaultPermissions( $fs->getchmod($tmppath) ); 
     244                if ( ! $fs->is_dir($tmppath) ) 
    247245                        $fs->mkdir($tmppath, 0755); 
    248                 } 
    249246        } 
    250247 
    251248        foreach ($archive_files as $file) { 
  • wp-admin/includes/update.php

     
    114114        $r = $current->response[ $file ]; 
    115115 
    116116        echo "<tr><td colspan='5' class='plugin-update'>"; 
    117         printf( __('There is a new version of %1$s available. <a href="%2$s">Download version %3$s here</a> or <a href="%4$s">upgrade automatically</a>.'), $plugin_data['Name'], $r->url, $r->new_version, "update.php?action=upgrade-plugin&amp;plugin=$file" ); 
     117        printf( __('There is a new version of %1$s available. <a href="%2$s">Download version %3$s here</a> or <a href="%4$s">upgrade automatically</a>.'), $plugin_data['Name'], $r->url, $r->new_version, wp_nonce_url("update.php?action=upgrade-plugin&amp;plugin=$file", 'upgrade-plugin_' . $file) ); 
    118118        echo "</td></tr>"; 
    119119} 
    120120add_action( 'after_plugin_row', 'wp_plugin_update_row' ); 
     
    154154 
    155155        // Download the package 
    156156        $package = $r->package; 
    157         apply_filters('update_feedback', sprintf(__("Downloading update from %s"), $package)); 
     157        apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); 
    158158        $file = download_url($package); 
    159159 
    160160        if ( !$file ) 
    161161                return new WP_Error('download_failed', __('Download failed.')); 
    162162 
    163         $name = basename($plugin, '.php'); 
    164         $working_dir = $base . 'wp-content/upgrade/' . $name; 
     163        $working_dir = $base . 'wp-content/upgrade/' . basename($plugin, '.php'); 
    165164 
    166165        // Clean up working directory 
    167         if ( is_dir($working_dir) ) 
     166        if ( $wp_filesystem->is_dir($working_dir) ) 
    168167                $wp_filesystem->delete($working_dir, true); 
    169168 
    170         apply_filters('update_feedback', __("Unpacking the update")); 
     169        apply_filters('update_feedback', __('Unpacking the update')); 
    171170        // Unzip package to working directory 
    172171        $result = unzip_file($file, $working_dir); 
    173172        if ( is_wp_error($result) ) { 
     
    180179        unlink($file); 
    181180 
    182181        // Remove the existing plugin. 
    183         apply_filters('update_feedback', __("Removing the old version of the plugin")); 
     182        apply_filters('update_feedback', __('Removing the old version of the plugin')); 
    184183        $plugin_dir = dirname($base . PLUGINDIR . "/$plugin"); 
    185184        $plugin_dir = trailingslashit($plugin_dir); 
     185         
    186186        // If plugin is in its own directory, recursively delete the directory. 
    187         if( ! in_array( $plugin_dir, array('.', trailingslashit($base . PLUGINDIR) ) ) ) 
     187        if( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' ) 
    188188                $deleted = $wp_filesystem->delete($plugin_dir, true); 
    189189        else 
    190190                $deleted = $wp_filesystem->delete($base . PLUGINDIR . "/$plugin"); 
     191 
    191192        if ( !$deleted ) { 
    192193                $wp_filesystem->delete($working_dir, true); 
    193194                return new WP_Error('delete_failed', __('Could not remove the old plugin')); 
    194195        } 
    195196 
    196         apply_filters('update_feedback', __("Installing the latest version")); 
     197        apply_filters('update_feedback', __('Installing the latest version')); 
    197198        // Copy new version of plugin into place. 
    198199        if ( !copy_dir($working_dir, $base . PLUGINDIR) ) { 
    199                 //$wp_filesystem->delete($working_dir, true); 
     200                //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. 
    200201                return new WP_Error('install_failed', __('Installation failed')); 
    201202        } 
    202203 
     
    207208        delete_option('update_plugins'); 
    208209} 
    209210 
    210 ?> 
     211?> 
     212 No newline at end of file 
  • wp-admin/update.php

     
    55if ( !current_user_can('edit_plugins') ) 
    66                wp_die('<p>'.__('You do not have sufficient permissions to update plugins for this blog.').'</p>'); 
    77 
    8 function request_filesystem_credentials($form_post, $type = '') { 
     8function request_filesystem_credentials($form_post, $type = '', $error = false) { 
    99        if ( empty($type) ) 
    1010                $type = get_filesystem_method(); 
    1111 
    1212        if ( 'direct' == $type ) 
    1313                return array(); 
    1414 
    15         if ( !empty($_POST['password']) && !empty($_POST['username']) && !empty($_POST['hostname']) ) { 
     15        if ( ! $error && !empty($_POST['password']) && !empty($_POST['username']) && !empty($_POST['hostname']) ) { 
    1616                $credentials = array('hostname' => $_POST['hostname'], 'username' => $_POST['username'], 
    1717                        'password' => $_POST['password'], 'ssl' => $_POST['ssl']); 
    1818                $stored_credentials = $credentials; 
     
    2626        $ssl = ''; 
    2727        if ( $credentials = get_option('ftp_credentials') ) 
    2828                extract($credentials, EXTR_OVERWRITE); 
     29        if( $error ){ 
     30                echo '<div id="message" class="error"><p>' . __('<strong>Error:</strong> There was an error connecting to the server, Please verify the settings are correct.') . '</p></div>'; 
     31        } 
    2932?> 
    3033<form action="<?php echo $form_post ?>" method="post"> 
    3134<div class="wrap"> 
     
    4245</tr> 
    4346<tr valign="top"> 
    4447<th scope="row"><?php _e('Password:') ?></th> 
    45 <td><input name="password" type="text" id="password" value="<?php echo attribute_escape($password) ?>" size="40" /></td> 
     48<td><input name="password" type="password" id="password" value="<?php echo attribute_escape($password) ?>" size="40" /></td> 
    4649</tr> 
    4750<tr valign="top"> 
    4851<th scope="row"><?php _e('Use SSL:') ?></th> 
     
    8083function do_plugin_upgrade($plugin) { 
    8184        global $wp_filesystem; 
    8285 
    83         $credentials = request_filesystem_credentials("update.php?action=upgrade-plugin&plugin=$plugin"); 
    84         if ( false === $credentials ) 
     86        $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin"); 
     87        if ( false === ($credentials = request_filesystem_credentials($url)) ) 
    8588                return; 
     89                 
     90        if( ! WP_Filesystem($credentials) ){ 
     91                request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again 
     92                return; 
     93        } 
     94                 
    8695        echo '<div class="wrap">'; 
    8796        echo '<h2>' . __('Upgrade Plugin') . '</h2>'; 
    88         WP_Filesystem($credentials); 
    89         // TODO: look for auth and connect error codes and direct back to credentials form. 
    9097        if ( $wp_filesystem->errors->get_error_code() ) { 
    9198                foreach ( $wp_filesystem->errors->get_error_messages() as $message ) 
    9299                        show_message($message); 
     
    108115                $plugin = trim($_GET['plugin']); 
    109116 
    110117        if ( 'upgrade-plugin' == $_GET['action'] ) { 
    111                 //check-admin_referer('upgrade-plugin_' . $plugin); 
     118                check_admin_referer('upgrade-plugin_' . $plugin); 
    112119                $title = __('Upgrade Plugin'); 
    113120                $parent_file = 'plugins.php'; 
    114121                require_once('admin-header.php'); 
    115122                do_plugin_upgrade($plugin); 
    116123                include('admin-footer.php'); 
    117124        } 
    118  
    119125} 
    120126 
    121 ?> 
    122  No newline at end of file 
     127?>