add user to group when user is added via dashboard
-
Hi,
I have created a group and want to add user to it automatically whenever the admin create the new user from WordPress user dashboard. I am using the following code snippet –
function automatic_group_membership_bp($user_id) { //if no user id return if (!$user_id) { return false; } // 1 is the group id $group_id = 1; //Get user meta to find the role $user_meta = get_userdata($user_id); $user_roles = $user_meta->roles; //only add user to group if it subscriber if (in_array("subscriber", $user_roles)) { $update_bp_user_last_activity = bp_update_user_last_activity($user_id, date("Y-m-d H:i:s")); //Buddypress hook to add member to a group $status = groups_join_group($user_id, $group_id); } } add_action('user_register', 'automatic_group_membership_bp', 10, 3);
I am adding a user with role subscriber to group. $status returns 1 that means the user is getting added to the group. I can even see the user in http://siteurl/members list. But I cannot see the user in a group. I am not sure what I am missing here, can you please help me out.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.