What is the best way to store plugin settings?

You have already found the right way. What you save as $value is absolutely up to you. You can store an option for every single setting or all together in one option as an array, which you would have to read in your plugin again.

For the latter way speaks maybe, if you will use a lot of options in your plugin. Then WordPress would theoretically have to query this option only once and not start a request per setting. However, WordPress already caches the options itself, so this approach would have only marginal performance advantages.

Thanks for the answer. Before that, I stored the settings in an array (I have a lot of them). But it is not convenient to save the settings. It is necessary to pass through the entire array. If each setting is stored in a separate option, then it will be more convenient to save. I was afraid for performance, but you dissuaded me.

Well, you can try it. I have only worked with single options in my plugin so far. Thanks to the caching in WordPress of these options is not so bad. But I don’t know how it is with hundreds of options.

For example, look at how many queries to the database WordPress makes with your plugin. Helpful is this plugin: https://projectdmc.org/plugins/query-monitor/

Yes, I am aware of this plugin. Thank you!

FWIW, theme specific customizer options are all stored in a single theme_mod array. But then themes don’t typically add a huge number of options. It doesn’t need to be an either/or proposition. You could organize options into logical groups and store each group as an array or sometimes as a single value.

In the end I’m not sure it really makes much difference. I suggest you do whatever makes sense for your conceptual organization and not worry so much about any performance gains. Any potential gains are likely very small in comparison with bottlenecks that occur elsewhere.

Thank you! I consider the discussion closed.


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Your Advertisement Here