Index: trunk/bp-groups/bp-groups-classes.php
===================================================================
--- trunk/bp-groups/bp-groups-classes.php	(revision 5697)
+++ trunk/bp-groups/bp-groups-classes.php	(revision 5713)
@@ -17,10 +17,6 @@
 	var $total_member_count;
 
-	function bp_groups_group( $id = null ) {
-		$this->__construct($id);
-	}
-
-	function __construct( $id = null ) {
-		if ( $id ) {
+	public function __construct( $id = null ) {
+		if ( !empty( $id ) ) {
 			$this->id = $id;
 			$this->populate();
@@ -28,5 +24,5 @@
 	}
 
-	function populate() {
+	private function populate() {
 		global $wpdb, $bp;
 
@@ -67,5 +63,5 @@
 	}
 
-	function save() {
+	public function save() {
 		global $wpdb, $bp;
 
@@ -138,5 +134,5 @@
 	}
 
-	function delete() {
+	public function delete() {
 		global $wpdb, $bp;
 
@@ -165,13 +161,13 @@
 	}
 
-	/* Static Functions */
-
-	function group_exists( $slug, $table_name = false ) {
-		global $wpdb, $bp;
-
-		if ( !$table_name )
+	/** Static Methods ********************************************************/
+
+	public static function group_exists( $slug, $table_name = false ) {
+		global $wpdb, $bp;
+
+		if ( empty( $table_name ) )
 			$table_name = $bp->groups->table_name;
 
-		if ( !$slug )
+		if ( empty( $slug ) )
 			return false;
 
@@ -179,5 +175,5 @@
 	}
 
-	function get_id_from_slug( $slug ) {
+	public static function get_id_from_slug( $slug ) {
 		return BP_Groups_Group::group_exists( $slug );
 	}
@@ -188,5 +184,5 @@
 	}
 
-	function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
+	public static function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
 		global $wpdb, $bp;
 
@@ -196,5 +192,5 @@
 		$filter = like_escape( $wpdb->escape( $filter ) );
 
-		if ( $limit && $page )
+		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
@@ -202,5 +198,5 @@
 		$gids = BP_Groups_Member::get_group_ids( $user_id );
 
-		if ( !$gids['groups'] )
+		if ( empty( $gids['groups'] ) )
 			return false;
 
@@ -213,15 +209,15 @@
 	}
 
-	function search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) {
+	public static function search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) {
 		global $wpdb, $bp;
 
 		$filter = like_escape( $wpdb->escape( $filter ) );
 
-		if ( $limit && $page )
+		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
-		if ( $sort_by && $order ) {
-			$sort_by = $wpdb->escape( $sort_by );
-			$order = $wpdb->escape( $order );
+		if ( !empty( $sort_by ) && !empty( $order ) ) {
+			$sort_by   = $wpdb->escape( $sort_by );
+			$order     = $wpdb->escape( $order );
 			$order_sql = "ORDER BY $sort_by $order";
 		}
@@ -236,5 +232,5 @@
 	}
 
-	function check_slug( $slug ) {
+	public static function check_slug( $slug ) {
 		global $wpdb, $bp;
 
@@ -242,5 +238,5 @@
 	}
 
-	function get_slug( $group_id ) {
+	public static function get_slug( $group_id ) {
 		global $wpdb, $bp;
 
@@ -248,10 +244,10 @@
 	}
 
-	function has_members( $group_id ) {
+	public static function has_members( $group_id ) {
 		global $wpdb, $bp;
 
 		$members = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
 
-		if ( !$members )
+		if ( empty( $members ) )
 			return false;
 
@@ -259,5 +255,5 @@
 	}
 
-	function has_membership_requests( $group_id ) {
+	public static function has_membership_requests( $group_id ) {
 		global $wpdb, $bp;
 
@@ -265,8 +261,8 @@
 	}
 
-	function get_membership_requests( $group_id, $limit = null, $page = null ) {
-		global $wpdb, $bp;
-
-		if ( $limit && $page ) {
+	public static function get_membership_requests( $group_id, $limit = null, $page = null ) {
+		global $wpdb, $bp;
+
+		if ( !empty( $limit ) && !empty( $page ) ) {
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 		}
@@ -278,8 +274,9 @@
 	}
 
-	function get( $type = 'newest', $per_page = null, $page = null, $user_id = 0, $search_terms = false, $include = false, $populate_extras = true, $exclude = false, $show_hidden = false ) {
-		global $wpdb, $bp;
-
-		$sql = array();
+	public static function get( $type = 'newest', $per_page = null, $page = null, $user_id = 0, $search_terms = false, $include = false, $populate_extras = true, $exclude = false, $show_hidden = false ) {
+		global $wpdb, $bp;
+
+		$sql       = array();
+		$total_sql = array();
 
 		$sql['select'] = "SELECT g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity";
@@ -341,5 +338,5 @@
 		}
 
-		if ( $per_page && $page )
+		if ( !empty( $per_page ) && !empty( $page ) )
 			$sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page), intval( $per_page ) );
 
@@ -379,5 +376,5 @@
 			$t_sql .= " WHERE " . join( ' AND ', (array)$total_sql['where'] );
 
-		/* Get total group results */
+		// Get total group results
 		$total_groups_sql = apply_filters( 'bp_groups_get_total_groups_sql', join( ' ', (array)$t_sql ), $t_sql );
 		$total_groups     = $wpdb->get_var( $total_groups_sql );
@@ -388,5 +385,5 @@
 		}
 		
-		/* Populate some extra information instead of querying each time in the loop */
+		// Populate some extra information instead of querying each time in the loop
 		if ( !empty( $populate_extras ) ) {
 			$group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
@@ -402,11 +399,11 @@
 	}
 
-	function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
+	public static function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
 		global $wpdb, $bp, $bbdb;
 
-		if ( !$bbdb )
+		if ( empty( $bbdb ) )
 			do_action( 'bbpress_init' );
 
-		if ( $limit && $page ) {
+		if ( !empty( $limit ) && !empty( $page ) ) {
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 		}
@@ -425,5 +422,5 @@
 		}
 
-		if ( $user_id ) {
+		if ( !empty( $user_id ) ) {
 			$user_id = $wpdb->escape( $user_id );
 			$paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
@@ -443,11 +440,11 @@
 	}
 
-	function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) {
+	public static function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) {
 		global $wpdb, $bp, $bbdb;
 
-		if ( !$bbdb )
+		if ( empty( $bbdb ) )
 			do_action( 'bbpress_init' );
 
-		if ( $limit && $page ) {
+		if ( !empty( $limit ) && !empty( $page ) ) {
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 		}
@@ -456,5 +453,5 @@
 			$hidden_sql = " AND g.status != 'hidden'";
 
-		if ( $search_terms ) {
+		if ( !empty( $search_terms ) ) {
 			$search_terms = like_escape( $wpdb->escape( $search_terms ) );
 			$search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
@@ -466,5 +463,5 @@
 		}
 
-		if ( $user_id ) {
+		if ( !empty( $user_id ) ) {
 			$user_id = $wpdb->escape( $user_id );
 			$paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
@@ -484,5 +481,5 @@
 	}
 
-	function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true, $exclude = false ) {
+	public static function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true, $exclude = false ) {
 		global $wpdb, $bp;
 
@@ -508,5 +505,5 @@
 		$letter = like_escape( $wpdb->escape( $letter ) );
 
-		if ( $limit && $page ) {
+		if ( !empty( $limit ) && !empty( $page ) ) {
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 			$total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND g.name LIKE '$letter%%' {$hidden_sql} {$search_sql} {$exclude_sql}" ) );
@@ -524,8 +521,8 @@
 	}
 
-	function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
-		global $wpdb, $bp;
-
-		if ( $limit && $page )
+	public static function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
+		global $wpdb, $bp;
+
+		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
@@ -533,5 +530,5 @@
 			$hidden_sql = "AND g.status != 'hidden'";
 
-		if ( $search_terms ) {
+		if ( !empty( $search_terms ) ) {
 			$search_terms = like_escape( $wpdb->escape( $search_terms ) );
 			$search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
@@ -543,5 +540,5 @@
 		}
 
-		if ( $user_id ) {
+		if ( !empty( $user_id ) ) {
 			$user_id = $wpdb->escape( $user_id );
 			$paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY rand() {$pag_sql}" );
@@ -561,5 +558,5 @@
 	}
 
-	function get_group_extras( &$paged_groups, &$group_ids, $type = false ) {
+	public static function get_group_extras( &$paged_groups, &$group_ids, $type = false ) {
 		global $bp, $wpdb;
 
@@ -567,5 +564,5 @@
 			return $paged_groups;
 
-		/* Fetch the logged in users status within each group */
+		// Fetch the logged in users status within each group
 		$user_status = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_confirmed = 1 AND is_banned = 0", bp_loggedin_user_id() ) );
 		for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
@@ -573,6 +570,7 @@
 
 			foreach ( (array)$user_status as $group_id ) {
-				if ( $group_id == $paged_groups[$i]->id )
+				if ( $group_id == $paged_groups[$i]->id ) {
 					$paged_groups[$i]->is_member = true;
+				}
 			}
 		}
@@ -583,6 +581,7 @@
 
 			foreach ( (array)$user_banned as $group_id ) {
-				if ( $group_id == $paged_groups[$i]->id )
+				if ( $group_id == $paged_groups[$i]->id ) {
 					$paged_groups[$i]->is_banned = true;
+				}
 			}
 		}
@@ -591,5 +590,5 @@
 	}
 
-	function delete_all_invites( $group_id ) {
+	public static function delete_all_invites( $group_id ) {
 		global $wpdb, $bp;
 
@@ -597,5 +596,5 @@
 	}
 
-	function get_total_group_count() {
+	public static function get_total_group_count() {
 		global $wpdb, $bp;
 
@@ -607,5 +606,5 @@
 	}
 
-	function get_global_forum_topic_count( $type ) {
+	public static function get_global_forum_topic_count( $type ) {
 		global $bbdb, $wpdb, $bp;
 
@@ -618,10 +617,9 @@
 	}
 
-	function get_total_member_count( $group_id ) {
+	public static function get_total_member_count( $group_id ) {
 		global $wpdb, $bp;
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
 	}
-
 
 	/**
@@ -634,5 +632,5 @@
 	 * @return int The topic count
 	 */
-	function get_global_topic_count( $status = 'public', $search_terms = false ) {
+	public static function get_global_topic_count( $status = 'public', $search_terms = false ) {
 		global $bbdb, $wpdb, $bp;
 
@@ -686,29 +684,29 @@
 	var $comments;
 	var $invite_sent;
-
 	var $user;
 
-	function bp_groups_member( $user_id = 0, $group_id = 0, $id = false, $populate = true ) {
-		$this->__construct($user_id,$group_id,$id,$populate);
-	}
-
-	function __construct( $user_id = 0, $group_id = 0, $id = false, $populate = true ) {
-		if ( $user_id && $group_id && !$id ) {
-			$this->user_id = $user_id;
+	public function __construct( $user_id = 0, $group_id = 0, $id = false, $populate = true ) {
+		
+		// User and group are not empty, and ID is
+		if ( !empty( $user_id ) && !empty( $group_id ) && empty( $id ) ) {
+			$this->user_id  = $user_id;
 			$this->group_id = $group_id;
 
-			if ( $populate )
+			if ( !empty( $populate ) ) {
 				$this->populate();
-		}
-
-		if ( $id ) {
+			}
+		}
+
+		// ID is not empty
+		if ( !empty( $id ) ) {
 			$this->id = $id;
 
-			if ( $populate )
+			if ( !empty( $populate ) ) {
 				$this->populate();
-		}
-	}
-
-	function populate() {
+			}
+		}
+	}
+
+	private function populate() {
 		global $wpdb, $bp;
 
@@ -716,10 +714,10 @@
 			$sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
 
-		if ( $this->id )
+		if ( !empty( $this->id ) )
 			$sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE id = %d", $this->id );
 
 		$member = $wpdb->get_row($sql);
 
-		if ( $member ) {
+		if ( !empty( $member ) ) {
 			$this->id            = $member->id;
 			$this->group_id      = $member->group_id;
@@ -739,5 +737,5 @@
 	}
 
-	function save() {
+	public function save() {
 		global $wpdb, $bp;
 
@@ -756,10 +754,10 @@
 		do_action_ref_array( 'groups_member_before_save', array( &$this ) );
 
-		if ( $this->id )
+		if ( !empty( $this->id ) )
 			$sql = $wpdb->prepare( "UPDATE {$bp->groups->table_name_members} SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = %s, is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id );
 		else
 			$sql = $wpdb->prepare( "INSERT INTO {$bp->groups->table_name_members} ( user_id, group_id, inviter_id, is_admin, is_mod, is_banned, user_title, date_modified, is_confirmed, comments, invite_sent ) VALUES ( %d, %d, %d, %d, %d, %d, %s, %s, %d, %s, %d )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent );
 
-		if ( !$wpdb->query($sql) )
+		if ( !$wpdb->query( $sql ) )
 			return false;
 
@@ -771,14 +769,14 @@
 	}
 
-	function promote( $status = 'mod' ) {
+	public function promote( $status = 'mod' ) {
 		if ( 'mod' == $status ) {
-			$this->is_admin = 0;
-			$this->is_mod = 1;
+			$this->is_admin   = 0;
+			$this->is_mod     = 1;
 			$this->user_title = __( 'Group Mod', 'buddypress' );
 		}
 
 		if ( 'admin' == $status ) {
-			$this->is_admin = 1;
-			$this->is_mod = 0;
+			$this->is_admin   = 1;
+			$this->is_mod     = 0;
 			$this->user_title = __( 'Group Admin', 'buddypress' );
 		}
@@ -787,7 +785,7 @@
 	}
 
-	function demote() {
-		$this->is_mod = 0;
-		$this->is_admin = 0;
+	public function demote() {
+		$this->is_mod     = 0;
+		$this->is_admin   = 0;
 		$this->user_title = false;
 
@@ -795,7 +793,7 @@
 	}
 
-	function ban() {
-
-		if ( $this->is_admin )
+	public function ban() {
+
+		if ( !empty( $this->is_admin ) )
 			return false;
 
@@ -812,7 +810,7 @@
 	}
 
-	function unban() {
-
-		if ( $this->is_admin )
+	public function unban() {
+
+		if ( !empty( $this->is_admin ) )
 			return false;
 
@@ -825,5 +823,5 @@
 	}
 
-	function accept_invite() {
+	public function accept_invite() {
 
 		$this->inviter_id    = 0;
@@ -834,5 +832,5 @@
 	}
 
-	function accept_request() {
+	public function accept_request() {
 
 		$this->is_confirmed = 1;
@@ -842,5 +840,5 @@
 	}
 
-	function remove() {
+	public function remove() {
 		global $wpdb, $bp;
 
@@ -859,7 +857,7 @@
 	}
 
-	/* Static Functions */
-
-	function delete( $user_id, $group_id ) {
+	/** Static Methods ********************************************************/
+
+	public static function delete( $user_id, $group_id ) {
 		global $wpdb, $bp;
 
@@ -867,9 +865,9 @@
 	}
 
-	function get_group_ids( $user_id, $limit = false, $page = false ) {
+	public static function get_group_ids( $user_id, $limit = false, $page = false ) {
 		global $wpdb, $bp;
 
 		$pag_sql = '';
-		if ( $limit && $page )
+		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
@@ -888,13 +886,13 @@
 	}
 
-	function get_recently_joined( $user_id, $limit = false, $page = false, $filter = false ) {
+	public static function get_recently_joined( $user_id, $limit = false, $page = false, $filter = false ) {
 		global $wpdb, $bp;
 
 		$pag_sql = $hidden_sql = $filter_sql = '';
 
-		if ( $limit && $page )
+		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
-		if ( $filter ) {
+		if ( !empty( $filter ) ) {
 			$filter = like_escape( $wpdb->escape( $filter ) );
 			$filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
@@ -910,13 +908,13 @@
 	}
 
-	function get_is_admin_of( $user_id, $limit = false, $page = false, $filter = false ) {
+	public static function get_is_admin_of( $user_id, $limit = false, $page = false, $filter = false ) {
 		global $wpdb, $bp;
 
 		$pag_sql = $hidden_sql = $filter_sql = '';
 
-		if ( $limit && $page )
+		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
-		if ( $filter ) {
+		if ( !empty( $filter ) ) {
 			$filter = like_escape( $wpdb->escape( $filter ) );
 			$filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
@@ -932,13 +930,13 @@
 	}
 
-	function get_is_mod_of( $user_id, $limit = false, $page = false, $filter = false ) {
+	public static function get_is_mod_of( $user_id, $limit = false, $page = false, $filter = false ) {
 		global $wpdb, $bp;
 
 		$pag_sql = $hidden_sql = $filter_sql = '';
 
-		if ( $limit && $page )
+		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
-		if ( $filter ) {
+		if ( !empty( $filter ) ) {
 			$filter = like_escape( $wpdb->escape( $filter ) );
 			$filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
@@ -954,5 +952,5 @@
 	}
 
-	function total_group_count( $user_id = 0 ) {
+	public static function total_group_count( $user_id = 0 ) {
 		global $bp, $wpdb;
 
@@ -967,5 +965,5 @@
 	}
 
-	function get_invites( $user_id, $limit = false, $page = false, $exclude = false ) {
+	public static function get_invites( $user_id, $limit = false, $page = false, $exclude = false ) {
 		global $wpdb, $bp;
 
@@ -980,5 +978,5 @@
 	}
 
-	function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
+	public static function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
 		global $wpdb, $bp;
 
@@ -994,5 +992,5 @@
 	}
 
-	function delete_invite( $user_id, $group_id ) {
+	public static function delete_invite( $user_id, $group_id ) {
 		global $wpdb, $bp;
 
@@ -1003,5 +1001,5 @@
 	}
 
-	function delete_request( $user_id, $group_id ) {
+	public static function delete_request( $user_id, $group_id ) {
 		global $wpdb, $bp;
 
@@ -1012,5 +1010,5 @@
 	}
 
-	function check_is_admin( $user_id, $group_id ) {
+	public static function check_is_admin( $user_id, $group_id ) {
 		global $wpdb, $bp;
 
@@ -1021,5 +1019,5 @@
 	}
 
-	function check_is_mod( $user_id, $group_id ) {
+	public static function check_is_mod( $user_id, $group_id ) {
 		global $wpdb, $bp;
 
@@ -1030,5 +1028,5 @@
 	}
 
-	function check_is_member( $user_id, $group_id ) {
+	public static function check_is_member( $user_id, $group_id ) {
 		global $wpdb, $bp;
 
@@ -1039,5 +1037,5 @@
 	}
 
-	function check_is_banned( $user_id, $group_id ) {
+	public static function check_is_banned( $user_id, $group_id ) {
 		global $wpdb, $bp;
 
@@ -1057,5 +1055,5 @@
 	 * @since 1.2.6
 	 */
-	function check_is_creator( $user_id, $group_id ) {
+	public static function check_is_creator( $user_id, $group_id ) {
 		global $bp, $wpdb;
 
@@ -1066,5 +1064,5 @@
 	}
 
-	function check_for_membership_request( $user_id, $group_id ) {
+	public static function check_for_membership_request( $user_id, $group_id ) {
 		global $wpdb, $bp;
 
@@ -1075,5 +1073,5 @@
 	}
 
-	function get_random_groups( $user_id, $total_groups = 5 ) {
+	public static function get_random_groups( $user_id, $total_groups = 5 ) {
 		global $wpdb, $bp;
 
@@ -1086,5 +1084,5 @@
 	}
 
-	function get_group_member_ids( $group_id ) {
+	public static function get_group_member_ids( $group_id ) {
 		global $bp, $wpdb;
 
@@ -1092,5 +1090,5 @@
 	}
 
-	function get_group_administrator_ids( $group_id ) {
+	public static function get_group_administrator_ids( $group_id ) {
 		global $bp, $wpdb;
 
@@ -1098,5 +1096,5 @@
 	}
 
-	function get_group_moderator_ids( $group_id ) {
+	public static function get_group_moderator_ids( $group_id ) {
 		global $bp, $wpdb;
 
@@ -1104,5 +1102,5 @@
 	}
 
-	function get_all_membership_request_user_ids( $group_id ) {
+	public static function get_all_membership_request_user_ids( $group_id ) {
 		global $bp, $wpdb;
 
@@ -1110,21 +1108,21 @@
 	}
 
-	function get_all_for_group( $group_id, $limit = false, $page = false, $exclude_admins_mods = true, $exclude_banned = true, $exclude = false ) {
+	public static function get_all_for_group( $group_id, $limit = false, $page = false, $exclude_admins_mods = true, $exclude_banned = true, $exclude = false ) {
 		global $bp, $wpdb;
 
 		$pag_sql = '';
-		if ( $limit && $page )
+		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
 		$exclude_admins_sql = '';
-		if ( $exclude_admins_mods )
+		if ( !empty( $exclude_admins_mods ) )
 			$exclude_admins_sql = $wpdb->prepare( "AND is_admin = 0 AND is_mod = 0" );
 
 		$banned_sql = '';
-		if ( $exclude_banned )
+		if ( !empty( $exclude_banned ) )
 			$banned_sql = $wpdb->prepare( " AND is_banned = 0" );
 
 		$exclude_sql = '';
-		if ( $exclude )
+		if ( !empty( $exclude ) )
 			$exclude_sql = $wpdb->prepare( " AND m.user_id NOT IN ({$exclude})" );
 
@@ -1134,5 +1132,5 @@
 			$members = $wpdb->get_results( apply_filters( 'bp_group_members_user_join_filter', $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u WHERE u.ID = m.user_id AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ) );
 
-		if ( !$members )
+		if ( empty( $members ) )
 			return false;
 
@@ -1142,7 +1140,9 @@
 			$total_member_count = $wpdb->get_var( apply_filters( 'bp_group_members_count_user_join_filter', $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql}", $group_id ) ) );
 
-		/* Fetch whether or not the user is a friend */
-		foreach ( (array)$members as $user ) $user_ids[] = $user->user_id;
-		$user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
+		// Fetch whether or not the user is a friend
+		foreach ( (array)$members as $user )
+			$user_ids[] = $user->user_id;
+
+		$user_ids = $wpdb->escape( join( ',', (array) $user_ids ) );
 
 		if ( bp_is_active( 'friends' ) ) {
@@ -1150,6 +1150,7 @@
 			for ( $i = 0, $count = count( $members ); $i < $count; ++$i ) {
 				foreach ( (array)$friend_status as $status ) {
-					if ( $status->initiator_user_id == $members[$i]->user_id || $status->friend_user_id == $members[$i]->user_id )
+					if ( $status->initiator_user_id == $members[$i]->user_id || $status->friend_user_id == $members[$i]->user_id ) {
 						$members[$i]->is_friend = $status->is_confirmed;
+					}
 				}
 			}
@@ -1159,5 +1160,5 @@
 	}
 
-	function delete_all( $group_id ) {
+	public static function delete_all( $group_id ) {
 		global $wpdb, $bp;
 
@@ -1174,5 +1175,5 @@
 	 * @uses BP_Groups_Member
 	 */
-	function delete_all_for_user( $user_id ) {
+	public static function delete_all_for_user( $user_id ) {
 		global $bp, $wpdb;
 
@@ -1209,13 +1210,13 @@
 	var $slug = false;
 	
-	/* The name/slug of the Group Admin tab for this extension */
+	// The name/slug of the Group Admin tab for this extension
 	var $admin_name = '';
 	var $admin_slug = '';
 
-	/* The name/slug of the Group Creation tab for this extension */
+	// The name/slug of the Group Creation tab for this extension
 	var $create_name = '';
 	var $create_slug = '';
 
-	/* Will this extension be visible to non-members of a group? Options: public/private */
+	// Will this extension be visible to non-members of a group? Options: public/private
 	var $visibility = 'public';
 
