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?
AI-generated summary
Users are experiencing issues with the “enabled” checkbox in their plugin’s site settings not working as expected. jack2 and leo.proctor have found that unchecking the box doesn’t disable their plugins, despite following the guidelines for creating custom settings.
According to cpradio, the checkbox is meant for the plugin developer to disable their plugin’s behavior in code, not for Discourse to automatically load or unload the plugin.
To enable or disable plugin code based on the myplugin_enabled value, michaeld suggests using if SiteSetting.myplugin_enabled. However, leo.proctor is confused about the purpose of enabled_site_setting :myplugin_enabled, as it doesn’t seem to make a difference in their plugin’s functionality.
michaeld explains that enabled_site_setting is an on/off switch that shows up on the Admin / Plugins screen, while riking notes that Discourse relies on the plugin code to check the setting and doesn’t have a clean way to undo the effects of a loaded plugin.
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 ![]()
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.
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 ![]()
It’s an on/off switch with the special property that it shows up on the Admin / Plugins screen.
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.