The best thing to do in this case is take a look through the code:
https://github.com/buddypress/BuddyPress
i’m using the buddypress groups to add a user role to members in the same group .. i hook into the groups_member_after_saveto
add the role , which means when the user become a member he get the role .. and groups_member_before_remove
to remove the role ,when the user leave the group the role been removed. my code is working like charm now . what i need is , to add this role when the user become admin to the group , and remove the role when he be demoted to mod or member, or be banned or removed.. this is my current code , to add the role to joined members:
function bpmp_add_member($bp_group_admin)
{
$bp_group = _bpmp_get_group($bp_group_admin->group_id);
$user = new WP_User($bp_group_admin->user_id);
$user->add_role(_bpmp_get_role($bp_group));
}
function bpmp_remove_member($bp_group_admin)
{
$bp_group = _bpmp_get_group($bp_group_admin->group_id);
$user = new WP_User($bp_group_admin->user_id);
$user->remove_role(_bpmp_get_role($bp_group));
}
add_action('groups_member_after_save', 'bpmp_add_member', 90, 1);
add_action('groups_member_before_remove', 'bpmp_remove_member', 10, 1);
i just need to know what’s the right hooks to use .. i found these hooks but don’t know how to use its functions parameters with the code above
// define the groups_promote_member callback
function action_groups_promote_member( $group_id, $user_id, $status ) {
// make action magic happen here...
};
// add the action
add_action( 'groups_promote_member', 'action_groups_promote_member', 10, 3 );
// define the groups_demote_member callback
function action_groups_demote_member( $group_id, $user_id ) {
// make action magic happen here...
};
// add the action
add_action( 'groups_demote_member', 'action_groups_demote_member', 10, 2 );
any help will be highly appreciated