Efficient way of saving plugin options

I’m considering the saving of options for a plugin I’m developing. The first obvious candidate is the wp_options table.

While reading the Pro WP Plugin Development book I came across this:

Every option saved adds a new record in WordPress ’ option table. You can simply store several
options at once, in one array: This avoids cluttering the database and updates the values in one single MySQL query for greater efficiency and speed.

On the other hand, I also imagine that if the plugin has a lot of settings it may hinder performance to store everything in one array. Would it therefore make sense to split options into separate records in such cases?

Third option I can think of is to create custom tables to store the plugin settings, as I’ve seen some plugins do this as well.

What are the rules/guidelines to decide which way to go?

2 Answers
2

Store the options in a single array and write your plugin as a class. Load the options in the constructor and save it as a member variable and you’ll have access to it everywhere in the plugin.

Leave a Comment