title: check if member is of a group
body: <p>I use buddypress with multiple groups. Every user can also join multiple groups as a member. I use custom profile fields for e.g. the address. Every member can select, who is able to view his profile. This try is based on the plugin 'User Profile Visibility Manager'. Now I need an additional option: View the profile to "Group Members Only"</p>
  
  <p>My plan is:</p>
  
  <ol>
  <li><p>Get the user_id of the 'visitor' - works perfect with:</p>
  
  <p>$user_id_visitor = bp_loggedin_user_id();</p></li>
  <li><p>Get the user_id of the 'profile owner' - works perfect with:</p>
  
  <p>$user_id_profile_owner = bp_displayed_user_id();</p></li>
  <li><p>Get the group(s) by the profile owner´s user_id: </p></li>
  </ol>
  
  <p>Here, I´ve tried a lot. With this function, I´m able to print all groups in which the 'profile owner' is a member. But I don´t need to print it, it is only for a test:</p>
  
  <pre><code>function bp_groups_profileowner( $user_id_profile_owner ) {
  global $wpdb;
  $groups = $wpdb-&gt;get_results( $wpdb-&gt;prepare( "SELECT group_id FROM wp_bp_groups_members WHERE user_id = %d", $user_id_profile_owner ) );
   if ( $groups ) {
    foreach ( $groups as $group ) {
    echo  '&lt;li&gt;' . $group-&gt;group_id . '&lt;/li&gt;';
    }
   }
  </code></pre>
  
  <ol>
  <li>check all members of the profile_owner´s group(s) and check, if the visitor is also member the group(s). </li>
  </ol>
  
  <p>My new option in the selectbox:</p>
  
  <pre><code>&lt;option value="groupmembers" &lt;?php echo selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?&gt;&gt;&lt;?php _e('Group Members Only','bp-profile-visibility');?&gt;&lt;/option&gt;    
  </code></pre>
  
  <p>This is the code snippet, coming from the plugin, which checks and protects user account visibility:</p>
  
  <pre><code> /**
   * Checks and protects user account visibility
   * @return type 
   */
  
  function check_profile_access(){
  
  
      if(!bp_is_user() ||  is_super_admin())
          return;
      //if we are on user profile page
      $privacy = bp_profile_visibility_get_settings(bp_displayed_user_id(), 'bp_profile_visibility');
  
      //if privacy is public, everyone can see
      if( 'public' == $privacy )
          return;
  
      $referrer=wp_get_referer();
      if($referrer)
          $referrer=bp_core_get_root_domain ();
      //in all other cases, user must be logged in
      if(!is_user_logged_in()){
          bp_core_add_message(__('Please login to view profile','bp-profile-visibility'),'error');
          wp_safe_redirect($referrer);
          exit(0);
  
          return ;
  
  
      }
      //if we are here, the person is logged in, let us see if the visibility is set to logged in
      if( 'loggedin' == $privacy )
          return ;
  
      //if this is my profile, do not prevent user
      if(bp_is_my_profile())
          return ;
  
      //now, since we have already tested for login , we just need to test for the friends only and me 
       if( 'friends' == $privacy &amp;&amp; function_exists('friends_check_friendship') &amp;&amp; friends_check_friendship(bp_displayed_user_id(), get_current_user_id()) )
                  return;  
  
  
      //now, we just need to test for the group members 
      if( 'groupmembers' ... )
  
  
  
      //if we are here, don't show the profile
  
  
          bp_core_add_message(__('This User\'s privacy settings does not allow you to view the profile.','bp-profile-visibility'),'error');
          wp_safe_redirect($referrer);
          exit(0);
  
          return ;
  
  }
  </code></pre>