How to keep cache files after plugin update?

I've got a premium plugin and setting up a custom solution to serve updates. However I've got a question regarding how contents are managed.

Wordpress just remove old plugin folder and install the new one. But what about cached files?

Assuming plugin has got two folders full of files and I must keep them: how should I proceed? Is there a way to tell Wordpress to ignore those elements?

Topic premium cache updates Wordpress

Category Web


Ok, after having digged into WP source for a couple of hours, found a workaround. Simply tell wordpress to NOT remove old files. Now files are 100% overwritten and cached files maintained.

Code is really simple

add_filter('upgrader_package_options', 'avoid_deletion', 999);
function avoid_deletion($options) {
    if($options['hook_extra']['plugin'] == 'my-plugin/my-plugin.php') {
        $options["clear_destination"] = false;
        $options["abort_if_destination_exists"] = false;
    }

    return $options;
}

I will write lately an optional method to remove single folders/files just in case.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.