Automate adding a secondary role on top of s2member level role after user registers

Hi,

Currently i’m using a user role editor plugin to manually add a ‘vendor role’ once a member has registered and gained an s2member level 1 role. However I find this method tedious and prone to error. Is their a way to programatically add a trigger to add this role?

I forgot to mention i’m using BuddyPress with this so I missed the fact adding a role will need to be on the activation level.

Update: I managed to add a role by hooking into BuddyPress’s bp_core_activated_user action hook:

function my_bp_core_activated_user( $user_id, $key, $user ) { $user = get_user_by('id', $user_id); $user->add_role('vendor'); }; add_action( 'bp_core_activated_user', 'my_bp_core_activated_user', 10, 3 );

Does this method interfere with S2member’s process at all? In which I mean does S2member leave account activation to BuddyPress, leaving this hook to run flawlessly.

I would use the ws_plugin__s2member_during_configure_user_registration hook instead. There is a BuddyPress example here (not exactly what you’re looking for), but it might help to see that example. http://s2member.com/kb-article/how-can-i-automatically-add-a-user-to-a-buddypress-group/

1 Like