/**
 * Check to see whether a user has already been invited to a group.
 *
 * By default, the function checks for invitations that have been sent.
 * Entering 'all' as the $type parameter will return unsent invitations as
 * well (useful to make sure AJAX requests are not duplicated).
 *
 * @param int    $user_id  ID of potential group member.
 * @param int    $group_id ID of potential group.
 * @param string $type     Optional. Use 'sent' to check for sent invites,
 *                         'all' to check for all. Default: 'sent'.
 *
 * @return bool True if an invitation is found, otherwise false.
 */
function groups_check_user_has_invite($user_id, $group_id, $type = 'sent')
{
    return BP_Groups_Member::check_has_invite($user_id, $group_id, $type);
}
 function get_invitable_friend_count($user_id, $group_id)
 {
     // Setup some data we'll use below
     $is_group_admin = BP_Groups_Member::check_is_admin($user_id, $group_id);
     $friend_ids = BP_Friends_Friendship::get_friend_user_ids($user_id);
     $invitable_count = 0;
     for ($i = 0, $count = count($friend_ids); $i < $count; ++$i) {
         // If already a member, they cannot be invited again
         if (BP_Groups_Member::check_is_member((int) $friend_ids[$i], $group_id)) {
             continue;
         }
         // If user already has invite, they cannot be added
         if (BP_Groups_Member::check_has_invite((int) $friend_ids[$i], $group_id)) {
             continue;
         }
         // If user is not group admin and friend is banned, they cannot be invited
         if (false === $is_group_admin && BP_Groups_Member::check_is_banned((int) $friend_ids[$i], $group_id)) {
             continue;
         }
         $invitable_count++;
     }
     return $invitable_count;
 }
Example #3
0
function groups_check_user_has_invite( $user_id, $group_id ) {
	return BP_Groups_Member::check_has_invite( $user_id, $group_id );
}
 /**
  * Set up data about the current group.
  */
 public function populate()
 {
     global $wpdb;
     // Get BuddyPress.
     $bp = buddypress();
     // Check cache for group data.
     $group = wp_cache_get($this->id, 'bp_groups');
     // Cache missed, so query the DB.
     if (false === $group) {
         $group = $wpdb->get_row($wpdb->prepare("SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id));
         wp_cache_set($this->id, $group, 'bp_groups');
     }
     // No group found so set the ID and bail.
     if (empty($group) || is_wp_error($group)) {
         $this->id = 0;
         return;
     }
     // Group found so setup the object variables.
     $this->id = $group->id;
     $this->creator_id = $group->creator_id;
     $this->name = stripslashes($group->name);
     $this->slug = $group->slug;
     $this->description = stripslashes($group->description);
     $this->status = $group->status;
     $this->enable_forum = $group->enable_forum;
     $this->date_created = $group->date_created;
     // Are we getting extra group data?
     if (!empty($this->args['populate_extras'])) {
         /**
          * Filters the SQL prepared statement used to fetch group admins and mods.
          *
          * @since 1.5.0
          *
          * @param string $value SQL select statement used to fetch admins and mods.
          */
         $admin_mods = $wpdb->get_results(apply_filters('bp_group_admin_mods_user_join_filter', $wpdb->prepare("SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id)));
         // Add admins and moderators to their respective arrays.
         foreach ((array) $admin_mods as $user) {
             if (!empty($user->is_admin)) {
                 $this->admins[] = $user;
             } else {
                 $this->mods[] = $user;
             }
         }
         // Set up some specific group vars from meta. Excluded
         // from the bp_groups cache because it's cached independently.
         $this->last_activity = groups_get_groupmeta($this->id, 'last_activity');
         $this->total_member_count = groups_get_groupmeta($this->id, 'total_member_count');
         // Set user-specific data.
         $user_id = bp_loggedin_user_id();
         $this->is_member = BP_Groups_Member::check_is_member($user_id, $this->id);
         $this->is_invited = BP_Groups_Member::check_has_invite($user_id, $this->id);
         $this->is_pending = BP_Groups_Member::check_for_membership_request($user_id, $this->id);
         // If this is a private or hidden group, does the current user have access?
         if ('private' === $this->status || 'hidden' === $this->status) {
             // Assume user does not have access to hidden/private groups.
             $this->user_has_access = false;
             // Group members or community moderators have access.
             if ($this->is_member && is_user_logged_in() || bp_current_user_can('bp_moderate')) {
                 $this->user_has_access = true;
             }
         } else {
             $this->user_has_access = true;
         }
     }
 }
Example #5
0
	function get_invitable_friend_count( $user_id, $group_id ) {
		global $wpdb, $bp;

		$friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );

		$invitable_count = 0;
		for ( $i = 0; $i < count($friend_ids); $i++ ) {

			if ( BP_Groups_Member::check_is_member( (int)$friend_ids[$i], $group_id ) )
				continue;

			if ( BP_Groups_Member::check_has_invite( (int)$friend_ids[$i], $group_id )  )
				continue;

			$invitable_count++;
		}

		return $invitable_count;
	}