Я сделал свой собственный плагин для этого. Возможно, это не самый элегантный код, но он делает то, что мне нужно:
function set_user_role($blog_id,$user_id)
{
$users = get_users();
// register each user to the new website.
foreach($users as $user=>$userid)
{
if($user_id == 1)
{
add_user_to_blog( $blog_id, $userid, "administrator" );
}
//auto register a new user for all previous blogs.But will this create duplicates for existing users? Nope. It doesn't!
else if($user_id == $userid)
{
//add_user_to_blog( $blogid, $user_id, "administrator" );
$blogs = get_blogs();
foreach($blogs as $blog=>$blogid)
{
//if this is the blog the user just created, then let them be an admin.
if($blogid == $blog_id )
add_user_to_blog( $blogid, $user_id, "administrator" );
else
add_user_to_blog( $blogid, $user_id, "subscriber" );
}
}
else
add_user_to_blog( $blog_id, $userid, "subscriber" );//if user is not an admin and not a new user, then just make them a subscriber.
}
}
function get_users()
{
global $wpdb;
$userids = $wpdb->get_col( $wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC", $szSort ));
return $userids;
}
function get_blogs()
{
global $wpdb;
$blogids = $wpdb->get_col( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY path", $wpdb->siteid));
return $blogids;
}
//When a new blog is created, auto-register all unblocked users for it.
add_action('wpmu_new_blog','set_user_role', 100, 2);