Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Enable 'Category Notifications' by default?
Jeff_s
New
Hi guys,
I want to setup my forums to default to notify all my users when a new Discussion is added to specific categories. Is that possible via something like:
$Configuration['Preferences']['Email']['MyCategoryName'] = '1';
I see requests from this previously, but no answers...
I don't my SQL hacking for my current users, but would really like to enable this automatically for new users...
0
Comments
I cannot imagine that it is doable by setting a config parameter. But a very small and easy plugin will do.
Something like that should be enough:
Please look at an example if you are not sure how a plugin for Vanilla must be named/structured
R_J - thanks! That looks really promising...
But after fiddling a bit, I see this in the UserMeta table:
Plugin.SetupNotifications.Preferences.Email.NewDiscussion.1 = 1
So, its prepending "Plugin.SetupNotifications" to the setting I'm trying to do. Makes sense, the code comments say:
Which makes sense, but is also a bummer when I really do want to change pre-existing keys.
But, all this shows what SQL scripts I need to write, so unless there's an obvious fix, I'll just go that route.
Your plugin is extending the plugin class. If you look at /library/core/class.plugin.php you will find the method
setUserMeta
with this code:What you can see is that the function creates a "metaKey" and that is something that you do not want to (I haven't thought of that, sorry)
But what you can also see is that after transforming the key somehow
$this->userMetaModel()->setUserMeta()
is called. There is nothing that prevents you from using it directly that way. In my code from the previous post, simply replace$this->setUserMeta(
by$this->userMetaModel()->setUserMeta(
and that should be all what is needed.BINGO!
Much appreciated!
@R_J thanks a lot for the solution. That worked for me in case of new users.
But, for existing 26K+ users in my forum how I'll set that?
Thanks in advance.
Well, I will tell you two things: 1. how to achieve what you've asked for and 2. that you shouldn't do it.
I start with the second one: If your users are current users and they never wanted to get notified about new discussion, changing their notification settings feels like ignoring their current decision which in the end feels like spam.
But if that for any reason doesn't apply to your situation (I didn't want to judge, just wanted to utter my concerns) here is what you have to do: the preferences are saved to the GDN_UserMeta table. For existing users I would say you should change it with an SQL. You will need to replace the number 1984 below with your CategoryID: