Index: trunk/bp-core.php
===================================================================
--- trunk/bp-core.php	(revision 2077)
+++ trunk/bp-core.php	(revision 2088)
@@ -533,21 +533,33 @@
  * @uses get_usermeta() WordPress function to get the usermeta for a user.
  */
-function bp_core_get_user_domain( $user_id ) {
+function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) {
 	global $bp;
 
 	if ( !$user_id ) return;
 
-	$ud = get_userdata($user_id);
+	if ( $domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) )
+		return apply_filters( 'bp_core_get_user_domain', $domain );
+
+	if ( !$user_nicename && !$user_login ) {
+		$ud = get_userdata($user_id);
+		$user_nicename = $ud->user_nicename;
+		$user_login = $ud->user_login;
+	}
 
 	if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
-		$username = $ud->user_login;
+		$username = $user_login;
 	else
-		$username = $ud->user_nicename;
+		$username = $user_nicename;
 
 	/* If we are using a members slug, include it. */
 	if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
-		return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/' );
+		$domain = $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
 	else
-		return apply_filters( 'bp_core_get_user_domain', $bp->root_domain . '/' . $username . '/' );
+		$domain = $bp->root_domain . '/' . $username . '/';
+
+	/* Cache the link */
+	wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
+
+	return apply_filters( 'bp_core_get_user_domain', $domain );
 }
 
@@ -721,18 +733,4 @@
 }
 add_action( 'wp_head', 'bp_core_sort_nav_items' );
-
-/**
- * bp_core_remove_nav_item()
- *
- * Removes a navigation item from the main navigation array.
- *
- * @package BuddyPress Core
- * @param $slug The slug of the sub navigation item.
- */
-function bp_core_remove_nav_item( $slug ) {
-	global $bp;
-
-	unset( $bp->bp_nav[$slug] );
-}
 
 /**
@@ -820,5 +818,5 @@
 
 /**
- * bp_core_remove_subnav_item()
+ * bp_core_remove_nav_item()
  *
  * Removes a navigation item from the sub navigation array used in BuddyPress themes.
@@ -828,8 +826,40 @@
  * @param $slug The slug of the sub navigation item.
  */
+function bp_core_remove_nav_item( $parent_id ) {
+	global $bp;
+
+	/* Unset subnav items for this nav item */
+	foreach( $bp->bp_options_nav[$parent_id] as $subnav_item ) {
+		bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );
+	}
+
+	unset( $bp->bp_nav[$parent_id] );
+}
+
+/**
+ * bp_core_remove_subnav_item()
+ *
+ * Removes a navigation item from the sub navigation array used in BuddyPress themes.
+ *
+ * @package BuddyPress Core
+ * @param $parent_id The id of the parent navigation item.
+ * @param $slug The slug of the sub navigation item.
+ */
 function bp_core_remove_subnav_item( $parent_id, $slug ) {
 	global $bp;
 
+	$function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];
+
+	if ( $function ) {
+		if ( !is_object( $screen_function[0] ) )
+			remove_action( 'wp', $screen_function, 3 );
+		else
+			remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
+	}
+
 	unset( $bp->bp_options_nav[$parent_id][$slug] );
+
+	if ( !count( $bp->bp_options_nav[$parent_id] ) )
+		unset($bp->bp_options_nav[$parent_id]);
 }
 
@@ -979,8 +1009,9 @@
 	global $bp;
 
-	if ( !is_numeric($uid) )
-		return false;
-
-	return apply_filters( 'bp_core_get_userurl', bp_core_get_user_domain( $uid ) );
+	if ( !$url = wp_cache_get( 'bp_user_url_' . $uid, 'bp' ) ) {
+		$url = bp_core_get_user_domain( $uid );
+	}
+
+	return apply_filters( 'bp_core_get_userurl', $url );
 }
 
@@ -997,6 +1028,9 @@
  */
 function bp_core_get_user_email( $uid ) {
-	$ud = get_userdata($uid);
-	return apply_filters( 'bp_core_get_user_email', $ud->user_email );
+	if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {
+		$ud = get_userdata($uid);
+		$email = $ud->user_email;
+	}
+	return apply_filters( 'bp_core_get_user_email', $email );
 }
 
@@ -1031,5 +1065,5 @@
 		return false;
 
-	if ( function_exists('bp_fetch_user_fullname') ) {
+	if ( function_exists( 'bp_core_get_user_displayname' ) ) {
 		$display_name = bp_core_get_user_displayname( $user_id );
 
@@ -1050,5 +1084,5 @@
 		return $url;
 
-	return '<a href="' . $url . '">' . $display_name . '</a>';
+	return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '">' . $display_name . '</a>', $user_id );
 }
 
@@ -1666,5 +1700,5 @@
 	global $wpdb;
 	?>
-<!-- Generated in <?php timer_stop(1); ?> seconds. -->
+<!-- Generated in <?php timer_stop(1); ?> seconds. <?php echo get_num_queries(); ?> -->
 	<?php
 }
