[wp-hackers] Best practices for upgrading plugin options?
Sean Newham
seanseviltwin at gmail.com
Thu Apr 28 18:36:36 UTC 2011
It's probably not best practice, but why don't you keep your current
setting/installation configuration, then append the extra details to the
array when an upgrade is performed using array_merge?
On 28 Apr 2011 19:32, "Steve Bruner [SlipFire]" <sbruner at slipfire.com>
wrote:
> 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.
>
> Thanks
> Steve
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list