Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can you make a role to subscribe a forum?


  • madflute
    Participant

    @madflute

    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.

Viewing 18 replies - 1 through 18 (of 18 total)

  • Robin W
    Moderator

    @robin-w

    I think this has what you need

    bbPress Toolkit


    madflute
    Participant

    @madflute

    Hmmm, I do have this plugin installed but couldn’t find the way. I need to go over the documentation again. Thank you.


    Robin W
    Moderator

    @robin-w

    just looked, yes that seems to only apply to new users


    madflute
    Participant

    @madflute

    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.


    Robin W
    Moderator

    @robin-w

    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 it


    madflute
    Participant

    @madflute

    Thank 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.


    Robin W
    Moderator

    @robin-w

    agree line 2, and line 4 should be

    $user_id = $user->ID ;


    madflute
    Participant

    @madflute

    Thank you! I just ran it and worked beautifully (as far as I can tell)!


    Robin W
    Moderator

    @robin-w

    great


    tracykistler
    Participant

    @tracykistler

    @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?


    Robin W
    Moderator

    @robin-w

    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' ) ;
    }

    tracykistler
    Participant

    @tracykistler

    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’ ) ;
    }


    Robin W
    Moderator

    @robin-w

    update_option (‘rew_done’ , ‘done2’ ) ;

    should read

    update_option (‘rew_done2’ , ‘done2’ ) ;


    tracykistler
    Participant

    @tracykistler

    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…


    Robin W
    Moderator

    @robin-w

    can you post the code you are using


    enkoes
    Participant

    @enkoes

    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.


    Robin W
    Moderator

    @robin-w

    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' ) ;

    }


    enkoes
    Participant

    @enkoes

    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.

Viewing 18 replies - 1 through 18 (of 18 total)
  • You must be logged in to reply to this topic.
Skip to toolbar