WordPress Update: Use local file

My WordPress installation couldn’t download the necessary update files fast enough. I could see that in wp-content/tmp the .tmp-files were created and growing, but they all stopped early and WordPress tried downloading again and again. Of course, your WordPress-installation might use a different tempdir. If you’re unsure, just add the following line to your wp-config.php to make sure that the tempdir is exactly what you expect:

define('WP_TEMP_DIR', ABSPATH . 'wp-content/tmp');

Here’s what you have to do:

  1. Download the update manually and upload it to the server into the directory wp-content/tmp.
  2. Modify the file wp-admin/includes/file.php by adding these five lines to the function download_url, right before the line with the call to wp_safe_remote_get().
    $parts = parse_url($url);
    if ( empty($dir) )
        $dir = get_temp_dir();
    if (file_exists($dir . $parts['path']))
        return $dir . $parts['path'];
  3. Run the „Automatic Update“ from your dashboard.

Please keep these things in mind:

  • The file that you stored into the wp-content/tmp will be deleted after the upgrade.
  • The changes to file.php will disappear as the upgrade normally overwrites file.php

How does this work?

We extract the filename from the URL that WordPress is trying to download ($parts['path'] is the filename). If the file resides in the tempdir, simply return with this filename rather than with a temporary filename.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.