Search code examples
phpwordpresswpmu

user and blog signup at same time on wordpress multisite


I am using wordpress multisite to create blog in my main site. Wordpress multisite allows us to signup for either user or blog, but i need to create a blog and a user at the same time and the user created need to be assigned as the admin of the blog created. Well i created a user and set it as administrator by changing it's metadata (wp_capabilities, wp_user_level) but when i tried to login to the admin of the blog created then it says you don't have sufficient priviledge. Do anyone know what do i missing?

Thanks in advance.


Solution

  • You have to create a custom registration. Create a new page: registration. In the theme folder make a page-registration.php file, and in the file create your form and the registration function, that should go something like this:

    if($_POST)
        {
    
        $data=$_POST;
    
        $validateuser=wpmu_validate_user_signup($data['user_name'],$data['user_email']);
        $validateblog=wpmu_validate_blog_signup($data['user_name'],$data['blog_title']);
    
        $usererrors=$validateuser['errors']->errors;
        $blogerrors=$validateblog['errors']->errors;
    
        if(!$usererrors && !$blogerrors)
        {
            $meta = array ('lang_id' => 1,'public' => 1);
            $meta = apply_filters( 'add_signup_meta', $meta );
            $path='/'.$data['user_name'].'/';
            wpmu_signup_blog($domain,$path,$data['blog_title'],$data['user_name'],$data['user_email'], $meta);
        }
    }
    

    note: this is only an example where the new blogname is the same as your username

    leave a comment if you need more detailed instructions or have any additional questions