diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
index e25389a..8108771 100644
--- src/bp-core/bp-core-functions.php
+++ src/bp-core/bp-core-functions.php
@@ -116,38 +116,60 @@ function bp_core_get_table_prefix() {
  * @return array $items The sorted array.
  */
 function bp_sort_by_key( $items, $key, $type = 'alpha' ) {
-	usort( $items, create_function( '$a, $b', '
-		$values = array( 0 => false, 1 => false, );
-		$func_args = func_get_args();
-		foreach ( $func_args as $indexi => $index ) {
-			if ( isset( $index->' . $key . ' ) ) {
-				$values[ $indexi ] = $index->' . $key . ';
-			} elseif ( isset( $index["' . $key . '"] ) ) {
-				$values[ $indexi ] = $index["' . $key . '"];
-			}
-		}
+	$bp = buddypress();
 
-		if ( isset( $values[0], $values[1] ) ) {
-			if ( "num" === "' . $type . '" ) {
-				$cmp = $values[0] - $values[1];
-			} else {
-				$cmp = strcmp( $values[0], $values[1] );
-			}
+	$bp->sort_key  = $key;
+	$bp->sort_type = $type;
 
-			if ( 0 > $cmp ) {
-				$retval = -1;
-			} elseif ( 0 < $cmp ) {
-				$retval = 1;
-			} else {
-				$retval = 0;
-			}
-			return $retval;
+	usort( $items, '_bp_sort_by_key_cb' );
+
+	unset( $bp->sort_key );
+	unset( $bp->sort_type );
+
+	return $items;
+}
+
+/**
+ * Sorting callback for bp_sort_by_key().
+ *
+ * @since 2.5.0
+ *
+ * @param object|array $a
+ * @param object|array $b
+ * @return int
+ */
+function _bp_sort_by_key_cb( $a, $b ) {
+	$key  = buddypress()->sort_key;
+	$type = buddypress()->sort_type;
+
+	$values = array( 0 => false, 1 => false, );
+	$func_args = func_get_args();
+	foreach ( $func_args as $indexi => $index ) {
+		if ( isset( $index->{$key} ) ) {
+			$values[ $indexi ] = $index->{$key};
+		} elseif ( isset( $index[ $key ] ) ) {
+			$values[ $indexi ] = $index[ $key ];
+		}
+	}
+
+	if ( isset( $values[0], $values[1] ) ) {
+		if ( 'num' === $type ) {
+			$cmp = $values[0] - $values[1];
 		} else {
-			return 0;
+			$cmp = strcmp( $values[0], $values[1] );
 		}
-	') );
 
-	return $items;
+		if ( 0 > $cmp ) {
+			$retval = -1;
+		} elseif ( 0 < $cmp ) {
+			$retval = 1;
+		} else {
+			$retval = 0;
+		}
+		return $retval;
+	} else {
+		return 0;
+	}
 }
 
 /**
diff --git src/bp-loader.php src/bp-loader.php
index 05c6e88..60f31cc 100644
--- src/bp-loader.php
+++ src/bp-loader.php
@@ -101,6 +101,22 @@ class BuddyPress {
 	 */
 	public $active_components = array();
 
+	/**
+	 * Sort key for bp_sort_by_key().
+	 *
+	 * @since 2.5.0
+	 * @var mixed
+	 */
+	public $sort_key;
+
+	/**
+	 * Sort type for bp_sort_by_key().
+	 *
+	 * @since 2.5.0
+	 * @var string
+	 */
+	public $sort_type;
+
 	/** Option Overload *******************************************************/
 
 	/**
