Skip to:
Content
Pages
Categories
Search
Top
Bottom

Checking for user role before group join


  • rdkelley8
    Participant

    @rdkelley8

    I’m rather new to writing plugins for WordPress, and am trying to fully understand actions, filters and hooks. So forgive me if just need to understand the basics better.

    When a user clicks the “Join Group” button, I would like to check if they have a particular user role assigned before they are added to a group. Is there a particular hook that will accomplish this?

    I know that “groups_action_join_group” evaluates a join request, and then “groups_join_group” is fired to add the user to the group– I’m just not sure how these two functions work in conjunction with each other. And how would I go about hooking my custom function to this process? If I use “groups_join_group,” it seems that doesn’t fire until after the user has joined.

    Thanks,

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

  • shanebp
    Moderator

    @shanebp

    Try using this hook:
    do_action_ref_array( 'groups_member_before_save', array( &$this ) );

    Found in: buddypress\bp-groups\classes\class-bp-groups-member.php


    rdkelley8
    Participant

    @rdkelley8

    Thank you– that does seem to be what I’m looking for. Passing in a parameter allows access to the group information. Now I’m trying to figure out how to stop the joining process if a certain condition is met.


    shanebp
    Moderator

    @shanebp

    The answer is right below the definition of the hook:

          // The following properties are required; bail if not met. 
          if ( empty( $this->user_id ) || empty( $this->group_id ) ) { 
              return false; 
          } 

    Just delete the value for one of those fields.

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