Plugin setting naming conventions?


(Mittineague) #1

Continuing the discussion from Rails Girls SoC Banter:

Some good points have been brought up.

Though it is possible to name a property something like “enable” where it actually disables when the value is true without breaking the code, it sure could be confusing to others and self after the code has grown cold. AFAIK there is no “rule” in this regard, but descriptive naming is a very good idea.

In that vien, re “discourse-___"
It seems logical to have “discourse” in a plugin name as that is what it works with. (there’s descriptive naming again) - BUT- I know when I wrote some WordPress plugins a few years ago I got in the habit of prefixing my class / function names with "mittineague
” to prevent the possibility of conflicts.

So, for example, instead of my naming a plugin
discourse-whatever
I could name it
mittineague-discourse-whatever

More verbose, true, but as the number of Discourse plugins is growing, maybe doing similar is a good idea?


(cpradio) #2

The unwritten rule (actually maybe it is written in @eviltrout’s how-tos?), is to prefix your settings with your plugin name.

So in the above case, all settings should be under discourse-adplugin adplugin instead of adsense_plugin, the latter which is already taken.

Now granted, the GitHub - discoursehosting/discourse-adsense: Google AdSense plugin for Discourse forum plugin isn’t using discourse-adsense for its plugin settings either…

I agree with @michaeld’s complaint, that using the exact same setting names is going to cause more problems down the line. It would be nice if the newer adsense plugin would adjust their setting names to be unique.


(Michael - DiscourseHosting.com) #3

How I interpret this:

Plugin name: adsense
Github repository: discourse-adsense (after all, I can have a wordpress-adsense repo as well)
Settings key: adsense_plugin
Settings names: adsense_settingname

So…:

Plugin name: xyz
Github repository: discourse-xyz
Settings key: xyz_plugin
Settings names: xyz_settingname


Rails Girls 2015 SoC Banter
(cpradio) #4

Yes, exactly. It is pretty much an unwritten rule. I’ve tried to go over @eviltrout’s how to on site settings, but it doesn’t actually address what to use for your setting prefix (at least when I briefly skimmed it, I didn’t see any direct statement about it).

I’ve laid out my plugins the exact same way as you described.

I’ve struck out the slightly misleading statements in my prior post to make my intent clearer. :smile:


(Robin Ward) #5

It is definitely not official yet. We are trying to figure out good conventions as we go along. Those are the ones that have worked well for us so far and we are likely to continue to using them.