Is there a way to test run a theme through the automatic updater?

We have a theme where a version will introduce new functionality which might break existing themes. I would like to check previous theme version upon upgrade and include some upgrade-specific code if the upgrade is between two certain versions.

I first thought I could use after_theme_switch hook, but the theme is mainly used as parent theme and will probably be upgraded while not being the active theme. I have looked into using upgrader_pre_install and upgrader_post_install hooks, but how to I test these?

The ultimate would be to have it as a unit test, but any other way to mock-upgrade would be great. Uploading a zip file is treated as an install and not upgrade.

Is this even possible from within a theme, our should I look into writing a mock-upgrade plugin?

2 Answers
2

You are asking two questions. The one being how can you test an update and the other being how can you run code after an update.

You can test a theme update by pushing the updates out your self and testing it if it works. You can do that by using GitHub Updater.

If you want to run code only after a upgrade there is no core solution. There are two ways it could work.

  1. You save the theme version to the database as with this you can calculate what version or update it is and then run the update code.
  2. If you are including new options in the update you could check if the new options exist yet and if not then run the update code.

I think the after_setup_theme should be fine.

Leave a Reply

Your email address will not be published. Required fields are marked *