Skip to content

Commit

Permalink
When removing user from a group, only reassign site role when necessary.
Browse files Browse the repository at this point in the history
* Don't do it if 'silent_add' is disabled.
* Don't do it if the user is not already a site member.
  • Loading branch information
boonebgorges committed Sep 19, 2016
1 parent b357df3 commit a52dcda
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bp-groupblog.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,22 @@ function bp_groupblog_changed_status_group( $user_id, $group_id ) {
* Called when user leaves.
*/
function bp_groupblog_remove_user( $group_id, $user_id = false ) {
// Only modify site membership if the plugin is configured to do so.
$settings = bp_groupblog_get_group_settings( $group_id );
if ( ! $settings['groupblog_silent_add'] ) {
return;
}

$blog_id = get_groupblog_blog_id( $group_id );

if ( ! $user_id )
$user_id = bp_loggedin_user_id();

// Users with no existing role should not be modified.
if ( ! is_user_member_of_blog( $user_id, $blog_id ) ) {
return;
}

$user = new WP_User( $user_id );
$user->for_blog( $blog_id );
$user->set_role( 'subscriber' );
Expand Down

0 comments on commit a52dcda

Please sign in to comment.