Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I learned from a previous question that plugin updates are downloaded as a zip file, and WordPress overwrites every file in the plugin folder whether or not that file actually had a change from one version to the next. My question is, if the user has added extra files to the plugin folder (such as .po/.mo files for language translation), will those files be deleted during a plugin update?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Yes, the entire old directory will be deleted. So store files in the upload directory and other data in the database to keep all changes.

From class Plugin_Upgrader:

//Hooked to upgrade_clear_destination
function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
    global $wp_filesystem;

    if ( is_wp_error($removed) )
        return $removed; //Pass errors through.

    $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
    if ( empty($plugin) )
        return new WP_Error('bad_request', $this->strings['bad_request']);

    $plugins_dir = $wp_filesystem->wp_plugins_dir();
    $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );

    if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
        return $removed;

    // If plugin is in its own directory, recursively delete the directory.
    if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that its not the root plugin folder
        $deleted = $wp_filesystem->delete($this_plugin_dir, true);
    else
        $deleted = $wp_filesystem->delete($plugins_dir . $plugin);

    if ( ! $deleted )
        return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);

    return true;
share|improve this answer
2  
If you have language files, you could submit them to the plugin developer for incorporation into the plugin. –  vancoder Apr 30 '13 at 16:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.