• I am sure there are folks who have faced this situation, unfortunately I could not find any literature on how to resolve it.

    When I make updates to my theme and release it on WP as a new version, users can upgrade through their control panels. However, I would like the upgrade to not touch certain things like a custom.css file or a folder for header images etc. In other words, if my theme is called “my-theme” and its directory is wp-content/my-theme, I would like to overwrite things like wp-content/my-theme/style.css, but not wp-content/my-theme/custom.css.

    What do I have to do so that certain files / folders are preserved? Is there some kind of an action hook for this or is it much simpler?

    Cheers,
    Sayontan.

Viewing 8 replies - 1 through 8 (of 8 total)
  • I’m not a full blown theme developer, but I suspect if there is no file called custom.css in your theme, when the user installs your theme upgrade its not going to delete a file that isn’t in your theme. That is exactly how WordPress upgrades work – they overwrite the default and classic themes in the themes folder, but no other files there.

    To make it even clearer you could create a folder in your theme called custom and have all user-supplied content stored in that folder and its subfolders.

    The best thing would be for you to test for yourself whether this is true.

    Thread Starter Sayontan Sinha

    (@sayontan)

    I am not sure that works. To cite an example, I use a plugin called “Now Reading”. This plugin has a setting that looks for a folder called “now-reading” within a theme and picks up various template files from it. The plugin author uses this as an approach to have the user do custom styles for the plugin. Now, whenever I do an upgrade of my theme this folder completely disappears from the theme directory.

    1) Check the code of that plugin

    2) plugin API is not identical to theme API

    I know that Lester Chan uses a setup in some of his plugins where if the stylesheet he is looking for exists in the main theme folder, it uses that stylesheet otherwise it uses the one in his plugin folder. Another plugin I know of looks in a different folder altogether for custom stylesheets.

    Suggestion: install someone’s theme on a test WP installation (one of yours?). Create a custom stylesheet in that folder. Then do an auto upgrade of that theme from within WordPress – reinstall it of necessary. Then see if the custom stylesheet is still there after your reinstall.

    Thread Starter Sayontan Sinha

    (@sayontan)

    Stvwlf,
    I don’t see how the plugin itself is relevant here – I just used the files from the plugin within my theme folder as an example to illustrate what is happening. Whenever I upgrade my theme (not the plugin), all the original contents of my theme folder disappear, including the files from any plugin and any other custom file that I have created.

    When I try this exercise with some themes like Atahualpa, this is not the case. Do I need to do package definitions anywhere?

    Hi
    I don’t have any more to add as this is out of the main area of my expertise.

    Thread Starter Sayontan Sinha

    (@sayontan)

    Thanks, for your inputs!

    Well I think the OP is talking about his theme operating the way Chris Pearson’s Thesis theme does. He uses custom functions.php and style.css files housed in the /custom/ subfolder of the theme files and they are preserved.

    Thread Starter Sayontan Sinha

    (@sayontan)

    Jonimueller,
    Yes, that is correct. To present another example, Atahualpa ships with a folder called images/header which has a few images in it. The theme user can actually overwrite the contents of that folder and delete the existing images. Upon an upgrade, the theme users files in that folder are preserved and the files that he/she deleted are not rewritten.

    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Preventing Overwrites in Theme Upgrades’ is closed to new replies.