0

In Wordpress MU, how can I allow users to register for new blogs with their existing account? Right now, it seems that the site admin has to manually add them at the admin page. That would be fine with me except that the admin for the entire site will have to manually add users to blogs one by one. With hundreds of blogs and hundreds of users, that could become a full time job in itself.

Or better yet, how can I cause existing users to be automatically registered under a set role for all newly created blogs under this site? That would be the holy grail of functionality for my website. Thanks.

2 Answers 2

0

I made my own plugin to do this. It may not be the most elegant code possible, but it does what I need:

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); 
0

Or if they are exsiting users, just send them back to yourdomain.com/wp-signup.php. that;s where they can create theor own new blog by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.