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?

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.

1 Like

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:

I face similar issue.

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

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?

Use if SiteSetting.myplugin_enabled to check for that.

2 Likes

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:

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

3 Likes

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.

3 Likes