Wordpress - Wordpress Multisite - When a user signs-up on main site, how to add the user to a subsite
Run add_user_to_blog()
after user creation.
You can hook on user_register()
to get newly created user ID and pass it and any conditional assignments to your callback that runs add_user_to_blog()
.
I complete @hwl's answer:
Most of the times, in a Multisite instance of WordPress, user registration includes an activation step.
In this case, it is necessary to hook actions on wpmu_activate_user
; actions hook on user_register
will be ignored. For instance:
my_function($user_id) {
// to add a user to main site (id=1) as a subscriber add_user_to_blog can be used
// more info: https://codex.wordpress.org/Function_Reference/add_user_to_blog
add_user_to_blog( '1', $user_id, 'subscriber' );
}
add_action('wpmu_activate_user','my_function',10,1);