WordPress.org

Codex

WPMU Functions/add user to blog

Contents

Description

Grants the specified user permissions of the specified role on the specified blog.

Parameters

$blog_id
(integer) (required) The ID of the blog to grant permissions on.
Default: None
$user_id
(integer) (required) The ID of the user to grant the permissions to.
Default: None
$role
(string) (required) The role to grant to the specified user on the blog in question. Must be one of the WordPress roles.
Default: None

Return values

(mixed) 
Boolean true if the user exists and is successfully added to the blog. A WP_Error is returned if the specified user does not exist.

Usage

<?php add_user_to_blog($blog_id$user_id$role); ?>

Examples

<?php
  $userid 
1;
  
$blogid 5;
  
$role 'administrator';
  if ( 
add_user_to_blog$blogid$userid$role ) ) {
    echo 
'Added user '.$userid.' as '.$role.' to blog '.$blogid.'.';
  } else {
    echo 
'Failed to add user '.$userid.' as '.$role.' to blog '.$blogid.'.';
  }
?>

Notes

Executes the add_user_to_blog action prior to switching back to the current blog with restore_current_blog().