Index: /branches/1.8/bp-activity/bp-activity-classes.php
===================================================================
--- /branches/1.8/bp-activity/bp-activity-classes.php	(revision 7336)
+++ /branches/1.8/bp-activity/bp-activity-classes.php	(revision 7337)
@@ -173,5 +173,5 @@
 		// Searching
 		if ( $search_terms ) {
-			$search_terms = $wpdb->escape( $search_terms );
+			$search_terms = esc_sql( $search_terms );
 			$where_conditions['search_sql'] = "a.content LIKE '%%" . esc_sql( like_escape( $search_terms ) ) . "%%'";
 		}
Index: /branches/1.8/bp-activity/bp-activity-functions.php
===================================================================
--- /branches/1.8/bp-activity/bp-activity-functions.php	(revision 7336)
+++ /branches/1.8/bp-activity/bp-activity-functions.php	(revision 7337)
@@ -686,5 +686,5 @@
 	// Sanitize value
 	if ( is_string( $meta_value ) )
-		$meta_value = stripslashes( $wpdb->escape( $meta_value ) );
+		$meta_value = stripslashes( esc_sql( $meta_value ) );
 
 	// Maybe, just maybe... serialize
Index: /branches/1.8/bp-blogs/bp-blogs-functions.php
===================================================================
--- /branches/1.8/bp-blogs/bp-blogs-functions.php	(revision 7336)
+++ /branches/1.8/bp-blogs/bp-blogs-functions.php	(revision 7337)
@@ -709,5 +709,5 @@
 
 	if ( is_string($meta_value) )
-		$meta_value = stripslashes($wpdb->escape($meta_value));
+		$meta_value = stripslashes( esc_sql( $meta_value ) );
 
 	$meta_value = maybe_serialize($meta_value);
Index: /branches/1.8/bp-core/bp-core-classes.php
===================================================================
--- /branches/1.8/bp-core/bp-core-classes.php	(revision 7336)
+++ /branches/1.8/bp-core/bp-core-classes.php	(revision 7337)
@@ -325,6 +325,5 @@
 		// 'exclude' - User ids to exclude from the results
 		if ( false !== $exclude ) {
-			$exclude        = wp_parse_id_list( $exclude );
-			$exclude_ids    = $wpdb->escape( implode( ',', (array) $exclude ) );
+			$exclude_ids    = implode( ',', wp_parse_id_list( $exclude ) );
 			$sql['where'][] = "u.{$this->uid_name} NOT IN ({$exclude_ids})";
 		}
Index: /branches/1.8/bp-forums/bp-forums-functions.php
===================================================================
--- /branches/1.8/bp-forums/bp-forums-functions.php	(revision 7336)
+++ /branches/1.8/bp-forums/bp-forums-functions.php	(revision 7337)
@@ -457,5 +457,5 @@
 	// Get the topic ids
 	foreach ( (array) $topics as $topic ) $topic_ids[] = $topic->topic_id;
-	$topic_ids = $wpdb->escape( join( ',', (array) $topic_ids ) );
+	$topic_ids = implode( ',', wp_parse_id_list( $topic_ids ) );
 
 	// Fetch the topic's last poster details
@@ -591,5 +591,5 @@
 	// Get the user ids
 	foreach ( (array) $posts as $post ) $user_ids[] = $post->poster_id;
-	$user_ids = $wpdb->escape( join( ',', (array) $user_ids ) );
+	$user_ids = implode( ',', wp_parse_id_list( $user_ids ) );
 
 	// Fetch the poster's user_email, user_nicename and user_login
Index: /branches/1.8/bp-groups/bp-groups-classes.php
===================================================================
--- /branches/1.8/bp-groups/bp-groups-classes.php	(revision 7336)
+++ /branches/1.8/bp-groups/bp-groups-classes.php	(revision 7337)
@@ -393,12 +393,10 @@
 
 		if ( ! empty( $r['include'] ) ) {
-			$include        = wp_parse_id_list( $r['include'] );
-			$include        = $wpdb->escape( implode( ',', $include ) );
+			$include        = implode( ',', wp_parse_id_list( $r['include'] ) );
 			$sql['include'] = " AND g.id IN ({$include})";
 		}
 
 		if ( ! empty( $r['exclude'] ) ) {
-			$exclude        = wp_parse_id_list( $r['exclude'] );
-			$exclude        = $wpdb->escape( implode( ',', $exclude ) );
+			$exclude        = implode( ',', wp_parse_id_list( $r['exclude'] ) );
 			$sql['exclude'] = " AND g.id NOT IN ({$exclude})";
 		}
