Automatically add members to Buddypress groups after subscribing

I'm using the Membership plugin and I'd like to automatically add new subscribers to a specific Buddypress group - is this possible?

Is the way to do this via Subscription Pings?

If so could you point me to a sample snippet that I could use?

i.e. when someone subscribes to XYZ Subscription they would be automatically added to a corresponding XYZ Buddypress group

  • aecnu

    Greetings locomo,

    Thank you for this great question and a significant item to bring up.

    I'm using the Membership plugin and I'd like to automatically add new subscribers to a specific Buddypress group - is this possible?

    Thanks for bringing this up, it certainly sounds like a useful customization to the plugin.

    Unfortunately, it is not currently available but we would love to put it into consideration for future development

    It might take a bit longer than useful but I'll see if I can get the lead developer in here to assist / give us some advice... in the meantime if you could post the results / problems you've come across doing it yourself here that would definitely help too.

    Alternatively, you could see if there's a developer available at wpmu jobs who could get onto it right this minute.

    Cheers, Joe

  • aecnu

    Greetings locomo,

    Thank you for the additional questions, they are certainly appreciated.

    what would be really helpful if anyone knows is how to programmatically add a user to a buddypress group - does buddypress have an API ?

    Have you asked Buddy press this question and if so what was their answer?

    Please advise in detail for the benefit of other members wanting to know the same if/when you get a solid answer.

    What is happening is that even though you have asked a question directly related to Word Press, in which we certainly try to help even if it is not our product, we do not have a Buddy Press team member here to answer questions about their product coding or API's.

    I am not a coder and it puts me in an awkward position that as a support team member I do not have access to a Buddy Press coder or team member to consult with about these types of technical questions, which therefore makes it virtually impossible to answer questions I do not know about concerning their product.

    I mention this because I truly want to help in any way I can but considering these circumstances I do not know what else to do but refer you the the Buddy Press team.

    Sincerely, Joe

  • locomo

    here's my solution - wasn't able to figure this out with Subscription Pings yet, but I was able to hook into Membership actions

    i placed this code in my theme's functions.php file

    function auto_join_buddypress_group( $sub_id, $level, $order, $userid ) {
    	global $bp;
    	switch ( $sub_id ) {
    		case 1: // subscription 1
    			groups_accept_invite( $userid, 13 ); // replace 13 with the group id
    			break;
    		case 2: // subscription 2
    			groups_accept_invite( $userid, 21 ); // replace 21 with the group id
    			break;
    	}
    }
    
    add_action( 'membership_add_subscription', 'auto_join_buddypress_group', 100, 4 );

    and if you want to remove a member from a group when their subscription is dropped you can use this:

    function auto_drop_buddypress_group( $sub_id, $level, $userid ) {
    	global $bp;
    	switch ( $sub_id ) {
    		case 1: // subscription 1
    			groups_remove_member( $userid, 13 ); // replace 13 with the group id
    			break;
    		case 2: // subscription 2
    			groups_remove_member( $userid, 21 ); // replace 21 with the group id
    			break;
    	}
    }
    
    add_action( 'membership_drop_subscription', 'auto_drop_buddypress_group', 100, 3 );

    cheers