I’m looking for advice on the best way to store a series of settings for a modular theme.

To note:

  • The settings will not be user facing (not suitable for the customiser
    api).
  • Ideally the options would not be stored in the database as they will be static (for performance).
  • The theme is not public, it will be used as a framework for multiple sites.

I have discarded add_option / get_option which uses the database, and likewise for get_theme_mod / set_theme_mod.

Am currently using a global scoped array – which is not ideal (from what I read).

Any other thoughts / suggestions?

2 s
2

If a user can not change them then they are not options, they are constants. Declare them using const in your maim theme file (probably functions.php but any other files that is being always loaded will do), and use them wherever you have use the “options” array now.

If you want to control it without editing you theme files, you can use a conditional define instead (check if value is not defined yet and if not define it). That way you will be able to override the default values by defining them at the wp-config.php file per site.

… But this all question sounds wrong. The DB is there, so just use it, and a basic UI to control the options is easy to come up with. There is no real reason to resort to code changes every time you want to active/deactivate a module.

Leave a Reply

Your email address will not be published. Required fields are marked *