Use this hook which is available right after they join.
do_action( 'groups_join_group', $group_id, $user_id );
Try this in your theme/functions.php or in bp-custom.php:
function schene_promote_group_member( $group_id, $user_id ) {
$group_member = new BP_Groups_Member( $user_id, $group_id );
$group_member->promote( 'admin' );
}
add_action( 'groups_join_group', 'schene_promote_group_member', 10, 2 );
Hi shanebp,
thank you for your info. But unfortunately it has not worked, that a registered WP users automatically became a BP group admin after his group membership request was confirmed from BP group admin. In the attached doc I explained how I did it. It would be great if you can find out the issue
https://docs.google.com/document/d/1E2EETy-rUYxFB00H5SuWU83Bq19jEcsr6XBbWJbr6qk/edit?usp=sharing
1. you aren’t supposed to do anything with the do_action. I was just showing you that hook exists.
2 & 3 – did you put the function in BOTH functions.php and bp-custom.php ?
If so, I said OR not AND. In both places it will cause a fatal error and show an entry in the log.
Learn how to debug in WP: https://codex.wordpress.org/WP_DEBUG
If not, then I don’t know what the issue is. It works properly on my test install.
Good morning shanebp,
yes, of course I did it exactly the way you described. In the end I also found the reason why it did not work: It does work for public groups, but not for private groups. Is this also the same on your side? And if yes, do you know if there is something to get the same result for private groups?
You are correct. For a private group try this which uses a different hook:
function schene_promote_group_member( $user_id, $group_id ) {
$group_member = new BP_Groups_Member( $user_id, $group_id );
$group_member->promote( 'admin' );
}
add_action( 'groups_membership_accepted', 'schene_promote_group_member', 99, 2 );
Hey, this works now!
Perfect, thank you very much