Save Plugin Version Number as Option?

I seem to recall seeing a tip somewhere saying that it was a best practice to save a plugin’s version number as an option. I’m working through releasing a plugin, and I’m considering whether to do it, but since all the plugin does is make a widget (right now, it literally has no other options), I’m struggling to understand what I would ever do with that option. I’m already setting a constant with the version number for use in a couple places (mostly wp_enqueue_*).

Can someone either point me to a good resource or explain the use cases for saving the version number as an option?

3 Answers
3

You need to save the version to the database– aka. save it “as an option”– so that your script has a comparison case. That is, your script should…

  1. Check the database for a version number
  2. Compare that version number to the new version number– a variable or constant in your plugin file.
  3. Update things if need be
  4. Save the new version number to the database

If all you have is a constant in your .php file. It always matches, meaning it is pretty much useless for any automated updating. Of course, you can keep track of the plugin versions with just the constant, but the point of saving it to the database is to be able to automatically update things when needed.

As you say, if the plugin is simple enough it may not be necessary.

Leave a Comment