Plugin development: site settings "enabled" checkbox not working


I declared a myplugin_enabled site setting in config/settings.yml, config/locales/server.en.yml and plugin.rb (as described here),.
However, I’ve recently discovered that unchecking the box doesn’t disable my plugin. The plugin is loaded - and works correctly, including accessing other site settings - whatever the checkbox state.
Any hint?

(cpradio) #2

That isn’t how that setting is meant to work. It is meant for you to disable your plugins behavior (in code) . Your plugin still gets loaded.


Thanks @cpradio, that helps a lot.
Maybe this could be clarified in the @eviltrout’s page I mentioned earlier.
I guess the enabled_site_setting :myplugin_enabled line relates to “multisite setup”, as stated here, but at this stage I have no idea what it is :slight_smile:

(Leo) #4

I face similar issue.

enabled_site_setting :myplugin_enabled
after_initialize do
  ::Topic.class_eval do
    after_commit do
      #myplugin code

No matter if myplugin_enabled is true/false, myplugin code is executed. I don’t see any use for enabled_site_setting either. Can anyone explain what exactly it is? How can I enable/disable myplugin code based on myplugin_enabled value?

(Michael - #5

Use if SiteSetting.myplugin_enabled to check for that.

(Leo) #6

Yeah, that is how I’m currently doing it. But I don’t see any use for enabled_site_setting: myplugin_enabled. It doesn’t make any difference if I keep/remove it. I’m trying to understand it. As explained here, it turns our features on and off :confused:

(Michael - #7

It’s an on/off switch with the special property that it shows up on the Admin / Plugins screen.

(Kane York) #8

Discourse doesn’t actually have a clean way to undo the effects of a loaded plugin, so it trusts the plugin code to be checking that setting instead.