Index: src/includes/extend/buddypress/groups.php
===================================================================
--- src/includes/extend/buddypress/groups.php	(revision 5567)
+++ src/includes/extend/buddypress/groups.php	(working copy)
@@ -98,6 +98,15 @@
 
 		// Adds a hidden input value to the "Group Settings" page
 		add_action( 'bp_before_group_settings_admin', array( $this, 'group_settings_hidden_field'    ) );
+
+		// When a member is banned from a group, unsubscribe from forum and its topics
+		add_action( 'groups_ban_member', 			 array( $this, 'leave_group_unsubscribe'), 10, 2	);	
+
+		// When a member is removed from a group, unsubscribe from forum and its topics
+		add_action( 'groups_remove_member', 		array( $this, 'leave_group_unsubscribe'), 10, 2		);
+
+		// When a member leaves a group, unsubscribe from forum and its topics
+		add_action( 'groups_leave_group', 			array( $this, 'leave_group_unsubscribe'), 10, 2		);
 	}
 
 	/**
@@ -1462,5 +1471,129 @@
 
 		return $args;
 	}
+
+
+/**
+	 * Unsubscribe user from all forums and topics when leaving a group
+	 *
+	 * @since 
+	 *
+	 * @param int $group_id  ID of the group.
+	 * @param int $user_id The user whose subscriptions need to be deleted.
+	 * @return bool true if any have been deleted
+	 */
+	public function leave_group_unsubscribe( $group_id, $user_id ){
+
+		$unsub = false;
+
+		// By default, everything is unfavorited and unsubscribed when someone leaves or gets banned or removed
+		// true means "unsubscribe and unfavorite", false means "leave as is" 
+		// eg 'ban_public' => true means if someone is banned from a public group, 
+		// they will be unsubscribed and their favorites will be removed.
+		$defaults = array(
+			'leave_hidden' => true, 
+			'leave_private' => true,
+			'leave_public' => true,
+			'remove_hidden' => true,
+			'remove_private' => true,
+			'remove_public' => true,
+			'ban_hidden' => true,
+			'ban_private' => true,
+			'ban_public' => true
+		);
+
+		
+		$args = array();
+		
+		// You can change the defaults by using add_filter( ' bbp_before_group_unsubscribe_parse_args', 'your_function')
+		// your_function() should return an array with whatever you'd like to change. 
+		$args = bbp_parse_args( $args, $defaults, $filter_key = 'group_unsubscribe'  );
+
+		// Is a user leaving / being removed / getting banned
+		$current_filter = current_filter();
+		
+		if( $current_filter == 'groups_remove_member'){
+			$action = 'remove';
+		} elseif( $current_filter == 'groups_ban_member'){
+			$action = 'ban';
+		} else {
+			$action = 'leave';
+		}
+
+		$statuses = array();
+
+		// Make an array of the statuses to act upon for the action (leave / remove / ban)
+		foreach( $args as $key => $value ){
+			if ( strpos( $key, $action ) !== false && $value == true ){
+				$status = explode( '_', $key );
+				$statuses[] = $status[1];
+			}
+		}
+
+		// What is the group status?
+		$group_status = groups_get_group( array( 'group_id' => $group_id  ) ) -> status;
+
+		// If this status is not in the array of statuses, bail
+		if( ! in_array( $group_status, $statuses ) ){
+			return false;
+		}
+
+		// Get the forum associated with the group, if there's none, bail
+		$forums = groups_get_groupmeta( $group_id, 'forum_id' );
+		if( empty( $forums ) ){
+			return false;
+		}
+
+		// Get the user's forum and topic subcriptions
+		$forum_subscriptions = bbp_get_user_subscribed_forum_ids( $user_id );
+		$topic_subscriptions = bbp_get_user_subscribed_topic_ids( $user_id );
+
+		// Get the user's topic favorites
+		$topic_favorites = bbp_get_user_favorites_topic_ids( $user_id );
+		
+		//  If no subscriptions, bail
+		if( empty( $forum_subscriptions ) && empty( $topic_subscriptions) && empty( $topic_favorites ) ){
+			return false;
+		}
+	
+		// Loop over all of the forums to get all the topics
+		foreach( $forums as $forum ){
+	
+			// Unsubscribe if subscribed to the forum
+			if( in_array( $forum, $forum_subscriptions ) ){			
+					bbp_remove_user_subscription( $user_id, $forum );
+					$unsub = true;
+			}
+		
+			// Get all the child topics for the forum
+			$topics = bbp_get_all_child_ids( $forum, 'topic' );
+		
+			// Get the child topics which are also in the user's topic subscriptions
+			$group_topics_subscribed = array_intersect( $topics, $topic_subscriptions );
+
+			// Get the child topics which are also in the user's topic favorites
+			$group_topics_favorited = array_intersect( $topics, $topic_favorites );
+
+	
+			// Unsubscribe them after checking if there are any 
+			if( !empty( $group_topics_subscribed ) ){
+				foreach( $group_topics_subscribed as $group_topic_subscribed ){
+					bbp_remove_user_subscription( $user_id, $group_topic_subscribed );
+					$unsub = true;
+				}
+			}
+
+			// Unfavorite (defavorite?) them after checking if there are any 
+			if( !empty( $group_topics_favorited ) ){
+				foreach( $group_topics_favorited as $group_topic_favorited ){
+					bbp_remove_user_favorite( $user_id, $group_topic_subscribed );
+					$unsub = true;
+				}
+			}
+		}
+
+		return $unsub;
+	}
+
 }
 endif;
