[wp-hackers] Best practices for upgrading plugin options?
Otto
otto at ottodestruct.com
Thu Apr 28 21:15:03 UTC 2011
On Thu, Apr 28, 2011 at 3:50 PM, Steve Bruner [SlipFire]
<sbruner at slipfire.com> wrote:
> The user chooses to delete the default text from their options, so
> "setting1" doesn't exist in the array anymore.
Instead of removing setting1 from the array, you should leave it in
the array as a blank string.
"Defaults" are *default*. That's what gets used when no entry exists.
If they've specified something other than the default, even a blank
string, then you should be storing it as what they are specifying,
even if it's a blank string.
> The user now upgrades to v2.0 of our plugin. It has some more settings, and
> I use wp_parse_args to merge the options. Since "setting1" is empty, won't
> wp_parse_args add the default text to the array? If yes, then this is the
> issue since the user removed the default text. This also happens when check
> boxes are checked on default, and then unchecked by user.
Ditto for checkboxes. You should be storing them as a boolean true or
false, and saving the false condition instead of deleting it from the
options array.
-Otto
More information about the wp-hackers
mailing list