Abhishek Saha
Abhishek Saha

Reputation: 2564

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.

--

Upvotes: 1

Views: 409

Answers (2)

Abhishek Saha
Abhishek Saha

Reputation: 2564

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.

Upvotes: 0

RRikesh
RRikesh

Reputation: 14381

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.

Upvotes: 4

Related Questions