Almost everyone who has worked with WordPress has dealt with wp-config.php. I know – there are a lot of managed hosts out there that take care of a lot of this for you – but even though a person may not have directly edited the file, they have definitely interacted with it.

For those who are unfamiliar:

This file is located in the root of your WordPress file directory and contains your website’s base configuration details, such as database connection information.

Anyway, for sometime now, I’ve been working on a relatively large plugin for a client and have recently taken to introducing a similar type of configuration files. So this raised that question, do what you think of plugin config files?

Plugin Config Files

To be clear, I don’t think that every plugin needs a configuration file. In fact, I think that if we’re not careful, then we’re dangerously approaching placing options into config files under the guise of treat them as configuration options.

"Not even sure how to set this up."

“Not even sure how to set this up.”

If you aren’t going to make decisions about how your plugin (or theme, for that matter) is going to function, then throw the options into a settings page and have your users work on that. After all, it’s only a little more work for them).

But seriously, here’s the scenarios in which I’m finding that it may be acceptable to introduce plugin config files:

  • The plugin is portable. That is, it will be installed on several different systems each of which have their own subtle nuances in the UI but have the same functionality.
  • The plugin includes custom post types, taxonomies, constants, etc. Whether it’s one or all of the above, the plugin has its own name for each of the above all of which still function the same way in terms of the back-end code.
  • The person managing the file is technically sound. Just like `wp-config.php` is meant for those who are comfortable with editing constant values and understanding their affect, such is the case of plugin config files.

For what it’s worth, I’ve found a lot of success with these.

We’ve been able to roll this out to a number of sites and have been able to completely control the menu, the meta boxes, the custom post types, and more all through the use of the config file without actually having to change variations of the code all over the place.

Have You Done This?

For a plugin that’s installed across a variety of site handled by a technical manager, I’ve found this solution to work out well. I wouldn’t say that this is something that I’d, you know, ship into the WordPress Plugin Repository.

Even still, for those who build plugins (or themes or other WordPress related work) for a living, when are your thoughts on doing something like this?

As much as I’m finding it to be useful, I’m interested in the feedback. Hit me.