Ticket #5586: 5586.16.diff
| File 5586.16.diff, 4.1 kB (added by DD32, 3 months ago) |
|---|
-
wp-admin/includes/file.php
old new 192 210 * Downloads a url to a local file using the Snoopy HTTP Class 193 211 * 194 212 * @param string $url the URL of the file to download 195 * @return mixed falseon failure, string Filename on success.213 * @return mixed WP_Error on failure, string Filename on success. 196 214 */ 197 215 function download_url( $url ) { 198 216 //WARNING: The file is not automatically deleted, The script must unlink() the file. 199 217 if( ! $url ) 200 return false;218 return new WP_Error('http_no_url', __('Invalid URL Provided')); 201 219 202 220 $tmpfname = tempnam(get_temp_dir(), 'wpupdate'); 203 221 if( ! $tmpfname ) 204 return false;222 return new WP_Error('http_no_file', __('Could not create Temporary file')); 205 223 206 224 $handle = @fopen($tmpfname, 'w'); 207 225 if( ! $handle ) 208 return false;226 return new WP_Error('http_no_file', __('Could not create Temporary file')); 209 227 210 228 require_once( ABSPATH . 'wp-includes/class-snoopy.php' ); 211 229 $snoopy = new Snoopy(); 212 230 $snoopy->fetch($url); 213 231 232 if( $snoopy->status != '200' ){ 233 fclose($handle); 234 unlink($tmpfname); 235 return new WP_Error('http_404', trim($snoopy->response_code)); 236 } 214 237 fwrite($handle, $snoopy->results); 215 238 fclose($handle); 216 239 -
wp-admin/includes/update.php
old new 176 176 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); 177 177 $file = download_url($package); 178 178 179 if ( !$file)180 return new WP_Error('download_failed', __('Download failed.') );179 if ( is_wp_error($file) ) 180 return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message()); 181 181 182 182 $working_dir = $base . 'wp-content/upgrade/' . basename($plugin, '.php'); 183 183 … … 194 194 return $result; 195 195 } 196 196 197 // Once installed, delete the package197 // Once extracted, delete the package 198 198 unlink($file); 199 199 200 200 if ( is_plugin_active($plugin) ) { 201 //Deactivate the plugin 201 //Deactivate the plugin silently, Prevent deactivation hooks from running. 202 202 apply_filters('update_feedback', __('Deactivating the plugin')); 203 203 deactivate_plugins($plugin, true); 204 204 } … … 209 209 $plugin_dir = trailingslashit($plugin_dir); 210 210 211 211 // If plugin is in its own directory, recursively delete the directory. 212 if ( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' ) 212 if ( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' ) //base check on if plugin includes directory seperator AND that its not the root plugin folder 213 213 $deleted = $wp_filesystem->delete($plugin_dir, true); 214 214 else 215 215 $deleted = $wp_filesystem->delete($base . PLUGINDIR . "/$plugin"); … … 226 226 return new WP_Error('install_failed', __('Installation failed')); 227 227 } 228 228 229 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 230 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 231 229 232 // Remove working directory 230 233 $wp_filesystem->delete($working_dir, true); 231 234 232 235 // Force refresh of plugin update information 233 236 delete_option('update_plugins'); 234 237 235 //Return the new plugin file. 236 if ( ! preg_match('!/([a-z0-9\-]+)/?$!i', $working_dir, $mat) ) 237 return false; 238 $plugin = get_plugins('/' . $mat[1]); //Pass it with a leading slash 239 $list = array_keys($plugin); 240 return $mat[1] . '/' . $list[0]; //Pass it without a leading slash. 238 if( empty($filelist) ) 239 return false; //We couldnt find any files in the working dir 240 241 $folder = $filelist[0]; 242 $plugin = get_plugins('/' . $folder); //Pass it with a leading slash, search out the plugins in the folder, 243 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 244 245 return $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires 241 246 } 242 247 243 248 ?>
