Hi
I have a function and an action that fires when a user leaves a group. When he does that he is automatically removed from the forum that belongs to the group. It works fine, but if I manually remove a user from a group in the backend, then he is not removed from the forum!
Has anyone a solution to this? Maybe I should use the action hook groups_member_after_remove?
Here is the function that works fine in frontend when the user leaves the group by himself:
add_action( 'groups_leave_group', 'cci_auto_unsubscribe_forum', 10, 2 ); // function triggered when user leaves group function cci_auto_unsubscribe_forum ( $group_id, $user_id ) { // checks to see if there's a user ID if( !$user_id ) return false; // Get's an array of forum IDs for the group $forum_ids = bbp_get_group_forum_ids( $group_id ); // checks to see if there is a forum ID if ( !empty( $forum_ids ) ) { // gets the first value from the array, assuming there is one forum $forum_id = array_shift( $forum_ids ); } // subscribes user to forum bbp_remove_user_forum_subscription( $user_id, $forum_id ); }
Thanks
Hi Ravi
Thank you for your answer. I tried to add your line just below the line with “bbp_remove_user_forum_subscription( $user_id, $forum_id );”, but it didn’t solve my problem. The user is still subscribed to the group forum after he is removed from the group by me in the backend.
Should I insert your line in another place? Eg. as an add_action?
Regards
TorbenHello Torben,
Please try the following code:
add_action( 'groups_remove_member', 'cci_auto_unsubscribe_forum', 10, 2 ); add_action( 'groups_leave_group', 'cci_auto_unsubscribe_forum', 10, 2 ); // function triggered when user leaves group function cci_auto_unsubscribe_forum ( $group_id, $user_id ) { // checks to see if there's a user ID if( !$user_id ) return false; // Get's an array of forum IDs for the group $forum_ids = bbp_get_group_forum_ids( $group_id ); // checks to see if there is a forum ID if ( !empty( $forum_ids ) ) { // gets the first value from the array, assuming there is one forum $forum_id = array_shift( $forum_ids ); } // subscribes user to forum bbp_remove_user_forum_subscription( $user_id, $forum_id ); }
Let me know if it works or not.
Regards
RaviYou are legend! It works as aspected! Thank you very much!
The topic ‘ [Resolved] How to remove member from a groups forum when member is removed from the group?’ is closed to new replies.