add_user_to_blog( int $blog_id, int $user_id, string $role )
Use the ‘add_user_to_blog’ action to fire an event when users are added to a blog.
(int) (Required) ID of the blog the user is being added to.
(int) (Required) ID of the user being added.
(string) (Required) The role you want the user to have.
(true|WP_Error) True on success or a WP_Error object if the user doesn’t exist or could not be added.
- It does not check if the user is already a member of the blog before setting their role. If you don’t want to overwrite the role of a user if they are already a member of the blog, use is_user_member_of_blog() to check that first.
- You do not need to call switch_to_blog() to switch to the blog you want to add the user to before calling this function. The function will switch to the blog itself, and restore the current blog before returning as well.