Make WordPress Core

Changeset 17590


Ignore:
Timestamp:
04/03/2011 11:54:07 AM (15 years ago)
Author:
dd32
Message:

When upgrading plugins|themes, if the new destination folder is different from the previous folder, delete the old folder upon upgrade. Fixes #14182

File:
1 edited

Legend:

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

    r17502 r17590  
    212212                }
    213213
    214                 if ( $wp_filesystem->exists($remote_destination) ) {
    215                         if ( $clear_destination ) {
    216                                 //We're going to clear the destination if theres something there
    217                                 $this->skin->feedback('remove_old');
     214                if ( $clear_destination ) {
     215                        //We're going to clear the destination if theres something there
     216                        $this->skin->feedback('remove_old');
     217                        $removed = true;
     218                        if ( $wp_filesystem->exists($remote_destination) )
    218219                                $removed = $wp_filesystem->delete($remote_destination, true);
    219                                 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
    220 
    221                                 if ( is_wp_error($removed) )
    222                                         return $removed;
    223                                 else if ( ! $removed )
    224                                         return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
    225                         } else {
    226                                 //If we're not clearing the destination folder and something exists there allready, Bail.
    227                                 //But first check to see if there are actually any files in the folder.
    228                                 $_files = $wp_filesystem->dirlist($remote_destination);
    229                                 if ( ! empty($_files) ) {
    230                                         $wp_filesystem->delete($remote_source, true); //Clear out the source files.
    231                                         return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
    232                                 }
     220                        $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
     221
     222                        if ( is_wp_error($removed) )
     223                                return $removed;
     224                        else if ( ! $removed )
     225                                return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
     226                } elseif ( $wp_filesystem->exists($remote_destination) ) {
     227                        //If we're not clearing the destination folder and something exists there allready, Bail.
     228                        //But first check to see if there are actually any files in the folder.
     229                        $_files = $wp_filesystem->dirlist($remote_destination);
     230                        if ( ! empty($_files) ) {
     231                                $wp_filesystem->delete($remote_source, true); //Clear out the source files.
     232                                return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
    233233                        }
    234234                }
     
    567567        function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
    568568                global $wp_filesystem;
    569 
     569var_dump("delete_old_plugin($removed, $local_destination, $remote_destination, $plugin)");
    570570                if ( is_wp_error($removed) )
    571571                        return $removed; //Pass errors through.
     
    577577                $plugins_dir = $wp_filesystem->wp_plugins_dir();
    578578                $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
    579 
     579var_dump(compact('plugins_dir', 'this_plugin_dir'), array('exists'=>  $wp_filesystem->exists($this_plugin_dir)) );
    580580                if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
    581581                        return $removed;
     
    586586                else
    587587                        $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
    588 
     588var_dump($deleted);
    589589                if ( ! $deleted )
    590590                        return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
    591591
    592                 return $removed;
     592                return true;
    593593        }
    594594}
Note: See TracChangeset for help on using the changeset viewer.