0

I've got a theme that checks for a new version on GitHub. When it finds a new version it downloads it and install it. The problem is that it installs the theme with a different folder name than previous. Resulting errors.

I call the updater with hook pre_set_site_transient_update_themes

In it I check the GitHub api with: https://api.github.com/repos/my-name/my-repo/releases/latest

I set the update package variable with https://api.github.com/repos/my-name/my-repo/zipball/0.1.0 Where 0.1.0 is the latest version.

So if I install a theme manually the theme root folder is called something like: my-theme. Updating the theme downloads a new set of files with a different theme folder name. Something like my-theme-3d547d1. Next update its again being renamed, something like my-theme-58fa412.

How can I prevent this? Is this something on the GitHub side where I rename the target's zip file name or Something wordpress side, where it renames the zip after download and before install?

#in short#

Wordpress renames the theme folder when fetching theme update from GitHub, how to prevent this

2
  • 1
    WordPress wouldn't be renaming the folder anything like that. This is likely the folder/zip name given by GitHub, and you'll need to account for it in your code. Feb 16 at 9:49
  • @JacobPeattie, correct. It removes the current theme version folder and inserts a new theme version with a folder name bases on the name of the downloaded zip file.
    – Tim
    Feb 17 at 9:32
1

My first instinct upon reading this was that a Wordpress Plugin may give you more control over this behaviour. Have you considered writing a plugin to pull and apply the updates?

A quick Google on the subject found this:

https://github.com/afragen/github-updater

Any use?

Likewise, reviewing their implementation may give you clues as to how to address your issue.

1
  • Yes, almost. This plugin I saw, but it was too intensive to implement. Plus the client could disable the extra plugin it installed. Instead I found a older repo of him which had the answer to check and rename the downloaded folder: github.com/afragen/github-theme-updater/blob/… This solved my problem. Now I can implement the thought of this process within my theme.
    – Tim
    Feb 17 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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