1

As when I create a new site on multisite wordpress network, then only admin user gets created. I want all users which are present on my first site to be present here too. I have tried several import and export csv plugins, but nothing is working right. Is there any other plugin?

0

How to add user to blog?

You can use add_user_to_blog function to do that. After Codex, it:

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

And you use it like so:

add_user_to_blog($blog_id, $user_id, $role);

How to do it automatically?

You want to do this automatically, when new site is created, so you'll have to write some code and use wpmu_new_blog hook.

Here's the list of it's params:

  • $blog_id (int) (optional) Blog ID of the created blog.
  • $user_id (int) (required) User ID of the user creating the blog.
  • $domain (string) (optional) Domain used for the new blog.
  • $path (string) (optional) Path to the new blog.
  • $site_id (int) (optional) Site ID. Only relevant on multi-network installs.
  • $meta (array) (optional) Meta data. Used to set initial site options.

So in your case you can use it like so:

function add_users_to_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
    // get users you want to add to new blog
    $users_to_add = new WP_User_Query( array( 'blog_id' => 1 ) );  // <-- change that 1 to proper blog id

    foreach ( $users_to_add->get_results() as $user ) {
        add_user_to_blog( $blog_id, $user->ID, 'administrator' );  // <-- change administrator to any role you need
    }
}
add_action( 'wpmu_new_blog', 'add_users_to_new_blog', 10, 6 );
0

I guess I have found perfect solution for it. There is a plugin called Multisite User Management. It easily does the task.

Just Activate it and go to Network Admin -> Settings -> Network Settings

Then there will be section called Multisite User Management. Just assign the role (which is to be given to users) for that particular site. And Save it, automatically all users will be copied to the new site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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