代码之家  ›  专栏  ›  技术社区  ›  Dylan West

在WordPressMU中,如何允许用户使用现有帐户注册新博客?

  •  0
  • Dylan West  · 技术社区  · 16 年前

    在WordPressMU中,如何允许用户使用现有帐户注册新博客?现在,似乎站点管理员必须在管理页面手动添加它们。这对我来说没什么问题,只是整个网站的管理员必须逐个手动将用户添加到博客中。拥有数百个博客和数百个用户,这本身就可能成为一份全职工作。

    或者更好的是,如何使现有用户自动注册到该站点下所有新创建的博客的设置角色下?这将是我的网站功能的圣杯。谢谢。

    2 回复  |  直到 16 年前
        1
  •  0
  •   Dylan West    16 年前

    我做了自己的插件。它可能不是最优雅的代码,但它满足了我的需要:

    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); 
    
        2
  •  0
  •   Andrea_r    16 年前

    或者,如果他们是现有用户,只需将他们发送回yourdomain.com/wp-signup.php即可。那个;默认情况下,他们可以在这里创建自己的新博客。