Quick Links to remove user from All groups or individual groups
-
I created a snippet for easily removing ALL groups or individual groups from a user’s extended profile page on the admin. I extended the Member’s Stats widget to add the links.
Add this to the functions.php file:
/*-- Add Remove All Groups from Member Option -------------*/ function bp_groups_profile_remove_groups( $args = '' ) { $r = bp_parse_args( $args, array( 'before' => '<li class="bp-groups-profile-stats">', 'after' => '</li>', 'user_id' => bp_displayed_user_id(), 'groups' => 0, 'output' => '' ), 'groups_get_profile_stats' ); // display links to the groups a user is member of $group_ids = groups_get_user_groups( $r['user_id'] ); echo '<li><a title="Remove ALL groups" href="' . wp_nonce_url( admin_url( 'users.php?page=bp-profile-edit&user_id='. $r['user_id'] .'&remove_group=all' ) ).'">Remove ALL Groups</a></li>'; foreach($group_ids["groups"] as $group_id) { echo '<li><a title="Remove group" href="' . wp_nonce_url( admin_url( 'users.php?page=bp-profile-edit&user_id='. $r['user_id'] .'&remove_group='.$group_id ) ).'"> Remove: ' . groups_get_group(array( 'group_id' => $group_id )) -> name .'</a></li>'; } } add_action( 'bp_members_admin_user_stats', 'bp_groups_profile_remove_groups', 11, 1 ); function bp_remove_groups_from_member() { if( isset( $_GET['remove_group'] ) ) { $user_id = isset( $_GET['user_id'] ) ? $_GET['user_id'] : 0; if ($user_id == 0){ return; } $group_id = $_GET['remove_group']; if( $group_id == 'all' ){ //Find Member groups and remove all $group_ids = groups_get_user_groups( $user_id ); foreach($group_ids["groups"] as $group_id) { groups_remove_member( $user_id, $group_id ); } }else { //Remove Single Group groups_remove_member( $user_id, $group_id ); } } } add_action( 'bp_members_admin_load', 'bp_remove_groups_from_member' );
Enjoy.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.