[wp-hackers] Best practices for upgrading plugin options?

Steve Bruner [SlipFire] sbruner at slipfire.com
Thu Apr 28 18:31:17 UTC 2011

Hi Everyone,

Any help with this would be greatly appreciated.

Our current plugin has over ten releases, some major and some minor.  For
most of the versions the plugin options have remained the same. We keep the
default settings in an array. When the plugin is initially activated we add
the defaults using add_option.  Here's an example of the array.
$default_setings = array(

"setting1" => "on",

"setting2" => "This is a text field"


Now we are coming out with another version of the plugin, and we're adding
more settings, and creating the upgrade function.  Writing the function to
trigger on the upgrade is not a problem.  However, we're having an issue
figuring out the best way to upgrade the actual settings.  The new
default_settings array would look like this:
$default_setings = array(

"setting1" => "on",

"setting2" => "This is a text field",
"setting3" => "style1"


First we thought we could just run the default_settings array on upgrade as
well using update_option. This would ignore setting1 and setting2 since they
already exist and just add setting3.  However, if the user decides to
uncheck setting1 or delete the text in setting2, running update_option will
add them back in using the defaults.

We're planning on adding lots of new options in future versions, so creating
different settings arrays for each version seems a bit tedious.

If anyone has any best practices or examples on how to implement this, I
would appreciate it.


More information about the wp-hackers mailing list