@@ -507,5 +505,5 @@
 		// Populate some extra information instead of querying each time in the loop
 		if ( !empty( $r['populate_extras'] ) ) {
-			$group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
+			$group_ids = implode( ',', wp_parse_id_list( $group_ids ) );
 			$paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $r['type'] );
 		}
@@ -676,11 +674,10 @@
 
 		if ( !empty( $exclude ) ) {
-			$exclude     = wp_parse_id_list( $exclude );
-			$exclude     = $wpdb->escape( implode( ',', $exclude ) );
+			$exclude     = implode( ',', wp_parse_id_list( $exclude ) );
 			$exclude_sql = " AND g.id NOT IN ({$exclude})";
 		}
 
 		if ( !empty( $user_id ) ) {
-			$user_id      = absint( $wpdb->escape( $user_id ) );
+			$user_id      = absint( esc_sql( $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}" );
 			$total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE 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}" );
@@ -692,5 +689,5 @@
 		if ( !empty( $populate_extras ) ) {
 			foreach ( (array) $paged_groups as $group ) $group_ids[] = $group->id;
-			$group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
+			$group_ids = implode( ',', wp_parse_id_list( $group_ids ) );
 			$paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
 		}
@@ -718,11 +715,10 @@
 
 		if ( !empty( $exclude ) ) {
-			$exclude     = wp_parse_id_list( $exclude );
-			$exclude     = $wpdb->escape( implode( ',', $exclude ) );
+			$exclude     = implode( ',', wp_parse_id_list( $exclude ) );
 			$exclude_sql = " AND g.id NOT IN ({$exclude})";
 		}
 
 		if ( !empty( $user_id ) ) {
-			$user_id = $wpdb->escape( $user_id );
+			$user_id = esc_sql( $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}" );
 			$total_groups = $wpdb->get_results( "SELECT COUNT(DISTINCT g.id) 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.posts > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} " );
@@ -734,5 +730,5 @@
 		if ( !empty( $populate_extras ) ) {
 			foreach ( (array) $paged_groups as $group ) $group_ids[] = $group->id;
-			$group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
+			$group_ids = implode( ',', wp_parse_id_list( $group_ids ) );
 			$paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
 		}
@@ -756,6 +752,5 @@
 
 		if ( !empty( $exclude ) ) {
-			$exclude     = wp_parse_id_list( $exclude );
-			$exclude     = $wpdb->escape( implode( ',', $exclude ) );
+			$exclude     = implode( ',', wp_parse_id_list( $exclude ) );
 			$exclude_sql = " AND g.id NOT IN ({$exclude})";
 		}
@@ -777,5 +772,5 @@
 				$group_ids[] = $group->id;
 			}
-			$group_ids    = $wpdb->escape( join( ',', (array) $group_ids ) );
+			$group_ids    = implode( ',', wp_parse_id_list( $group_ids ) );
 			$paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
 		}
@@ -802,10 +797,10 @@
 		if ( !empty( $exclude ) ) {
 			$exclude     = wp_parse_id_list( $exclude );
-			$exclude     = $wpdb->escape( implode( ',', $exclude ) );
+			$exclude     = esc_sql( implode( ',', $exclude ) );
 			$exclude_sql = " AND g.id NOT IN ({$exclude})";
 		}
 
 		if ( !empty( $user_id ) ) {
-			$user_id = $wpdb->escape( $user_id );
+			$user_id = esc_sql( $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}" );
 			$total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}" );
