Reply To: Setting New Role Upon Login with iMember360 Plugin
Stackoverflow came to the rescue, and I have this question to thank for it.
If you read all the comments, it gets to the solution, which in my case was this code.
function i4w_authenticated_remote_login_action($user, $contact) {
global $SESSION;
IF ($arrTAGS = explode(',', $SESSION['i4wuser']['Groups'])) :
IF (in_array(38181, $arrTAGS) || in_array(38185, $arrTAGS) || in_array(38193, $arrTAGS)) :
$user_id = get_current_user_id();
$new_role_forum_role="bbp_participant";
bbp_set_user_role( $user_id, $new_role_forum_role );
$wp_user_capabilities_arr = array("subscriber" => true, "bbp_participant" => true, "bbp_spectator" => false);
update_user_meta($user_id, "wp_capabilities", $wp_user_capabilities_arr);
ELSEIF (in_array(38177, $arrTAGS) || in_array(38195, $arrTAGS) || in_array(38183, $arrTAGS) || in_array(38187, $arrTAGS) || in_array(38189, $arrTAGS)) :
$user_id = get_current_user_id();
$new_role_forum_role=”bbp_spectator”;
bbp_set_user_role( $user_id, $new_role_forum_role );
$wp_user_capabilities_arr = array("subscriber" => true, "bbp_spectator" => false);
update_user_meta($user_id, "wp_capabilities", $wp_user_capabilities_arr);
ENDIF;
ENDIF;
}
add_filter('i4w_authenticated_remote_login', 'i4w_authenticated_remote_login_action', 1, 2);
I am a bit confused as to why I needed to use the update_user_meta to remove the additional capabilities (or why I would have had additional capabilities generated from the bbp_set_user_role function). If someone could answer that it would be greatly appreciated, as I am sure this code is not 100% efficient.