groups_member_before_save for restricting one group per user
-
Hello,
I want to restrict memberships to only one private group and multiple public groups. I was thinking of using the hook groups_member_before_save to do that validation. Is that the correct place?
This is how i researched..
in groups_join_group we have
$new_member = new BP_Groups_Member; $new_member->group_id = $group_id; $new_member->user_id = $user_id; $new_member->inviter_id = 0; $new_member->is_admin = 0; $new_member->user_title = ''; $new_member->date_modified = bp_core_current_time(); $new_member->is_confirmed = 1; if ( !$new_member->save() ) return false;
and in BP_Groups_Member we have
public function save() { global $wpdb; $bp = buddypress(); $this->user_id = apply_filters( 'groups_member_user_id_before_save', $this->user_id, $this->id ); $this->group_id = apply_filters( 'groups_member_group_id_before_save', $this->group_id, $this->id ); $this->inviter_id = apply_filters( 'groups_member_inviter_id_before_save', $this->inviter_id, $this->id ); $this->is_admin = apply_filters( 'groups_member_is_admin_before_save', $this->is_admin, $this->id ); $this->is_mod = apply_filters( 'groups_member_is_mod_before_save', $this->is_mod, $this->id ); $this->is_banned = apply_filters( 'groups_member_is_banned_before_save', $this->is_banned, $this->id ); $this->user_title = apply_filters( 'groups_member_user_title_before_save', $this->user_title, $this->id ); $this->date_modified = apply_filters( 'groups_member_date_modified_before_save', $this->date_modified, $this->id ); $this->is_confirmed = apply_filters( 'groups_member_is_confirmed_before_save', $this->is_confirmed, $this->id ); $this->comments = apply_filters( 'groups_member_comments_before_save', $this->comments, $this->id ); $this->invite_sent = apply_filters( 'groups_member_invite_sent_before_save', $this->invite_sent, $this->id ); /** * Fires before the current group membership item gets saved. * * Please use this hook to filter the properties above. Each part will be passed in. * * @since 1.0.0 * * @param BP_Groups_Member $this Current instance of the group membership item being saved. Passed by reference. */ do_action_ref_array( 'groups_member_before_save', array( &$this ) ); // The following properties are required; bail if not met. if ( empty( $this->user_id ) || empty( $this->group_id ) ) { return false; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘groups_member_before_save for restricting one group per user’ is closed to new replies.