[wp-hackers] Best practices for upgrading plugin options?
Philip Walton
philip at philipwalton.com
Thu Apr 28 19:09:15 UTC 2011
Steve, as long as you're only adding additional items to your option in
future releases, using wp_parse_args() against the defaults should
always work. If a user has old settings stored in the database (meaning
they are missing the new items in the options array), they will be
seamlessly merged with the new defaults and updated the next time the
user saves.
This gets a little tricky when you're not just adding a new item but you
want to change the way an old item is used. In such cases I'd recommend
creating a new item entirely and deprecating the old one. That will give
you the ability to check if a deprecated item is still stored in the
options table and allow you to deal with it or (if absolutely necessary)
inform the user in an admin alert that they need to update their options
because of new functionality.
Philip
On 4/28/11 11:44 AM, Steve Bruner [SlipFire] wrote:
> Hi Sean,
>
> Thanks for the suggestion. The issue is that we are going to release future
> versions with different settings and defaults, and we don't know which
> version the user is upgrading from, so we would have to keep each default
> settings array in all future versions. I was hoping for a cleaner solution.
>
> 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