WordPress.org

Make WordPress Core

Ticket #17680: Proposed Upgrader Fix.diff

File Proposed Upgrader Fix.diff, 4.2 KB (added by blurback, 7 years ago)
  • wp-admin/includes/class-wp-upgrader.php

     
    208208                        $destination = trailingslashit($destination) . trailingslashit(basename($source));
    209209                }
    210210
     211                $tempdir = untrailingslashit($remote_destination) . ".tmp-" . time() . "/";
    211212                if ( $clear_destination ) {
     213                        //Try to rename original theme (also works as a backup)
     214                        $moved = @rename($remote_destination, $tempdir);
     215                        if ( ! $moved )
     216                                return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
     217
    212218                        //We're going to clear the destination if theres something there
    213219                        $this->skin->feedback('remove_old');
    214220                        $removed = true;
     
    259265                        return $res;
    260266                }
    261267
     268                // Remove temporary backup
     269                $removed = $wp_filesystem->delete($tempdir, true);
     270                if( !$removed ) $this->skin->feedback("remove_tmp_failed");
     271
    262272                //Bombard the calling function will all the info which we've just used.
    263273                return $this->result;
    264274        }
     
    373383                $this->strings['deactivate_plugin'] = __('Deactivating the plugin…');
    374384                $this->strings['remove_old'] = __('Removing the old version of the plugin…');
    375385                $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
     386                $this->strings['remove_tmp_failed'] = __('Could not remove the temporary plugin directory.');
    376387                $this->strings['process_failed'] = __('Plugin update failed.');
    377388                $this->strings['process_success'] = __('Plugin updated successfully.');
    378389        }
     
    612623                $this->strings['unpack_package'] = __('Unpacking the update…');
    613624                $this->strings['remove_old'] = __('Removing the old version of the theme…');
    614625                $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
     626                $this->strings['remove_tmp_failed'] = __('Could not remove the temporary theme directory.');
    615627                $this->strings['process_failed'] = __('Theme update failed.');
    616628                $this->strings['process_success'] = __('Theme updated successfully.');
    617629        }