Thank you for reporting this important issue.
And thank you for your patience with us over the weekend.
I’m not familiar with the achivements plugin myself, but it sounds like it’s doing something similar to what bbPress does (adding capabilities to certain Users).
What you’ll need to do is two things. First off, this thread goes over how you add Capabilities to Roles directly:
http://wordpress.stackexchange.com/questions/13413/how-to-add-a-capability-to-a-user-role
You’ll want to get all of the capabilties that are required for your external plugin, and add them like this:
<?php
$role = get_role('subscriber'); // For Subscriber Role
$role->add_cap($cap_name);
$role->add_cap($another_cap);
By the looks of your code snippet, you’ve gotten that far. The issue with your code *probably* has to do with this call:
dpa_get_caps_for_role( $role )
If the name of that function is correct, then this is only looking for the Capabilities for the achievement plugin the Role already has. You need to add the roles that it does not have. Try looking at the plugin’s API or ask the developer if there is a list of required Capabilities for this.
Once you’ve got these Capabilities added to your plugin, you’ll want to lock your Roles and Capabilities to keep s2Member from overriding them in the next update. You can see this article on that:
Knowledge Base » Locking s2Member Roles/Capabilities