$blog ) { if( is_user_member_of_blog( $user_id, $blog[ 'blog_id' ] ) ) continue; switch_to_blog( $blog[ 'blog_id' ] ); $role = get_option( 'msum_default_user_role', 'none' ); // if no default set, use 'none' if( $role != 'none' ) add_user_to_blog( $blog[ 'blog_id' ], $user_id, $role ); restore_current_blog(); } update_user_meta( $user_id, 'msum_has_caps', 'true' ); } // When a user activates their account, allocate them the default role set for each site. This plugin needs to be in mu-plugins folder for this to work, otherwise role will be allocated on login. add_action( 'wpmu_activate_user', 'msum_add_roles', 10, 1 ); // For users activating both a blog and an account function msum_activate_blog_user( $blog_id, $user_id ){ msum_add_roles( $user_id, $blog_id ); } add_action( 'wpmu_activate_blog', 'msum_activate_blog_user', 10, 2 ); //If plugin is not in mu-plugins folder, allocate roles on login. function msum_maybe_add_roles( $user_login ) { $userdata = get_userdatabylogin( $user_login ); if( $userdata != false && get_user_meta( $userdata->ID, 'msum_has_caps', true ) != 'true' ){ msum_add_roles( $userdata->ID ); } } add_action( 'wp_login', 'msum_maybe_add_roles', 10, 1 ); add_action( 'social_connect_login', 'msum_maybe_add_roles', 10, 1 ); // Role assignment selection boxes on the 'Site Admin | Options' page function msum_options(){ $blogs = get_blog_list( 0, 'all' ); echo '
' . __( 'No public, safe sites available.', 'msum' ) . '
'; } else { echo '' . __( 'Select the default role for each of your sites.', 'msum' ) . '
'; echo '' . __( 'New users will receive these roles when activating their account. Existing users will receive these roles only if they have the current default role or no role at all for each particular site.', 'msum' ) . '
'; echo '