Add New Network Users to the Main Site
Adds every newly registered user to the main site with a role you choose, so members of any subsite also have an account on your hub site.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
$wpide_role = 'subscriber'; // Role on the main site.
$wpide_add = function ( $user_id ) use ( $wpide_role ) {
$main = get_main_site_id();
if ( ! is_user_member_of_blog( $user_id, $main ) ) {
add_user_to_blog( $main, $user_id, $wpide_role );
}
};
add_action( 'wpmu_new_user', $wpide_add );
add_action( 'wpmu_activate_user', $wpide_add );
Notes
Change $wpide_role. Users who are already members of the main site are left alone.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.