I’m not sure if there are any plugins that do this, but it would not be too tricky to write something. If you hook into the wp_login & wp_logout actions you could add the desired role when a user logs in and then remove it when they logout. Something along these lines could do what you want.
disclaimer: the code below is untested and may have errors in it.
class role_domain_swapper {
public function __construct() {
$this->do_hooks();
$this->domain_role_map[ 'domain_A' ] = 'contributor';
$this->domain_role_map[ 'domain_B' ] = 'subscriber';
}
public function add_role( $user_login, $user ) {
global $unique_name_remapped_user_roles;
$unique_name_remapped_user_roles[] = $user->ID;
$user->add_role( $this->domain_role_map[ $_SERVER['SERVER_NAME'] ] );
}
public function remove_role() {
$current_user = wp_get_current_user();
global $unique_name_remapped_user_roles;
if( in_array( $current_user->ID, $unique_name_remapped_user_roles ) ) {
$current_user->remove_role( $this->domain_role_map[ $_SERVER['SERVER_NAME'] ] );
}
}
private function do_hooks() {
add_action( 'wp_login', array( $this, 'add_role' ), 10, 2 );
add_action( 'wp_logout', array( $this, 'remove_role' ) );
}
private $domain_role_map;
}