Changeset 8009 for trunk/wp-admin/includes/update.php
- Timestamp:
- 05/29/2008 05:29:32 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/includes/update.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/update.php
r7999 r8009 151 151 152 152 // Is a filesystem accessor setup? 153 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )153 if ( ! $wp_filesystem || ! is_object($wp_filesystem) ) 154 154 WP_Filesystem(); 155 155 … … 161 161 162 162 //Get the base plugin folder 163 $base = $wp_filesystem->get_base_dir(WP_PLUGIN_DIR); 164 165 if ( empty($base) ) 166 return new WP_Error('fs_nowordpress', __('Unable to locate WordPress directory.')); 163 $plugins_dir = $wp_filesystem->wp_plugins_dir(); 164 if ( empty($plugins_dir) ) 165 return new WP_Error('fs_no)plugins_dir', __('Unable to locate WordPress Plugin directory.')); 166 167 //And the same for the Content directory. 168 $content_dir = $wp_filesystem->wp_content_dir(); 169 if( empty($content_dir) ) 170 return new WP_Error('fs_no_content_dor', __('Unable to locate WordPress Content directory (wp-content).')); 171 172 $plugins_dir = trailingslashit( $plugins_dir ); 173 $content_dir = trailingslashit( $content_dir ); 167 174 168 175 // Get the URL to the zip file … … 175 182 $package = $r->package; 176 183 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); 177 $ file = download_url($package);178 179 if ( is_wp_error($ file) )184 $download_file = download_url($package); 185 186 if ( is_wp_error($download_file) ) 180 187 return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message()); 181 188 182 $working_dir = $ wp_filesystem->get_base_dir(WP_CONTENT_DIR) . '/upgrade/' . basename($plugin, '.php');189 $working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php'); 183 190 184 191 // Clean up working directory … … 188 195 apply_filters('update_feedback', __('Unpacking the update')); 189 196 // Unzip package to working directory 190 $result = unzip_file($file, $working_dir); 197 $result = unzip_file($download_file, $working_dir); 198 199 // Once extracted, delete the package 200 unlink($download_file); 201 191 202 if ( is_wp_error($result) ) { 192 unlink($file);193 203 $wp_filesystem->delete($working_dir, true); 194 204 return $result; 195 205 } 196 197 // Once extracted, delete the package198 unlink($file);199 206 200 207 if ( is_plugin_active($plugin) ) { … … 206 213 // Remove the existing plugin. 207 214 apply_filters('update_feedback', __('Removing the old version of the plugin')); 208 $plugin_dir = dirname($base . "/$plugin"); 209 $plugin_dir = trailingslashit($plugin_dir); 215 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); 210 216 211 217 // If plugin is in its own directory, recursively delete the directory. 212 if ( strpos($plugin, '/') && $ plugin_dir != $base . '/') //base check on if plugin includes directory seperator AND that its not the root plugin folder213 $deleted = $wp_filesystem->delete($ plugin_dir, true);218 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder 219 $deleted = $wp_filesystem->delete($this_plugin_dir, true); 214 220 else 215 $deleted = $wp_filesystem->delete($ base . '/'. $plugin);216 217 if ( ! $deleted ) {221 $deleted = $wp_filesystem->delete($plugins_dir . $plugin); 222 223 if ( ! $deleted ) { 218 224 $wp_filesystem->delete($working_dir, true); 219 225 return new WP_Error('delete_failed', __('Could not remove the old plugin')); … … 222 228 apply_filters('update_feedback', __('Installing the latest version')); 223 229 // Copy new version of plugin into place. 224 if ( !copy_dir($working_dir, $base) ) { 230 $result = copy_dir($working_dir, $plugins_dir); 231 if ( is_wp_error($result) ) { 225 232 //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. 226 return new WP_Error('install_failed', __('Installation failed'));233 return $result; 227 234 } 228 235 … … 237 244 238 245 if( empty($filelist) ) 239 return false; //We couldnt find any files in the working dir 246 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. 240 247 241 248 $folder = $filelist[0]; 242 $plugin = get_plugins('/' . $folder); // Pass it with a leading slash, search out the plugins in the folder,249 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 243 250 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 244 251 245 return $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires252 return $folder . '/' . $pluginfiles[0]; 246 253 } 247 254
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)