Can you make a role to subscribe a forum?
-
Hi, I need to make all the 500+ Subscriber role users subscribe to the Announcement forum as well as the General Discussion forum in batch. Is it possible?
Thank you.
-
I think this has what you need
Hmmm, I do have this plugin installed but couldn’t find the way. I need to go over the documentation again. Thank you.
just looked, yes that seems to only apply to new users
Yup, I already have that option turned on. Now I still don’t know what to do with 500+ Subscribers who are not subscribed to the forums. Any ideas would be appreciated.
This code (untested) should subscribe all current users to forum ID 3
$list = get_users(); if (empty (get_option ('rew_done')) { foreach ($list as $user) { $user_id = $user=>ID ; $forum_id = 3 ; bbp_add_user_forum_subscription( $user_id, $forum_id ) ; } update_option ('rew_done' , 'done' ) ; }
Put this in your child theme’s function file – or use
https://en-gb.wordpress.org/plugins/code-snippets/ and load a page, then remove itThank you so much for the snippets. I am no developer and have been struggling with this, to be honest.
I think line 2 is missing a closing ‘)’ and
Getting a parse error on line 4. Is ‘=>’ supposed to be ‘->’ or something else is upsetting the parser? Any help would be appreciated.agree line 2, and line 4 should be
$user_id = $user->ID ;
Thank you! I just ran it and worked beautifully (as far as I can tell)!
great
@robin-w I was able to use this code to subscribe all of our members to our main forum and it worked great. Thank you! I have since tried to run it to subscribe them to our other two forums and it’s not working. Any idea what I can do to get them subscribed to the others?
the update_option bit stops it being run more than once.
so to run it a 2nd time use
$list = get_users(); if (empty (get_option ('rew_done2')) { foreach ($list as $user) { $user_id = $user->ID ; $forum_id = 3 ; bbp_add_user_forum_subscription( $user_id, $forum_id ) ; } update_option ('rew_done2' , 'done2' ) ; }
Hmm, I tried below updating the forum id and it didn’t work.
$list = get_users();
if (empty (get_option (‘rew_done2’)) {
foreach ($list as $user) {
$user_id = $user->ID ;
$forum_id = 327 ;
bbp_add_user_forum_subscription( $user_id, $forum_id ) ;
}
update_option (‘rew_done’ , ‘done2’ ) ;
}update_option (‘rew_done’ , ‘done2’ ) ;
should read
update_option (‘rew_done2’ , ‘done2’ ) ;
I tried updating the line and it causes a critical error to the site. I have been working on a staging site so it hasn’t been a huge problem. I would really appreciate any additional help you can provide though. If we can’t find a way to run the script we will have to manually subscribe everyone and that will take ages…
can you post the code you are using
Hi, just want to know how can we make the codes below role-specific? e.g. auto-subscribe moderator to forum with ID 3.
$list = get_users(); if (empty (get_option ('rew_done'))) { foreach ($list as $user) { $user_id = $user->ID ; $forum_id = 3 ; bbp_add_user_forum_subscription( $user_id, $forum_id ) ; } update_option ('rew_done' , 'done' ) ; }
Regards.
this should do it
$list = get_users(); if (empty (get_option ('rew_done'))) { foreach ($list as $user) { $user_id = $user->ID ; $role = bbp_get_user_role( $user_id ); if ($role == 'bbp_moderator') { $forum_id = 3 ; bbp_add_user_forum_subscription( $user_id, $forum_id ) ; } } update_option ('rew_done' , 'done' ) ;
}
Thanks @robin-w, it works beautifully!
For anyone who want to execute the code 2nd time (or more), reset the ‘rew_done’ option by running
update_option('rew_done', '');
before activating the code again.Regards.
- You must be logged in to reply to this topic.