@@ -817,5 +812,5 @@
 		if ( !empty( $populate_extras ) ) {
 			foreach ( (array) $paged_groups as $group ) $group_ids[] = $group->id;
-			$group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
+			$group_ids = implode( ',', wp_parse_id_list( $group_ids ) );
 			$paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
 		}
@@ -1512,6 +1507,5 @@
 
 		if ( !empty( $exclude ) ) {
-			$exclude     = wp_parse_id_list( $exclude );
-			$exclude     = $wpdb->escape( implode( ',', $exclude ) );
+			$exclude     = implode( ',', wp_parse_id_list( $exclude ) );
 			$exclude_sql = " AND g.id NOT IN ({$exclude})";
 		} else {
@@ -1674,6 +1668,5 @@
 		$exclude_sql = '';
 		if ( !empty( $exclude ) ) {
-			$exclude     = wp_parse_id_list( $exclude );
-			$exclude     = $wpdb->escape( implode( ',', $exclude ) );
+			$exclude     = implode( ',', wp_parse_id_list( $exclude ) );
 			$exclude_sql = " AND m.user_id NOT IN ({$exclude})";
 		}
Index: /branches/1.8/bp-groups/bp-groups-functions.php
===================================================================
--- /branches/1.8/bp-groups/bp-groups-functions.php	(revision 7336)
+++ /branches/1.8/bp-groups/bp-groups-functions.php	(revision 7337)
@@ -1046,5 +1046,5 @@
 
 	if ( is_string( $meta_value ) )
-		$meta_value = stripslashes( $wpdb->escape( $meta_value ) );
+		$meta_value = stripslashes( esc_sql( $meta_value ) );
 
 	$meta_value = maybe_serialize( $meta_value );
Index: /branches/1.8/bp-messages/bp-messages-classes.php
===================================================================
--- /branches/1.8/bp-messages/bp-messages-classes.php	(revision 7336)
+++ /branches/1.8/bp-messages/bp-messages-classes.php	(revision 7337)
@@ -150,5 +150,5 @@
 
 		if ( !empty( $search_terms ) ) {
-			$search_terms = like_escape( $wpdb->escape( $search_terms ) );
+			$search_terms = like_escape( esc_sql( $search_terms ) );
 			$search_sql   = "AND ( subject LIKE '%%$search_terms%%' OR message LIKE '%%$search_terms%%' )";
 		}
Index: /branches/1.8/bp-xprofile/bp-xprofile-functions.php
===================================================================
--- /branches/1.8/bp-xprofile/bp-xprofile-functions.php	(revision 7336)
+++ /branches/1.8/bp-xprofile/bp-xprofile-functions.php	(revision 7337)
@@ -590,5 +590,5 @@
 
 	if ( is_string( $meta_value ) )
-		$meta_value = stripslashes( $wpdb->escape( $meta_value ) );
+		$meta_value = stripslashes( esc_sql( $meta_value ) );
 
 	$meta_value = maybe_serialize( $meta_value );
Index: /branches/1.8/tests/testcases/core/class-bp-user-query.php
===================================================================
--- /branches/1.8/tests/testcases/core/class-bp-user-query.php	(revision 7336)
+++ /branches/1.8/tests/testcases/core/class-bp-user-query.php	(revision 7337)
@@ -201,3 +201,25 @@
 		$this->assertEquals( $user_id, $found_user_id );
 	}
+
+	/**
+	 * @group exclude
+	 */
+	public function test_bp_user_query_with_exclude() {
+		// Grab list of existing users who should also be excluded
+		global $wpdb;
+		$existing_users = $wpdb->get_col( "SELECT ID FROM {$wpdb->users}" );
+
+		$u1 = $this->create_user();
+		$u2 = $this->create_user();
+
+		$exclude = array_merge( array( $u1 ), $existing_users );
+		$q = new BP_User_Query( array( 'exclude' => $exclude, ) );
+
+		$found_user_ids = null;
+		if ( ! empty( $q->results ) ) {
+			$found_user_ids = array_values( wp_parse_id_list( wp_list_pluck( $q->results, 'ID' ) ) );
+		}
+
+		$this->assertEquals( array( $u2 ), $found_user_ids );
+	}
 }
