WordPress.org

Ready to get started?Download WordPress

Forums

Preventing Overwrites in Theme Upgrades (9 posts)

  1. Sayontan Sinha
    Member
    Posted 4 years ago #

    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.

  2. stvwlf
    Member
    Posted 4 years ago #

    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.

  3. Sayontan Sinha
    Member
    Posted 4 years ago #

    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.

  4. stvwlf
    Member
    Posted 4 years ago #

    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.

  5. Sayontan Sinha
    Member
    Posted 4 years ago #

    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?

  6. stvwlf
    Member
    Posted 4 years ago #

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

  7. Sayontan Sinha
    Member
    Posted 4 years ago #

    Thanks, for your inputs!

  8. Joni
    Member
    Posted 4 years ago #

    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.

  9. Sayontan Sinha
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic