Skip to:
Content

BuddyPress.org

Changeset 5974


Ignore:
Timestamp:
04/10/2012 07:01:14 PM (13 years ago)
Author:
boonebgorges
Message:

Check to see whether a user is already a member of a group before creating a new membership in BP_Groups_Member::save(). Fixes #4113

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r5927 r5974  
    762762        do_action_ref_array( 'groups_member_before_save', array( &$this ) );
    763763
    764         if ( !empty( $this->id ) )
     764        if ( !empty( $this->id ) ) {
    765765            $sql = $wpdb->prepare( "UPDATE {$bp->groups->table_name_members} SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = %s, is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id );
    766         else
     766        } else {
     767            // Ensure that user is not already a member of the group before inserting
     768            if ( $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d LIMIT 1", $this->user_id, $this->group_id ) ) ) {
     769                return false;
     770            }
     771           
    767772            $sql = $wpdb->prepare( "INSERT INTO {$bp->groups->table_name_members} ( user_id, group_id, inviter_id, is_admin, is_mod, is_banned, user_title, date_modified, is_confirmed, comments, invite_sent ) VALUES ( %d, %d, %d, %d, %d, %d, %s, %s, %d, %s, %d )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent );
     773        }
    768774
    769775        if ( !$wpdb->query( $sql ) )
Note: See TracChangeset for help on using the changeset viewer.