Skip to:
Content
Pages
Categories
Search
Top
Bottom

Solved – Default role for new BP group member


  • Andreas
    Participant

    @schenefeld

    Hi everybody,

    I want to give each new group member the default BP role “Administrator”. Usually when someone joins a new group after his membership request was confirmed, his default BuddyPress role (I don’t mean the WP role) is “Member”. So do you have an idea how to set this?

    Thank you already for your ideas 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

  • shanebp
    Moderator

    @shanebp

    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 );

    Andreas
    Participant

    @schenefeld

    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


    shanebp
    Moderator

    @shanebp

    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.


    Andreas
    Participant

    @schenefeld

    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?


    shanebp
    Moderator

    @shanebp

    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 );

    Andreas
    Participant

    @schenefeld

    Hey, this works now!

    Perfect, thank you very much

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar