WordPress Function for Performing a Plugin Update Routine — Or Not?

Today I was updating my Ecwid plugin such that the widgets load via ajax. One of the steps there involved creating a url that would respond to requests for widget markup, such that I could easily feed that url to jQuery’s excellent load() function. However, when I pushed this from my local to one of my test installs that’s actually on the web, I found that the url was 404’ing because I needed to flush the rewrite cache. I wouldn’t want my plugin users to have to do that themselves, so I added a class to my plugin to perform arbitrary functions upon plugin update.

I have one version number hard-coded into the main plugin file, and I’m saving that value to the database as well. In wp-admin, I compare the file version to the database version. If they are not the same version number, I know that it’s time to run the update routine, and also update the version in the database. Here’s the gist.

I hooked one function into this class: My function that dumps transients and rewrite rules. However, as I was looking at the code for my transients class, it occurred to me that I could accomplish this simply by adding the plugin version number to the transient prefix that my plugin uses:

One line of code instead of a whole new class!