bp_member_add_auto_join_groups( int $user_id, $key, $user )
Add members to Auto Group Membership Approval based on their profile type.
Description
Parameters
- $user_id
-
(Required) The user ID to add the Auto Group Membership Approval.
Source
File: bp-members/bp-members-functions.php
function bp_member_add_auto_join_groups( $user_id, $key, $user ) { $user_member_type = bp_get_member_type( $user_id ); // Get post id of selected profile type. $post_id = bp_member_type_post_by_type( $user_member_type ); // Get selected Auto Membership Approval group types. $group_types = get_post_meta( $post_id, '_bp_member_type_enabled_group_type_auto_join', true ); if ( !empty( $group_types ) && isset( $group_types ) ) { foreach ( $group_types as $group_type ) { $groups_args = array( 'object' => 'groups', 'per_page' => 0, 'group_type' => array( $group_type ), ); if ( bp_has_groups( $groups_args ) ) : while ( bp_groups() ) : bp_the_group(); $group_id = bp_get_group_id(); // check if already member $membership = new BP_Groups_Member( $user_id, $group_id ); if( !isset($membership->ID) ){ // add as member groups_accept_invite($user_id, $group_id); } endwhile; endif; } } }
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.