[Resolved] Programatically add new members to a group on account activation
-
WP version: 4.2 on localhost XAMPP
BP version: 2.2.2.1
WP Theme: TwentyFifteenI created bp-custom.php file and I placed the following code there:
//get user's nfl team from custom field in registration form function get_member_nfl_team() { $user_nfl_team = bp_get_profile_field_data('field=2&user_id='.bp_loggedin_user_id()); return $user_nfl_team; } //Autommatically add new members to their NFL team's group function add_members_to_nfl_group(){ global $bp; $bp_user_id = $bp->loggedin_user->id; //The user id, it works. $nfl_team = get_member_nfl_team(); // The team the user chose, it works. $nfl_team_slug = str_replace(" ", "-", strtolower($nfl_team)); //Part of the slug of the group, it works $group_slug = "aficionados-a-los-".$nfl_team_slug; // The slug of the group, it works $group_id = BP_Groups_Group::group_exists($group_slug); // The ID of the group, it works groups_accept_invite( $bp_user_id, $group_id); // Adding the member to the group, don't know if it works } add_action( 'bp_core_activated_user', 'add_members_to_nfl_group', 10, 3 ); //Calling the function on activation of new account, don't know if it works
I have been reading all threads about adding new members to groups automatically in BP, and from what I have been reading, the code above should work, but it doesn’t and I dont know what is wrong with it. I have been searching and reading for hours and nothing seems to work.
I don’t like using plugins and I’am learning BP, so, please suggest code solutions.
Any ideas?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘[Resolved] Programatically add new members to a group on account activation’ is closed to new replies.