Make WordPress Core


Ignore:
Timestamp:
05/29/2008 05:29:32 PM (18 years ago)
Author:
ryan
Message:

Make WP_Filesystem work with new directory constants. Props DD32. fixes #7059

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/update.php

    r7999 r8009  
    151151
    152152        // Is a filesystem accessor setup?
    153         if ( ! $wp_filesystem || !is_object($wp_filesystem) )
     153        if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
    154154                WP_Filesystem();
    155155
    … …  
    161161
    162162        //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 );
    167174
    168175        // Get the URL to the zip file
    … …  
    175182        $package = $r->package;
    176183        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) )
    180187                return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message());
    181188
    182         $working_dir = $wp_filesystem->get_base_dir(WP_CONTENT_DIR) . '/upgrade/' . basename($plugin, '.php');
     189        $working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php');
    183190
    184191        // Clean up working directory
    … …  
    188195        apply_filters('update_feedback', __('Unpacking the update'));
    189196        // 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       
    191202        if ( is_wp_error($result) ) {
    192                 unlink($file);
    193203                $wp_filesystem->delete($working_dir, true);
    194204                return $result;
    195205        }
    196 
    197         // Once extracted, delete the package
    198         unlink($file);
    199206
    200207        if ( is_plugin_active($plugin) ) {
    … …  
    206213        // Remove the existing plugin.
    207214        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) );
    210216       
    211217        // 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 folder
    213                 $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);
    214220        else
    215                 $deleted = $wp_filesystem->delete($base . '/' . $plugin);
    216 
    217         if ( !$deleted ) {
     221                $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
     222
     223        if ( ! $deleted ) {
    218224                $wp_filesystem->delete($working_dir, true);
    219225                return new WP_Error('delete_failed', __('Could not remove the old plugin'));
    … …  
    222228        apply_filters('update_feedback', __('Installing the latest version'));
    223229        // 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) ) {
    225232                //$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;
    227234        }
    228235
    … …  
    237244       
    238245        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.
    240247       
    241248        $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
    243250        $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
    244251
    245         return  $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires
     252        return  $folder . '/' . $pluginfiles[0];
    246253}
    247254
Note: See TracChangeset for help on using the changeset viewer.