Wordpress Theme Update without deleting destination folder

I am using the script written by Jeremy Clark for updating my self hosted Wordpress Themes. The script can be downloaded from here - GitHub

The updator works perfectly fine but it deletes the destination theme folder and then unzips the updates from the downloaded zip file. This deletes the customizations like custom.css

My Question:

Is there any way that i can overwrite the updates by not delete the existing (old)theme data. This way if my theme size is 12mb, then i can just zip the new updates(only the updated files) which will be merely 200kb (depending on updates). This way i can retain the customizations.

Any thoughts on this ?

I hope i was able to explain my problem.

--

Answers


I guess you're doing it wrong. WordPress has child themes just because parent themes get updated and you'll lose all modifications in that process.

For this same reason, you shouldn't modify core files or plugin files.


I managed to solve this in the below way:

add_filter('upgrader_pre_install', 'backup', 10, 2); //line 1
add_filter('upgrader_post_install', 'recover', 10, 2); //line2
add_filter('pre_set_site_transient_update_themes', 'check_for_update'); //line 3

Explaination

upgrader_pre_install is a filter hook which runs just before the upgrade starts.

upgrader_post_install is a filter hooks which runs just after the upgradation has finished.

So the below functions get triggered at the appropriate time which allows me to take a backup of customized files and then later copies them back into the theme.

function backup() {

     //create a folder using mkdir outside the theme folder and copy the necessary files.

}

function restore() {

     //restore the files and then delete the backup folder

}

Hope this helps to developers in similar situation.


Need Your Help

.NET Framework on Android

c# .net android mobile cross-compiling

Is anyone aware of any projects out there to port a version of the .NET framework to the Android platform, kind of like Mono.Touch?

Is wakelock needed in broadcast receiver for ACTION_SCREEN_OFF

android broadcastreceiver wakelock

I'm registering a broadcast receiver that will be activated when the screen is turned off. The receiver performs a short, synchronous operation in OnReceive. This operation must happen in my app be...