[wp-hackers] How do you store multiple plugin options
jpotkanski at tribune.com
Wed Mar 24 17:56:42 UTC 2010
Storing database variables in an array should be considered a bad practice. Doing this is as an convenient hack that shortens plugin design but has significant consequences.
Serialized data in the blog options table denormalizes the database. ReCaptcha uses one blog option setting called reCaptcha. If I want to update the keys across all my blogs in a wordpress MU install, I can not do it via SQL alone, I have to write a php plugin to tinker with the values. (Yes, I know reCaptcha has MU installation option and configuration file). Where I could have help from a DBA to fix something, I now need a developer.
Denormalization also means I couldn't have any systems integration or monitoring on database values without custom plugins. Other programming languages such as Java or Ruby don't have the same serialization functions PHP does, so any other development work that may need access to Wordpress data is restricted to PHP.
There are autoload features of blog options tables which many plugins are not taking advantage of.
There may also be performance penalties to serializing and deserializing arrays all the time that cause performance problems on high traffic sites.
Correct practice should be to avoid serialized arrays where possible and use proper prefixing in blog options to avoid collisions with other plugins.
On 3/24/10 10:06 AM, "Otto" <otto at ottodestruct.com> wrote:
On Tue, Mar 23, 2010 at 6:06 PM, Peter van der Does
<peter at avirtualhome.com> wrote:
> Everybody knows, or at least should know, that storing every variable
> as an option is a bad idea. You usually use an array and store the
I discuss some of this in my Settings API tutorial:
But, in general, the way you want to do it is as follows: Anything
that you will load all the options for at once (presumably because
you're using all or most of them) should be in one single option. The
majority of plugins should put all their options in one field, for
simplicity. Only rarely do you actually need extra options fields.
More information about the wp-hackers