add_user_to_blog() wordpress function and usage This text is not used because the data attribute has a value

add_user_to_blog() wordpress function and usage

Home / WordPress / WordPress Wiki / add_user_to_blog() wordpress function and usage

add_user_to_blog( int $blog_id, int $user_id, string $role )
Adds a user to a blog, along with specifying the user’s role.

Description

Use the ‘add_user_to_blog’ action to fire an event when users are added to a blog.

Parameters

$blog_id

(int) (Required) ID of the blog the user is being added to.

$user_id

(int) (Required) ID of the user being added.

$role

(string) (Required) The role you want the user to have.

Return

(true|WP_Error) True on success or a WP_Error object if the user doesn’t exist or could not be added.

More Information

  • 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.

 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments