Index: /trunk/src/bp-activity/bp-activity-actions.php
===================================================================
--- /trunk/src/bp-activity/bp-activity-actions.php	(revision 9470)
+++ /trunk/src/bp-activity/bp-activity-actions.php	(revision 9471)
@@ -36,5 +36,4 @@
  * @since BuddyPress (1.2)
  *
- * @global object $bp BuddyPress global settings
  * @uses bp_is_activity_component()
  * @uses bp_is_current_action()
@@ -201,10 +200,9 @@
  * @since BuddyPress (1.6)
  *
- * @global object $bp BuddyPress global settings
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
  * @return bool False on failure.
  */
 function bp_activity_action_spam_activity( $activity_id = 0 ) {
-	global $bp;
+	$bp = buddypress();
 
 	// Not viewing activity, or action is not spam, or Akismet isn't present
@@ -507,5 +505,4 @@
  * @since BuddyPress (1.0)
  *
- * @global object $bp BuddyPress global settings
  * @uses bp_is_activity_component()
  * @uses bp_is_current_action()
@@ -516,5 +513,5 @@
  */
 function bp_activity_action_sitewide_feed() {
-	global $bp;
+	$bp = buddypress();
 
 	if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) )
@@ -715,9 +712,7 @@
  *
  * @since BuddyPress (1.6)
- *
- * @global object $bp BuddyPress global settings
  */
 function bp_activity_setup_akismet() {
-	global $bp;
+	$bp = buddypress();
 
 	// Bail if Akismet is not active
Index: /trunk/src/bp-activity/bp-activity-admin.php
===================================================================
--- /trunk/src/bp-activity/bp-activity-admin.php	(revision 9470)
+++ /trunk/src/bp-activity/bp-activity-admin.php	(revision 9471)
@@ -821,10 +821,8 @@
  * @since BuddyPress (1.6.0)
  *
- * @global object $bp BuddyPress global settings.
- *
  * @param object $item Activity item.
  */
 function bp_activity_admin_edit_metabox_type( $item ) {
-	global $bp;
+	$bp = buddypress();
 
 	$actions  = array();
Index: /trunk/src/bp-activity/bp-activity-akismet.php
===================================================================
--- /trunk/src/bp-activity/bp-activity-akismet.php	(revision 9470)
+++ /trunk/src/bp-activity/bp-activity-akismet.php	(revision 9471)
@@ -655,9 +655,10 @@
  * @since BuddyPress (1.6)
  *
- * @global object $bp BuddyPress global settings.
  * @global wpdb $wpdb WordPress database object.
  */
 function bp_activity_akismet_delete_old_metadata() {
-	global $bp, $wpdb;
+	global $wpdb;
+
+	$bp = buddypress();
 
 	/**
Index: /trunk/src/bp-activity/bp-activity-cache.php
===================================================================
--- /trunk/src/bp-activity/bp-activity-cache.php	(revision 9470)
+++ /trunk/src/bp-activity/bp-activity-cache.php	(revision 9471)
@@ -21,5 +21,5 @@
  */
 function bp_activity_update_meta_cache( $activity_ids = false ) {
-	global $bp;
+	$bp = buddypress();
 
 	$cache_args = array(
Index: /trunk/src/bp-activity/bp-activity-functions.php
===================================================================
--- /trunk/src/bp-activity/bp-activity-functions.php	(revision 9470)
+++ /trunk/src/bp-activity/bp-activity-functions.php	(revision 9471)
@@ -912,5 +912,4 @@
  *
  * @global object $wpdb WordPress database access object.
- * @global object $bp BuddyPress global settings.
  *
  * @param int $activity_id ID of the activity item whose metadata is being deleted.
@@ -1079,5 +1078,4 @@
  *
  * @global object $wpdb WordPress database access object.
- * @global object $bp BuddyPress global settings.
  *
  * @param int $user_id ID of the user whose activity is being spammed.
@@ -1148,5 +1146,4 @@
  *
  * @global object $wpdb WordPress database access object.
- * @global object $bp BuddyPress global settings.
  *
  * @param int $user_id ID of the user whose activity is being hammed.
@@ -2054,5 +2051,4 @@
  * @since BuddyPress (1.2.0)
  *
- * @global object $bp BuddyPress global settings.
  * @uses wp_parse_args()
  * @uses bp_activity_add()
Index: /trunk/src/bp-activity/bp-activity-screens.php
===================================================================
--- /trunk/src/bp-activity/bp-activity-screens.php	(revision 9470)
+++ /trunk/src/bp-activity/bp-activity-screens.php	(revision 9471)
@@ -231,5 +231,4 @@
  * @since BuddyPress (1.2.0)
  *
- * @global object $bp BuddyPress global settings
  * @uses bp_is_activity_component()
  * @uses bp_activity_get_specific()
@@ -253,5 +252,5 @@
  */
 function bp_activity_screen_single_activity_permalink() {
-	global $bp;
+	$bp = buddypress();
 
 	// No displayed user or not viewing activity component
Index: /trunk/src/bp-activity/bp-activity-template.php
===================================================================
--- /trunk/src/bp-activity/bp-activity-template.php	(revision 9470)
+++ /trunk/src/bp-activity/bp-activity-template.php	(revision 9471)
@@ -165,5 +165,5 @@
 	 */
 	function __construct( $args ) {
-		global $bp;
+		$bp = buddypress();
 
 		// Backward compatibility with old method of passing arguments
@@ -427,5 +427,4 @@
  *
  * @global object $activities_template {@link BP_Activity_Template}
- * @global object $bp BuddyPress global settings.
  * @uses groups_is_user_member()
  * @uses bp_current_action()
@@ -1349,5 +1348,4 @@
 	 * @see bp_core_fetch_avatar() For a description of the arguments.
 	 * @global object $activities_template {@link BP_Activity_Template}
-	 * @global object $bp BuddyPress global settings
 	 * @uses bp_is_single_activity()
 	 * @uses wp_parse_args()
Index: /trunk/src/bp-blogs/bp-blogs-activity.php
===================================================================
--- /trunk/src/bp-blogs/bp-blogs-activity.php	(revision 9470)
+++ /trunk/src/bp-blogs/bp-blogs-activity.php	(revision 9471)
@@ -16,10 +16,8 @@
  * @since BuddyPress (1.0.0)
  *
- * @global object $bp The BuddyPress global settings object.
- *
  * @return bool|null Returns false if activity component is not active.
  */
 function bp_blogs_register_activity_actions() {
-	global $bp;
+	$bp = buddypress();
 
 	// Bail if activity is not active
@@ -322,5 +320,4 @@
  *
  * @see bp_activity_add() for description of parameters.
- * @global object $bp The BuddyPress global settings object.
  *
  * @param array $args {
@@ -333,5 +330,4 @@
  */
 function bp_blogs_record_activity( $args = '' ) {
-	global $bp;
 
 	// Bail if activity is not active
@@ -339,4 +335,6 @@
 		return false;
 	}
+
+	$bp = buddypress();
 
 	$defaults = array(
Index: /trunk/src/bp-blogs/bp-blogs-classes.php
===================================================================
--- /trunk/src/bp-blogs/bp-blogs-classes.php	(revision 9470)
+++ /trunk/src/bp-blogs/bp-blogs-classes.php	(revision 9471)
@@ -40,5 +40,7 @@
 	 */
 	public function populate() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
@@ -54,5 +56,5 @@
 	 */
 	public function save() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id );
@@ -78,4 +80,6 @@
 			return false;
 
+		$bp = buddypress();
+
 		if ( $this->id ) {
 			// Update
@@ -113,5 +117,7 @@
 	 */
 	public function exists() {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
@@ -141,5 +147,7 @@
 	 */
 	public static function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false, $update_meta_cache = true, $include_blog_ids = false ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
@@ -232,7 +240,10 @@
 	 */
 	public static function delete_blog_for_all( $blog_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		bp_blogs_delete_blogmeta( $blog_id );
+		
+		$bp = buddypress();
+
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
 	}
@@ -247,8 +258,10 @@
 	 */
 	public static function delete_blog_for_user( $blog_id, $user_id = null ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !$user_id )
 			$user_id = bp_loggedin_user_id();
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
@@ -264,8 +277,10 @@
 	 */
 	public static function delete_blogs_for_user( $user_id = null ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !$user_id )
 			$user_id = bp_loggedin_user_id();
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
@@ -290,5 +305,7 @@
 	 */
 	public static function get_blogs_for_user( $user_id = 0, $show_hidden = false ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( !$user_id )
@@ -325,5 +342,7 @@
 	 */
 	public static function get_blog_ids_for_user( $user_id = 0 ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( !$user_id )
@@ -341,5 +360,7 @@
 	 */
 	public static function is_recorded( $blog_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
@@ -358,5 +379,7 @@
 	 */
 	public static function total_blog_count_for_user( $user_id = null ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( !$user_id )
@@ -387,5 +410,5 @@
 	 */
 	public static function search_blogs( $filter, $limit = null, $page = null ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$search_terms_like = '%' . bp_esc_like( $filter ) . '%';
@@ -400,4 +423,6 @@
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 		}
+
+		$bp = buddypress();
 
 		$paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND {$search_terms_sql} ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
@@ -422,8 +447,10 @@
 	 */
 	public static function get_all( $limit = null, $page = null ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$hidden_sql = !bp_current_user_can( 'bp_moderate' ) ? "AND wb.public = 1" : '';
-		$pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
+		$pag_sql    = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
 
 		$paged_blogs = $wpdb->get_results( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql} {$pag_sql}" );
@@ -449,5 +476,7 @@
 	 */
 	public static function get_by_letter( $letter, $limit = null, $page = null ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$letter_like = '%' . bp_esc_like( $letter ) . '%';
@@ -483,5 +512,7 @@
 	 */
 	public static function get_blog_extras( &$paged_blogs, &$blog_ids, $type = false ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( empty( $blog_ids ) )
@@ -562,5 +593,7 @@
 	 */
 	public static function get_user_blog( $user_id, $blog_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$user_blog = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
Index: /trunk/src/bp-blogs/bp-blogs-functions.php
===================================================================
--- /trunk/src/bp-blogs/bp-blogs-functions.php	(revision 9470)
+++ /trunk/src/bp-blogs/bp-blogs-functions.php	(revision 9471)
@@ -15,10 +15,8 @@
  * @since BuddyPress (1.5.0)
  *
- * @global BuddyPress $bp The one true BuddyPress instance.
- *
  * @return bool True if set, false if empty.
  */
 function bp_blogs_has_directory() {
-	global $bp;
+	$bp = buddypress();
 
 	return (bool) !empty( $bp->pages->blogs->id );
@@ -827,5 +825,4 @@
  */
 function bp_blogs_remove_blog( $blog_id ) {
-	global $bp;
 
 	$blog_id = (int) $blog_id;
@@ -844,5 +841,9 @@
 
 	// Delete activity stream item
-	bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => 'new_blog' ) );
+	bp_blogs_delete_activity( array(
+		'item_id'   => $blog_id,
+		'component' => buddypress()->blogs->id,
+		'type'      => 'new_blog'
+	) );
 
 	/**
@@ -865,5 +866,4 @@
  */
 function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
-	global $bp;
 
 	$blog_id = (int) $blog_id;
@@ -885,5 +885,5 @@
 	bp_blogs_delete_activity( array(
 		'item_id'   => $blog_id,
-		'component' => $bp->blogs->id,
+		'component' => buddypress()->blogs->id,
 		'type'      => 'new_blog'
 	) );
@@ -910,5 +910,5 @@
  */
 function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
-	global $wpdb, $bp;
+	global $wpdb;
 
 	if ( empty( $wpdb->blogid ) )
@@ -935,5 +935,10 @@
 
 	// Delete activity stream item
-	bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->id, 'type' => 'new_blog_post' ) );
+	bp_blogs_delete_activity( array(
+		'item_id'           => $blog_id,
+		'secondary_item_id' => $post_id,
+		'component'         => buddypress()->blogs->id,
+		'type'              => 'new_blog_post'
+	) );
 
 	/**
@@ -1064,6 +1069,4 @@
  * @since BuddyPress (1.6.0)
  *
- * @global object $bp BuddyPress global settings.
- *
  * @param string $new_status New comment status.
  * @param string $old_status Previous comment status.
@@ -1071,5 +1074,4 @@
  */
 function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {
-	global $bp;
 
 	// Check the Activity component is active
@@ -1100,5 +1102,10 @@
 	// Get the activity
 	if ( bp_disable_blogforum_comments() ) {
-		$activity_id = bp_activity_get_activity_id( array( 'component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment', ) );
+		$activity_id = bp_activity_get_activity_id( array(
+			'component'         => buddypress()->blogs->id,
+			'item_id'           => get_current_blog_id(),
+			'secondary_item_id' => $comment->comment_ID,
+			'type'              => 'new_blog_comment'
+		) );
 	} else {
 		$activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
@@ -1189,5 +1196,4 @@
  */
 function bp_blogs_remove_data_for_blog( $blog_id ) {
-	global $bp;
 
 	/**
@@ -1205,5 +1211,9 @@
 
 	// Delete activity stream item
-	bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => false ) );
+	bp_blogs_delete_activity( array(
+		'item_id'   => $blog_id,
+		'component' => buddypress()->blogs->id,
+		'type'      => false
+	) );
 
 	/**
@@ -1284,5 +1294,4 @@
  *
  * @global object $wpdb WordPress database access object.
- * @global object $bp BuddyPress global settings.
  *
  * @param int $blog_id ID of the blog whose metadata is being deleted.
@@ -1298,5 +1307,5 @@
  */
 function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
-	global $wpdb, $bp;
+	global $wpdb;
 
 	// Legacy - if no meta_key is passed, delete all for the blog_id
@@ -1326,5 +1335,4 @@
  *
  * @global object $wpdb WordPress database access object.
- * @global object $bp BuddyPress global settings.
  *
  * @param int $blog_id ID of the blog whose metadata is being requested.
@@ -1349,5 +1357,4 @@
  *
  * @global object $wpdb WordPress database access object.
- * @global object $bp BuddyPress global settings.
  *
  * @param int $blog_id ID of the blog whose metadata is being updated.
Index: /trunk/src/bp-blogs/bp-blogs-template.php
===================================================================
--- /trunk/src/bp-blogs/bp-blogs-template.php	(revision 9470)
+++ /trunk/src/bp-blogs/bp-blogs-template.php	(revision 9471)
@@ -1115,7 +1115,9 @@
  */
 function bp_blog_signup_enabled() {
-	global $bp;
-
-	$active_signup = isset( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : 'all';
+	$bp = buddypress();
+
+	$active_signup = isset( $bp->site_options['registration'] )
+		? $bp->site_options['registration']
+		: 'all';
 
 	/**
Index: /trunk/src/bp-core/admin/bp-core-slugs.php
===================================================================
--- /trunk/src/bp-core/admin/bp-core-slugs.php	(revision 9470)
+++ /trunk/src/bp-core/admin/bp-core-slugs.php	(revision 9471)
@@ -49,5 +49,5 @@
  */
 function bp_core_admin_slugs_options() {
-	global $bp;
+	$bp = buddypress();
 
 	// Get the existing WP pages
Index: /trunk/src/bp-core/admin/bp-core-tools.php
===================================================================
--- /trunk/src/bp-core/admin/bp-core-tools.php	(revision 9470)
+++ /trunk/src/bp-core/admin/bp-core-tools.php	(revision 9471)
@@ -156,5 +156,5 @@
  */
 function bp_admin_repair_friend_count() {
-	global $wpdb, $bp;
+	global $wpdb;
 
 	if ( ! bp_is_active( 'friends' ) ) {
@@ -169,4 +169,6 @@
 		return array( 1, sprintf( $statement, $result ) );
 	}
+
+	$bp = buddypress();
 
 	// Walk through all users on the site
@@ -212,5 +214,5 @@
  */
 function bp_admin_repair_group_count() {
-	global $wpdb, $bp;
+	global $wpdb;
 
 	if ( ! bp_is_active( 'groups' ) ) {
@@ -225,4 +227,6 @@
 		return array( 1, sprintf( $statement, $result ) );
 	}
+
+	$bp = buddypress();
 
 	// Walk through all users on the site
Index: /trunk/src/bp-core/bp-core-buddybar.php
===================================================================
--- /trunk/src/bp-core/bp-core-buddybar.php	(revision 9470)
+++ /trunk/src/bp-core/bp-core-buddybar.php	(revision 9471)
@@ -14,6 +14,4 @@
 /**
  * Add an item to the main BuddyPress navigation array.
- *
- * @global BuddyPress $bp The one true BuddyPress instance.
  *
  * @param array $args {
@@ -39,5 +37,5 @@
  */
 function bp_core_new_nav_item( $args = '' ) {
-	global $bp;
+	$bp = buddypress();
 
 	$defaults = array(
@@ -120,6 +118,4 @@
  * Modify the default subnav item that loads when a top level nav item is clicked.
  *
- * @global BuddyPress $bp The one true BuddyPress instance.
- *
  * @param array $args {
  *     @type string $parent_slug The slug of the nav item whose default is
@@ -131,5 +127,5 @@
  */
 function bp_core_new_nav_default( $args = '' ) {
-	global $bp;
+	$bp = buddypress();
 
 	$defaults = array(
@@ -196,10 +192,8 @@
  * after all plugins have had a chance to register their navigation items.
  *
- * @global BuddyPress $bp The one true BuddyPress instance
- *
  * @return bool|null Returns false on failure.
  */
 function bp_core_sort_nav_items() {
-	global $bp;
+	$bp = buddypress();
 
 	if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
@@ -229,6 +223,4 @@
 /**
  * Add a subnav item to the BuddyPress navigation.
- *
- * @global BuddyPress $bp The one true BuddyPress instance.
  *
  * @param array $args {
@@ -261,5 +253,5 @@
  */
 function bp_core_new_subnav_item( $args = '' ) {
-	global $bp;
+	$bp = buddypress();
 
 	$r = wp_parse_args( $args, array(
@@ -442,10 +434,8 @@
  * Sort all subnavigation arrays.
  *
- * @global BuddyPress $bp The one true BuddyPress instance
- *
  * @return bool|null Returns false on failure.
  */
 function bp_core_sort_subnav_items() {
-	global $bp;
+	$bp = buddypress();
 
 	if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
@@ -487,5 +477,5 @@
  */
 function bp_nav_item_has_subnav( $nav_item = '' ) {
-	global $bp;
+	$bp = buddypress();
 
 	if ( !$nav_item )
@@ -504,5 +494,5 @@
  */
 function bp_core_remove_nav_item( $parent_id ) {
-	global $bp;
+	$bp = buddypress();
 
 	// Unset subnav items for this nav item
@@ -533,7 +523,9 @@
  */
 function bp_core_remove_subnav_item( $parent_id, $slug ) {
-	global $bp;
-
-	$screen_function = isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) ? $bp->bp_options_nav[$parent_id][$slug]['screen_function'] : false;
+	$bp = buddypress();
+
+	$screen_function = isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] )
+		? $bp->bp_options_nav[$parent_id][$slug]['screen_function']
+		: false;
 
 	if ( ! empty( $screen_function ) ) {
@@ -553,10 +545,8 @@
  * Clear all subnav items from a specific nav item.
  *
- * @global BuddyPress $bp The one true BuddyPress instance.
- *
  * @param string $parent_slug The slug of the parent navigation item.
  */
 function bp_core_reset_subnav_items( $parent_slug ) {
-	global $bp;
+	$bp = buddypress();
 
 	unset( $bp->bp_options_nav[$parent_slug] );
Index: /trunk/src/bp-core/bp-core-catchuri.php
===================================================================
--- /trunk/src/bp-core/bp-core-catchuri.php	(revision 9470)
+++ /trunk/src/bp-core/bp-core-catchuri.php	(revision 9471)
@@ -34,9 +34,11 @@
  */
 function bp_core_set_uri_globals() {
-	global $bp, $current_blog, $wp_rewrite;
+	global $current_blog, $wp_rewrite;
 
 	// Don't catch URIs on non-root blogs unless multiblog mode is on
 	if ( !bp_is_root_blog() && !bp_is_multiblog_mode() )
 		return false;
+
+	$bp = buddypress();
 
 	// Define local variables
@@ -419,5 +421,7 @@
  */
 function bp_core_catch_no_access() {
-	global $bp, $wp_query;
+	global $wp_query;
+
+	$bp = buddypress();
 
 	// If coming from bp_core_redirect() and $bp_no_status_set is true,
@@ -550,5 +554,4 @@
  */
 function bp_redirect_canonical() {
-	global $bp;
 
 	if ( !bp_is_blog_page() && apply_filters( 'bp_do_redirect_canonical', true ) ) {
@@ -574,4 +577,6 @@
 		if ( $canonical_url !== $req_url_clean ) {
 
+			$bp = buddypress();
+
 			// Template messages have been deleted from the cookie by this point, so
 			// they must be readded before redirecting
@@ -619,5 +624,4 @@
  */
 function bp_get_canonical_url( $args = array() ) {
-	global $bp;
 
 	// For non-BP content, return the requested url, and let WP do the work
@@ -625,4 +629,6 @@
 		return bp_get_requested_url();
 	}
+
+	$bp = buddypress();
 
 	$defaults = array(
@@ -701,5 +707,5 @@
  */
 function bp_get_requested_url() {
-	global $bp;
+	$bp = buddypress();
 
 	if ( empty( $bp->canonical_stack['requested_url'] ) ) {
Index: /trunk/src/bp-core/bp-core-classes.php
===================================================================
--- /trunk/src/bp-core/bp-core-classes.php	(revision 9470)
+++ /trunk/src/bp-core/bp-core-classes.php	(revision 9471)
@@ -222,5 +222,7 @@
 	 */
 	public function prepare_user_ids_query() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		// Default query variables used here
@@ -953,7 +955,9 @@
 	 */
 	public static function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		_deprecated_function( __METHOD__, '1.7', 'BP_User_Query' );
+
+		$bp = buddypress();
 
 		$sql = array();
@@ -1129,5 +1133,4 @@
 	 * Fetch the details for all users whose usernames start with the given letter.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance.
 	 * @global wpdb $wpdb WordPress database object.
 	 *
@@ -1143,5 +1146,5 @@
 	 */
 	public static function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) {
-		global $bp, $wpdb;
+		global $wpdb;
 
 		$pag_sql = '';
@@ -1160,4 +1163,6 @@
 			}
 		}
+
+		$bp = buddypress();
 
 		$letter_like = bp_esc_like( $letter ) . '%';
@@ -1244,5 +1249,4 @@
 	 * Find users who match on the value of an xprofile data.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance.
 	 * @global wpdb $wpdb WordPress database object.
 	 *
@@ -1255,5 +1259,7 @@
 	 */
 	public static function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$user_ids = array();
@@ -1288,5 +1294,4 @@
 	 * Accepts multiple user IDs to fetch data for.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance.
 	 * @global wpdb $wpdb WordPress database object.
 	 *
@@ -1297,5 +1302,7 @@
 	 */
 	public static function get_user_extras( &$paged_users, &$user_ids, $type = false ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( empty( $user_ids ) )
@@ -1699,10 +1706,11 @@
 	 * Update or insert notification details into the database.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance
 	 * @global wpdb $wpdb WordPress database object
 	 * @return bool Success or failure
 	 */
 	public function save() {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		// Update
@@ -1728,9 +1736,10 @@
 	 * Fetches the notification data from the database.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance
 	 * @global wpdb $wpdb WordPress database object
 	 */
 	public function populate() {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
@@ -1748,5 +1757,7 @@
 
 	public static function check_access( $user_id, $notification_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->core->table_name_notifications} WHERE id = %d AND user_id = %d", $notification_id, $user_id ) );
@@ -1756,5 +1767,4 @@
 	 * Fetches all the notifications in the database for a specific user.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance
 	 * @global wpdb $wpdb WordPress database object
 	 * @param integer $user_id User ID
@@ -1764,7 +1774,11 @@
 	 */
 	public static function get_all_for_user( $user_id, $status = 'is_new' ) {
-		global $bp, $wpdb;
-
-		$is_new = ( 'is_new' == $status ) ? ' AND is_new = 1 ' : '';
+		global $wpdb;
+
+		$bp = buddypress();
+
+		$is_new = ( 'is_new' === $status )
+			? ' AND is_new = 1 '
+			: '';
 
  		return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d {$is_new}", $user_id ) );
@@ -1774,5 +1788,4 @@
 	 * Delete all the notifications for a user based on the component name and action.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance
 	 * @global wpdb $wpdb WordPress database object
 	 * @param integer $user_id
@@ -1782,5 +1795,7 @@
 	 */
 	public static function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
@@ -1790,5 +1805,4 @@
 	 * Delete all the notifications that have a specific item id, component name and action.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance
 	 * @global wpdb $wpdb WordPress database object
 	 * @param integer $user_id The ID of the user who the notifications are for.
@@ -1800,7 +1814,11 @@
 	 */
 	public static function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
-		global $bp, $wpdb;
-
-		$secondary_item_sql = !empty( $secondary_item_id ) ? $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id ) : '';
+		global $wpdb;
+
+		$bp = buddypress();
+
+		$secondary_item_sql = !empty( $secondary_item_id )
+			? $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id )
+			: '';
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) );
@@ -1810,5 +1828,4 @@
 	 * Deletes all the notifications sent by a specific user, by component and action.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance
 	 * @global wpdb $wpdb WordPress database object
 	 * @param integer $user_id The ID of the user whose sent notifications we wish to delete.
@@ -1818,5 +1835,7 @@
 	 */
 	public static function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
@@ -1826,5 +1845,4 @@
 	 * Deletes all the notifications for all users by item id, and optional secondary item id, and component name and action.
 	 *
-	 * @global BuddyPress $bp The one true BuddyPress instance
 	 * @global wpdb $wpdb WordPress database object
 	 * @param string $item_id The item id that they notifications are to be for.
@@ -1835,5 +1853,5 @@
 	 */
 	public static function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
 
 		if ( $component_action )
@@ -1846,4 +1864,6 @@
 		else
 			$secondary_item_sql = '';
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s {$component_action_sql} {$secondary_item_sql}", $item_id, $component_name ) );
Index: /trunk/src/bp-core/bp-core-filters.php
===================================================================
--- /trunk/src/bp-core/bp-core-filters.php	(revision 9470)
+++ /trunk/src/bp-core/bp-core-filters.php	(revision 9471)
@@ -504,5 +504,4 @@
  *
  * @see wp_title()
- * @global object $bp BuddyPress global settings.
  *
  * @param string $title Original page title.
@@ -512,5 +511,4 @@
  */
 function bp_modify_page_title( $title, $sep = '', $seplocation = '' ) {
-	global $bp;
 
 	// If this is not a BP page, just return the title produced by WP
@@ -529,4 +527,5 @@
 	}
 
+	$bp    = buddypress();
 	$title = '';
 
Index: /trunk/src/bp-core/bp-core-options.php
===================================================================
--- /trunk/src/bp-core/bp-core-options.php	(revision 9470)
+++ /trunk/src/bp-core/bp-core-options.php	(revision 9471)
@@ -297,7 +297,8 @@
  */
 function bp_core_activate_site_options( $keys = array() ) {
-	global $bp;
 
 	if ( !empty( $keys ) && is_array( $keys ) ) {
+		$bp = buddypress();
+
 		$errors = false;
 
Index: /trunk/src/bp-core/bp-core-template.php
===================================================================
--- /trunk/src/bp-core/bp-core-template.php	(revision 9470)
+++ /trunk/src/bp-core/bp-core-template.php	(revision 9471)
@@ -443,5 +443,6 @@
 	 */
 	function bp_get_search_default_text( $component = '' ) {
-		global $bp;
+
+		$bp = buddypress();
 
 		if ( empty( $component ) ) {
Index: /trunk/src/bp-core/deprecated/2.1.php
===================================================================
--- /trunk/src/bp-core/deprecated/2.1.php	(revision 9470)
+++ /trunk/src/bp-core/deprecated/2.1.php	(revision 9471)
@@ -91,6 +91,4 @@
  * @since BuddyPress (1.0.0)
  * @deprecated BuddyPress (2.1.0)
- *
- * @global object $bp The BuddyPress global settings object.
  *
  * @return bool|null Returns false on failure. Otherwise echoes the menu item.
Index: /trunk/src/bp-forums/bp-forums-filters.php
===================================================================
--- /trunk/src/bp-forums/bp-forums-filters.php	(revision 9470)
+++ /trunk/src/bp-forums/bp-forums-filters.php	(revision 9471)
@@ -105,6 +105,4 @@
  */
 function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
-	global $bp;
-
 	/**
 	 * Filters the link for a forum topic tags directory.
@@ -142,6 +140,4 @@
  * Append forum topic to page title.
  *
- * @global object $bp Global BuddyPress settings object.
- *
  * @see bp_modify_page_title()
  *
@@ -153,5 +149,4 @@
  */
 function bp_forums_add_forum_topic_to_page_title( $title, $original_title, $sep, $seplocation  ) {
-	global $bp;
 
 	if ( bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) )
Index: /trunk/src/bp-forums/bp-forums-functions.php
===================================================================
--- /trunk/src/bp-forums/bp-forums-functions.php	(revision 9470)
+++ /trunk/src/bp-forums/bp-forums-functions.php	(revision 9471)
@@ -316,5 +316,5 @@
  */
 function bp_forums_new_topic( $args = '' ) {
-	global $bp;
+	$bp = buddypress();
 
 	/** This action is documented in bp-forums/bp-forums-screens */
@@ -907,8 +907,10 @@
  */
 function bp_forums_get_post_extras( $posts ) {
-	global $bp, $wpdb;
+	global $wpdb;
 
 	if ( empty( $posts ) )
 		return $posts;
+
+	$bp = buddypress();
 
 	// Get the user ids
Index: /trunk/src/bp-forums/bp-forums-template.php
===================================================================
--- /trunk/src/bp-forums/bp-forums-template.php	(revision 9470)
+++ /trunk/src/bp-forums/bp-forums-template.php	(revision 9471)
@@ -28,6 +28,4 @@
 	 */
 	function bp_get_forums_slug() {
-		global $bp;
-
 		/**
 		 * Filters the forums component slug.
@@ -37,5 +35,5 @@
 		 * @param string $slug Forums component slug.
 		 */
-		return apply_filters( 'bp_get_forums_slug', $bp->forums->slug );
+		return apply_filters( 'bp_get_forums_slug', buddypress()->forums->slug );
 	}
 
@@ -58,6 +56,4 @@
 	 */
 	function bp_get_forums_root_slug() {
-		global $bp;
-
 		/**
 		 * Filters the forums component root slug.
@@ -67,5 +63,5 @@
 		 * @param string $root_slug Forums component root slug.
 		 */
-		return apply_filters( 'bp_get_forums_root_slug', $bp->forums->root_slug );
+		return apply_filters( 'bp_get_forums_root_slug', buddypress()->forums->root_slug );
 	}
 
@@ -231,5 +227,5 @@
 	 */
 	function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) {
-		global $bp;
+		$bp = buddypress();
 
 		$this->pag_page     = $page;
@@ -333,5 +329,5 @@
 		 * @param string $no_stickies Requested sticky format.
 		 */
-		$this->topic_count       = apply_filters_ref_array( 'bp_forums_template_topic_count',                                 array( $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies ) );
+		$this->topic_count = apply_filters_ref_array( 'bp_forums_template_topic_count', array( $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies ) );
 
 		/**
@@ -499,5 +495,7 @@
  */
 function bp_has_forum_topics( $args = '' ) {
-	global $forum_template, $bp;
+	global $forum_template;
+
+	$bp = buddypress();
 
 	/***
@@ -1666,6 +1664,4 @@
 	 */
 	function bp_get_my_forum_topics_link() {
-		global $bp;
-
 		/**
 		 * Filters the permalink to the 'personal' topics tab.
@@ -1690,6 +1686,4 @@
 	 */
 	function bp_get_unreplied_forum_topics_link() {
-		global $bp;
-
 		/**
 		 * Filters the permalink to the 'unreplied' topics tab.
@@ -1714,6 +1708,4 @@
 	 */
 	function bp_get_popular_forum_topics_link() {
-		global $bp;
-
 		/**
 		 * Filters the permalink to the 'popular' topics tab.
@@ -1738,6 +1730,4 @@
 	 */
 	function bp_get_newest_forum_topics_link() {
-		global $bp;
-
 		/**
 		 * Filters the link to the forums directory.
@@ -1764,5 +1754,4 @@
 	 */
 	function bp_get_forum_topic_type() {
-		global $bp;
 
 		if ( !bp_is_directory() || !bp_current_action() )
@@ -1879,5 +1868,5 @@
 	 */
 	function bp_get_forum_pagination_count() {
-		global $bp, $forum_template;
+		global $forum_template;
 
 		$start_num  = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1;
@@ -1909,5 +1898,4 @@
  */
 function bp_is_edit_topic() {
-	global $bp;
 
 	if ( bp_is_action_variable( 'post' ) && bp_is_action_variable( 'edit' ) )
@@ -2061,9 +2049,9 @@
 	 */
 	function __construct( $topic_id, $per_page, $max, $order ) {
-		global $bp, $current_user, $forum_template;
-
-                if ( !isset( $forum_template ) ) {
-                        $forum_template = new stdClass;
-                }
+		global $forum_template;
+
+		if ( !isset( $forum_template ) ) {
+			$forum_template = new stdClass;
+		}
 
 		$this->pag_page        = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1;
@@ -2193,5 +2181,4 @@
 	 */
 	function the_post() {
-		global $post;
 
 		$this->in_the_loop = true;
@@ -2516,5 +2503,5 @@
 	 */
 	function bp_get_the_topic_post_is_mine() {
-		global $bp, $topic_template;
+		global $topic_template;
 
 		return bp_loggedin_user_id() == $topic_template->post->poster_id;
@@ -2629,5 +2616,5 @@
  */
 function bp_the_topic_pagination_count() {
-	global $bp, $topic_template;
+	global $topic_template;
 
 	$start_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
@@ -2758,5 +2745,4 @@
 	 */
 	function bp_get_forum_name( $forum_id = 0 ) {
-		global $bp;
 
 		if ( empty( $forum_id ) ) {
Index: /trunk/src/bp-friends/bp-friends-classes.php
===================================================================
--- /trunk/src/bp-friends/bp-friends-classes.php	(revision 9470)
+++ /trunk/src/bp-friends/bp-friends-classes.php	(revision 9471)
@@ -113,5 +113,7 @@
 	 */
 	public function populate() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( $friendship = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) ) ) {
@@ -138,5 +140,7 @@
 	 */
 	public function save() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$this->initiator_user_id = apply_filters( 'friends_friendship_initiator_user_id_before_save', $this->initiator_user_id, $this->id );
@@ -178,5 +182,8 @@
 
 	public function delete() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) );
 	}
@@ -195,5 +202,5 @@
 	 */
 	public static function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !empty( $friend_requests_only ) ) {
@@ -205,4 +212,5 @@
 		}
 
+		$bp = buddypress();
 		$friends = $wpdb->get_results( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} {$friend_sql} {$oc_sql} ORDER BY date_created DESC" );
 		$fids = array();
@@ -228,5 +236,7 @@
 	 */
 	public static function get_friendship_id( $user_id, $friend_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->friends->table_name} WHERE ( initiator_user_id = %d AND friend_user_id = %d ) OR ( initiator_user_id = %d AND friend_user_id = %d ) AND is_confirmed = 1", $user_id, $friend_id, $friend_id, $user_id ) );
@@ -244,5 +254,7 @@
 
 		if ( false === $friend_requests ) {
-			global $wpdb, $bp;
+			global $wpdb;
+
+			$bp = buddypress();
 
 			$friend_requests = $wpdb->get_col( $wpdb->prepare( "SELECT initiator_user_id FROM {$bp->friends->table_name} WHERE friend_user_id = %d AND is_confirmed = 0", $user_id ) );
@@ -263,8 +275,10 @@
 	 */
 	public static function total_friend_count( $user_id = 0 ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
+
+		$bp = buddypress();
 
 		/* This is stored in 'total_friend_count' usermeta.
@@ -298,5 +312,5 @@
 	 */
 	public static function search_friends( $filter, $user_id, $limit = null, $page = null ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// TODO: Optimize this function.
@@ -321,4 +335,6 @@
 		if ( empty( $fids ) )
 			return false;
+
+		$bp = buddypress();
 
 		// filter the user_ids based on the search criteria.
@@ -356,9 +372,11 @@
 	 */
 	public static function check_is_friend( $initiator_userid, $possible_friend_userid ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $initiator_userid ) || empty( $possible_friend_userid ) ) {
 			return false;
 		}
+
+		$bp = buddypress();
 
 		$result = $wpdb->get_results( $wpdb->prepare( "SELECT id, initiator_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $initiator_userid, $possible_friend_userid, $possible_friend_userid, $initiator_userid ) );
@@ -419,5 +437,8 @@
 	 */
 	public static function accept($friendship_id) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 	 	return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, bp_loggedin_user_id() ) );
 	}
@@ -430,5 +451,8 @@
 	 */
 	public static function withdraw($friendship_id) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND initiator_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
 	}
@@ -441,5 +465,8 @@
 	 */
 	public static function reject($friendship_id) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND friend_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
 	}
@@ -458,5 +485,5 @@
 	 */
 	public static function search_users( $filter, $user_id, $limit = null, $page = null ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// Only search for matching strings at the beginning of the
@@ -470,4 +497,6 @@
 		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) );
+
+		$bp = buddypress();
 
 		// filter the user_ids based on the search criteria.
@@ -495,5 +524,5 @@
 	 */
 	public static function search_users_count( $filter ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// Only search for matching strings at the beginning of the
@@ -503,4 +532,6 @@
 		$usermeta_table = $wpdb->prefix . 'usermeta';
 		$users_table    = $wpdb->base_prefix . 'users';
+
+		$bp = buddypress();
 
 		// filter the user_ids based on the search criteria.
@@ -528,8 +559,10 @@
 	 */
 	public static function sort_by_name( $user_ids ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !bp_is_active( 'xprofile' ) )
 			return false;
+
+		$bp = buddypress();
 
 		$user_ids = implode( ',', wp_parse_id_list( $user_ids ) );
@@ -548,6 +581,7 @@
 	 */
 	public static function get_random_friends( $user_id, $total_friends = 5 ) {
-		global $wpdb, $bp;
-
+		global $wpdb;
+
+		$bp      = buddypress();
 		$fids    = array();
 		$sql     = $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE (friend_user_id = %d || initiator_user_id = %d) && is_confirmed = 1 ORDER BY rand() LIMIT %d", $user_id, $user_id, $total_friends );
@@ -612,5 +646,8 @@
 	 */
 	public static function get_user_ids_for_friendship( $friendship_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->get_row( $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE id = %d", $friendship_id ) );
 	}
@@ -622,5 +659,7 @@
 	 */
 	public static function delete_all_for_user( $user_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		// Get friends of $user_id
Index: /trunk/src/bp-friends/bp-friends-filters.php
===================================================================
--- /trunk/src/bp-friends/bp-friends-filters.php	(revision 9470)
+++ /trunk/src/bp-friends/bp-friends-filters.php	(revision 9471)
@@ -16,5 +16,4 @@
  * @since BuddyPress (1.7.0)
  *
- * @global BuddyPress $bp Global BuddyPress settings.
  * @global WPDB $wpdb WordPress database access object.
  *
@@ -24,5 +23,5 @@
  */
 function bp_friends_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) {
-	global $bp, $wpdb;
+	global $wpdb;
 
 	// stop if user isn't logged in
@@ -30,4 +29,6 @@
 		return;
 	}
+
+	$bp = buddypress();
 
 	// Fetch whether or not the user is a friend of the current user
Index: /trunk/src/bp-groups/bp-groups-actions.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-actions.php	(revision 9470)
+++ /trunk/src/bp-groups/bp-groups-actions.php	(revision 9471)
@@ -96,5 +96,4 @@
  */
 function groups_action_create_group() {
-	global $bp;
 
 	// If we're not at domain.org/groups/create/ then return false
@@ -109,4 +108,6 @@
 		bp_core_redirect( bp_get_groups_directory_permalink() );
 	}
+
+	$bp = buddypress();
 
 	// Make sure creation steps are in the right order
@@ -361,5 +362,4 @@
  */
 function groups_action_join_group() {
-	global $bp;
 
 	if ( !bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( 'join' ) )
@@ -369,4 +369,6 @@
 	if ( !check_admin_referer( 'groups_join_group' ) )
 		return false;
+
+	$bp = buddypress();
 
 	// Skip if banned or already a member
@@ -457,8 +459,9 @@
  */
 function groups_action_sort_creation_steps() {
-	global $bp;
 
 	if ( !bp_is_groups_component() || !bp_is_current_action( 'create' ) )
 		return false;
+
+	$bp = buddypress();
 
 	if ( !is_array( $bp->groups->group_creation_steps ) )
Index: /trunk/src/bp-groups/bp-groups-cache.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-cache.php	(revision 9470)
+++ /trunk/src/bp-groups/bp-groups-cache.php	(revision 9471)
@@ -29,5 +29,5 @@
  */
 function bp_groups_update_meta_cache( $group_ids = false ) {
-	global $bp;
+	$bp = buddypress();
 
 	$cache_args = array(
Index: /trunk/src/bp-groups/bp-groups-classes.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-classes.php	(revision 9470)
+++ /trunk/src/bp-groups/bp-groups-classes.php	(revision 9471)
@@ -260,5 +260,7 @@
 	 */
 	public function save() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$this->creator_id   = apply_filters( 'groups_group_creator_id_before_save',   $this->creator_id,   $this->id );
@@ -356,5 +358,5 @@
 	 */
 	public function delete() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// Delete groupmeta for the group
@@ -374,4 +376,6 @@
 
 		wp_cache_delete( $this->id, 'bp_groups' );
+
+		$bp = buddypress();
 
 		// Finally remove the group entry from the DB
@@ -393,8 +397,8 @@
 	 */
 	public static function group_exists( $slug, $table_name = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $table_name ) )
-			$table_name = $bp->groups->table_name;
+			$table_name = buddypress()->groups->table_name;
 
 		if ( empty( $slug ) )
@@ -425,5 +429,8 @@
 	 */
 	public static function get_invites( $user_id, $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d and is_confirmed = 0 AND inviter_id = %d", $group_id, $user_id ) );
 	}
@@ -447,5 +454,5 @@
 	 */
 	public static function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
@@ -464,4 +471,6 @@
 		if ( empty( $gids['groups'] ) )
 			return false;
+
+		$bp = buddypress();
 
 		$gids = esc_sql( implode( ',', wp_parse_id_list( $gids['groups'] ) ) );
@@ -491,5 +500,5 @@
 	 */
 	public static function search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$search_terms_like = '%' . bp_esc_like( $filter ) . '%';
@@ -509,4 +518,6 @@
 			$hidden_sql = "AND status != 'hidden'";
 
+		$bp = buddypress();
+
 		$paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT id as group_id FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) {$hidden_sql} {$order_sql} {$pag_sql}", $search_terms_like, $search_terms_like ) );
 		$total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) {$hidden_sql}", $search_terms_like, $search_terms_like ) );
@@ -522,5 +533,7 @@
 	 */
 	public static function check_slug( $slug ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM {$bp->groups->table_name} WHERE slug = %s", $slug ) );
@@ -534,5 +547,7 @@
 	 */
 	public static function get_slug( $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM {$bp->groups->table_name} WHERE id = %d", $group_id ) );
@@ -546,5 +561,7 @@
 	 */
 	public static function has_members( $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$members = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
@@ -564,5 +581,7 @@
 	 */
 	public static function has_membership_requests( $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 0", $group_id ) );
@@ -584,9 +603,11 @@
 	 */
 	public static function get_membership_requests( $group_id, $limit = null, $page = null ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !empty( $limit ) && !empty( $page ) ) {
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 		}
+
+		$bp = buddypress();
 
 		$paged_requests = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 0 AND inviter_id = 0{$pag_sql}", $group_id ) );
@@ -648,5 +669,5 @@
 	 */
 	public static function get( $args = array() ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// Backward compatibility with old method of passing arguments
@@ -687,4 +708,6 @@
 
 		$r = wp_parse_args( $args, $defaults );
+
+		$bp = buddypress();
 
 		$sql       = array();
@@ -1013,5 +1036,5 @@
 	 */
 	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;
+		global $wpdb, $bbdb;
 
 		if ( empty( $bbdb ) )
@@ -1034,4 +1057,6 @@
 			$exclude_sql = " AND g.id NOT IN ({$exclude})";
 		}
+
+		$bp = buddypress();
 
 		if ( !empty( $user_id ) ) {
@@ -1077,5 +1102,5 @@
 	 */
 	public static function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) {
-		global $wpdb, $bp, $bbdb;
+		global $wpdb, $bbdb;
 
 		if ( empty( $bbdb ) )
@@ -1098,4 +1123,6 @@
 			$exclude_sql = " AND g.id NOT IN ({$exclude})";
 		}
+
+		$bp = buddypress();
 
 		if ( !empty( $user_id ) ) {
@@ -1138,5 +1165,5 @@
 	 */
 	public static function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true, $exclude = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$pag_sql = $hidden_sql = $exclude_sql = '';
@@ -1152,4 +1179,6 @@
 			}
 		}
+
+		$bp = buddypress();
 
 		if ( !empty( $exclude ) ) {
@@ -1206,5 +1235,5 @@
 	 */
 	public static function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$pag_sql = $hidden_sql = $search_sql = $exclude_sql = '';
@@ -1226,4 +1255,6 @@
 			$exclude_sql = " AND g.id NOT IN ({$exclude})";
 		}
+
+		$bp = buddypress();
 
 		if ( !empty( $user_id ) ) {
@@ -1264,8 +1295,10 @@
 	 */
 	public static function get_group_extras( &$paged_groups, &$group_ids, $type = false ) {
-		global $bp, $wpdb;
+		global $wpdb;
 
 		if ( empty( $group_ids ) )
 			return $paged_groups;
+
+		$bp = buddypress();
 
 		// Sanitize group IDs
@@ -1338,5 +1371,7 @@
 	 */
 	public static function delete_all_invites( $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d AND invite_sent = 1", $group_id ) );
@@ -1352,5 +1387,5 @@
 	 */
 	public static function get_total_group_count() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$hidden_sql = '';
@@ -1358,4 +1393,6 @@
 			$hidden_sql = "WHERE status != 'hidden'";
 
+		$bp = buddypress();
+
 		return $wpdb->get_var( "SELECT COUNT(id) FROM {$bp->groups->table_name} {$hidden_sql}" );
 	}
@@ -1369,5 +1406,7 @@
 	 */
 	public static function get_global_forum_topic_count( $type ) {
-		global $bbdb, $wpdb, $bp;
+		global $bbdb, $wpdb;
+
+		$bp = buddypress();
 
 		if ( 'unreplied' == $type )
@@ -1391,5 +1430,7 @@
 	 */
 	public static function get_total_member_count( $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		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 ) );
@@ -1406,5 +1447,5 @@
 	 */
 	public static function get_global_topic_count( $status = 'public', $search_terms = false ) {
-		global $bbdb, $wpdb, $bp;
+		global $bbdb, $wpdb;
 
 		switch ( $status ) {
@@ -1427,4 +1468,6 @@
 		}
 
+		$bp = buddypress();
+
 		$sql = array();
 
@@ -1452,6 +1495,7 @@
 	 */
 	public static function get_group_type_ids() {
-		global $wpdb, $bp;
-
+		global $wpdb;
+
+		$bp  = buddypress();
 		$ids = array();
 
@@ -1981,5 +2025,7 @@
 	 */
 	public function populate() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( $this->user_id && $this->group_id && !$this->id )
@@ -2015,5 +2061,7 @@
 	 */
 	public function save() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$this->user_id       = apply_filters( 'groups_member_user_id_before_save',       $this->user_id,       $this->id );
@@ -2145,6 +2193,7 @@
 	 */
 	public function remove() {
-		global $wpdb, $bp;
-
+		global $wpdb;
+
+		$bp  = buddypress();
 		$sql = $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
 
@@ -2195,6 +2244,7 @@
 	 */
 	public static function delete( $user_id, $group_id ) {
-		global $wpdb, $bp;
-
+		global $wpdb;
+
+		$bp = buddypress();
 		$remove = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
 
@@ -2222,9 +2272,11 @@
 	 */
 	public static function get_group_ids( $user_id, $limit = false, $page = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$pag_sql = '';
 		if ( !empty( $limit ) && !empty( $page ) )
 			$pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
+
+		$bp = buddypress();
 
 		// If the user is logged in and viewing their own groups, we can show hidden and private groups
@@ -2258,5 +2310,5 @@
 	 */
 	public static function get_recently_joined( $user_id, $limit = false, $page = false, $filter = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
@@ -2274,4 +2326,6 @@
 		if ( $user_id != bp_loggedin_user_id() )
 			$hidden_sql = " AND g.status != 'hidden'";
+
+		$bp = buddypress();
 
 		$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}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY m.date_modified DESC {$pag_sql}" );
@@ -2297,5 +2351,5 @@
 	 */
 	public static function get_is_admin_of( $user_id, $limit = false, $page = false, $filter = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
@@ -2313,4 +2367,6 @@
 		if ( $user_id != bp_loggedin_user_id() )
 			$hidden_sql = " AND g.status != 'hidden'";
+
+		$bp = buddypress();
 
 		$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}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY m.date_modified ASC {$pag_sql}" );
@@ -2336,5 +2392,5 @@
 	 */
 	public static function get_is_mod_of( $user_id, $limit = false, $page = false, $filter = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
@@ -2353,4 +2409,6 @@
 			$hidden_sql = " AND g.status != 'hidden'";
 
+		$bp = buddypress();
+
 		$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}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY m.date_modified ASC {$pag_sql}" );
 		$total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY date_modified ASC" );
@@ -2366,8 +2424,10 @@
 	 */
 	public static function total_group_count( $user_id = 0 ) {
-		global $bp, $wpdb;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			$user_id = bp_displayed_user_id();
+
+		$bp = buddypress();
 
 		if ( $user_id != bp_loggedin_user_id() && !bp_current_user_can( 'bp_moderate' ) ) {
@@ -2394,5 +2454,5 @@
 	 */
 	public static function get_invites( $user_id, $limit = false, $page = false, $exclude = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$pag_sql = ( !empty( $limit ) && !empty( $page ) ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
@@ -2404,4 +2464,6 @@
 			$exclude_sql = '';
 		}
+
+		$bp = buddypress();
 
 		$paged_groups = $wpdb->get_results( $wpdb->prepare( "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' AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d {$exclude_sql} ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
@@ -2444,9 +2506,10 @@
 	 */
 	public static function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
 
+		$bp  = buddypress();
 		$sql = "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0";
 
@@ -2465,8 +2528,10 @@
 	 */
 	public static function delete_invite( $user_id, $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1", $user_id, $group_id ) );
@@ -2481,8 +2546,10 @@
 	 */
 	public static function delete_request( $user_id, $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
+
+		$bp = buddypress();
 
  		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id = 0 AND invite_sent = 0", $user_id, $group_id ) );
@@ -2498,8 +2565,10 @@
 	 */
 	public static function check_is_admin( $user_id, $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_admin = 1 AND is_banned = 0", $user_id, $group_id ) );
@@ -2515,8 +2584,10 @@
 	 */
 	public static function check_is_mod( $user_id, $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_mod = 1 AND is_banned = 0", $user_id, $group_id ) );
@@ -2532,8 +2603,10 @@
 	 */
 	public static function check_is_member( $user_id, $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 1 AND is_banned = 0", $user_id, $group_id ) );
@@ -2549,8 +2622,10 @@
 	 */
 	public static function check_is_banned( $user_id, $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
@@ -2568,8 +2643,10 @@
 	 */
 	public static function check_is_creator( $user_id, $group_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
@@ -2584,8 +2661,10 @@
 	 */
 	public static function check_for_membership_request( $user_id, $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			return false;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND is_banned = 0 AND inviter_id = 0", $user_id, $group_id ) );
@@ -2600,5 +2679,7 @@
 	 */
 	public static function get_random_groups( $user_id = 0, $total_groups = 5 ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		// If the user is logged in and viewing their random groups, we can show hidden and private groups
@@ -2617,5 +2698,7 @@
 	 */
 	public static function get_group_member_ids( $group_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
@@ -2629,9 +2712,10 @@
 	 */
 	public static function get_group_administrator_ids( $group_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
 
 		$group_admins = wp_cache_get( $group_id, 'bp_group_admins' );
 
 		if ( false === $group_admins ) {
+			$bp = buddypress();
 			$group_admins = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_admin = 1 AND is_banned = 0", $group_id ) );
 
@@ -2649,5 +2733,7 @@
 	 */
 	public static function get_group_moderator_ids( $group_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_mod = 1 AND is_banned = 0", $group_id ) );
@@ -2661,5 +2747,7 @@
 	 */
 	public static function get_all_membership_request_user_ids( $group_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 0 AND inviter_id = 0", $group_id ) );
@@ -2672,5 +2760,5 @@
 	 */
 	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;
+		global $wpdb;
 
 		_deprecated_function( __METHOD__, '1.8', 'BP_Group_Member_Query' );
@@ -2693,4 +2781,6 @@
 			$exclude_sql = " AND m.user_id NOT IN ({$exclude})";
 		}
+
+		$bp = buddypress();
 
 		if ( bp_is_active( 'xprofile' ) ) {
@@ -2737,5 +2827,7 @@
 	 */
 	public static function delete_all( $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
@@ -2750,5 +2842,7 @@
 	 */
 	public static function delete_all_for_user( $user_id ) {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		// Get all the group ids for the current user's groups and update counts
Index: /trunk/src/bp-groups/bp-groups-filters.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-filters.php	(revision 9470)
+++ /trunk/src/bp-groups/bp-groups-filters.php	(revision 9471)
@@ -142,5 +142,5 @@
  */
 function groups_add_forum_tables_sql( $sql = '' ) {
-	global $bp;
+	$bp = buddypress();
 
 	$sql .= 'JOIN ' . $bp->groups->table_name . ' AS g LEFT JOIN ' . $bp->groups->table_name_groupmeta . ' AS gm ON g.id = gm.group_id ';
@@ -156,5 +156,4 @@
  */
 function groups_add_forum_where_sql( $sql = '' ) {
-	global $bp;
 
 	// Define locale variable
@@ -190,4 +189,6 @@
 	// Assemble Voltron
 	$parts_string = implode( ' AND ', $parts );
+
+	$bp = buddypress();
 
 	// Set it to the global filter
@@ -207,11 +208,15 @@
  */
 function groups_filter_bbpress_caps( $value, $cap, $args ) {
-	global $bp;
 
 	if ( bp_current_user_can( 'bp_moderate' ) )
 		return true;
 
-	if ( 'add_tag_to' == $cap )
-		if ( $bp->groups->current_group->user_has_access ) return true;
+	if ( 'add_tag_to' === $cap ) {
+		$bp = buddypress();
+
+		if ( $bp->groups->current_group->user_has_access ) {
+			return true;
+		}
+	}
 
 	if ( 'manage_forums' == $cap && is_user_logged_in() )
Index: /trunk/src/bp-groups/bp-groups-functions.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-functions.php	(revision 9470)
+++ /trunk/src/bp-groups/bp-groups-functions.php	(revision 9471)
@@ -21,9 +21,8 @@
  * @since BuddyPress (1.5.0)
  *
- * @global BuddyPress $bp The one true BuddyPress instance
  * @return bool True if set, False if empty
  */
 function bp_groups_has_directory() {
-	global $bp;
+	$bp = buddypress();
 
 	return (bool) !empty( $bp->pages->groups->id );
@@ -301,5 +300,5 @@
  */
 function groups_is_valid_status( $status ) {
-	global $bp;
+	$bp = buddypress();
 
 	return in_array( $status, (array) $bp->groups->valid_status );
@@ -313,5 +312,5 @@
  */
 function groups_check_slug( $slug ) {
-	global $bp;
+	$bp = buddypress();
 
 	if ( 'wp' == substr( $slug, 0, 2 ) )
@@ -365,5 +364,4 @@
  */
 function groups_leave_group( $group_id, $user_id = 0 ) {
-	global $bp;
 
 	if ( empty( $user_id ) )
@@ -399,5 +397,4 @@
  */
 function groups_join_group( $group_id, $user_id = 0 ) {
-	global $bp;
 
 	if ( empty( $user_id ) )
@@ -427,4 +424,6 @@
 	if ( !$new_member->save() )
 		return false;
+
+	$bp = buddypress();
 
 	if ( !isset( $bp->groups->current_group ) || !$bp->groups->current_group || $group_id != $bp->groups->current_group->id )
@@ -705,7 +704,9 @@
  */
 function groups_get_current_group() {
-	global $bp;
-
-	$current_group = isset( $bp->groups->current_group ) ? $bp->groups->current_group : false;
+	$bp = buddypress();
+
+	$current_group = isset( $bp->groups->current_group )
+		? $bp->groups->current_group
+		: false;
 
 	return apply_filters( 'groups_get_current_group', $current_group );
@@ -722,8 +723,8 @@
  */
 function groups_avatar_upload_dir( $group_id = 0 ) {
-	global $bp;
-
-	if ( !$group_id )
-		$group_id = $bp->groups->current_group->id;
+
+	if ( empty( $group_id ) ) {
+		$group_id = bp_get_current_group_id();
+	}
 
 	$path    = bp_core_avatar_upload_path() . '/group-avatars/' . $group_id;
@@ -810,5 +811,5 @@
  */
 function groups_post_update( $args = '' ) {
-	global $bp;
+	$bp = buddypress();
 
 	$defaults = array(
Index: /trunk/src/bp-groups/bp-groups-screens.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-screens.php	(revision 9470)
+++ /trunk/src/bp-groups/bp-groups-screens.php	(revision 9471)
@@ -510,5 +510,4 @@
  */
 function groups_screen_group_request_membership() {
-	global $bp;
 
 	if ( !is_user_logged_in() )
@@ -912,5 +911,4 @@
  */
 function groups_screen_group_admin_delete_group() {
-	global $bp;
 
 	if ( 'delete-group' != bp_get_group_current_admin_tab() )
@@ -919,4 +917,6 @@
 	if ( ! bp_is_item_admin() && !bp_current_user_can( 'bp_moderate' ) )
 		return false;
+
+	$bp = buddypress();
 
 	if ( isset( $_REQUEST['delete-group-button'] ) && isset( $_REQUEST['delete-group-understand'] ) ) {
Index: /trunk/src/bp-groups/bp-groups-template.php
===================================================================
--- /trunk/src/bp-groups/bp-groups-template.php	(revision 9470)
+++ /trunk/src/bp-groups/bp-groups-template.php	(revision 9471)
@@ -1500,5 +1500,4 @@
  */
 function bp_group_search_form() {
-	global $bp;
 
 	$action = bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/search/';
@@ -1597,7 +1596,5 @@
  */
 function bp_groups_auto_join() {
-	global $bp;
-
-	return apply_filters( 'bp_groups_auto_join', (bool)$bp->groups->auto_join );
+	return apply_filters( 'bp_groups_auto_join', (bool) buddypress()->groups->auto_join );
 }
 
@@ -1861,7 +1858,9 @@
  */
 function bp_group_get_invite_status( $group_id = false ) {
-	global $bp, $groups_template;
+	global $groups_template;
 
 	if ( !$group_id ) {
+		$bp = buddypress();
+
 		if ( isset( $bp->groups->current_group->id ) ) {
 			// Default to the current group first
@@ -2558,8 +2557,10 @@
 	 */
 	function bp_get_group_accept_invite_link( $group = false ) {
-		global $groups_template, $bp;
+		global $groups_template;
 
 		if ( empty( $group ) )
 			$group =& $groups_template->group;
+
+		$bp = buddypress();
 
 		return apply_filters( 'bp_get_group_accept_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/accept/' . $group->id ), 'groups_accept_invite' ) );
@@ -2580,8 +2581,10 @@
 	 */
 	function bp_get_group_reject_invite_link( $group = false ) {
-		global $groups_template, $bp;
+		global $groups_template;
 
 		if ( empty( $group ) )
 			$group =& $groups_template->group;
+
+		$bp = buddypress();
 
 		return apply_filters( 'bp_get_group_reject_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/reject/' . $group->id ), 'groups_reject_invite' ) );
@@ -3623,5 +3626,5 @@
 
 function bp_group_creation_tabs() {
-	global $bp;
+	$bp = buddypress();
 
 	if ( !is_array( $bp->groups->group_creation_steps ) )
@@ -3648,5 +3651,5 @@
 
 function bp_group_creation_stage_title() {
-	global $bp;
+	$bp = buddypress();
 
 	echo apply_filters( 'bp_group_creation_stage_title', '<span>&mdash; ' . $bp->groups->group_creation_steps[bp_get_groups_current_create_step()]['name'] . '</span>' );
@@ -3657,5 +3660,5 @@
 }
 	function bp_get_group_creation_form_action() {
-		global $bp;
+		$bp = buddypress();
 
 		if ( !bp_action_variable( 1 ) ) {
@@ -3668,9 +3671,10 @@
 
 function bp_is_group_creation_step( $step_slug ) {
-	global $bp;
 
 	/* Make sure we are in the groups component */
 	if ( !bp_is_groups_component() || !bp_is_current_action( 'create' ) )
 		return false;
+
+	$bp = buddypress();
 
 	/* If this the first step, we can just accept and return true */
@@ -3693,5 +3697,5 @@
 
 function bp_is_group_creation_step_complete( $step_slugs ) {
-	global $bp;
+	$bp = buddypress();
 
 	if ( !isset( $bp->groups->completed_create_steps ) )
@@ -3715,5 +3719,5 @@
 
 function bp_are_previous_group_creation_steps_complete( $step_slug ) {
-	global $bp;
+	$bp = buddypress();
 
 	/* If this is the first group creation step, return true */
@@ -3740,5 +3744,5 @@
 }
 	function bp_get_new_group_id() {
-		global $bp;
+		$bp = buddypress();
 
 		if ( isset( $bp->groups->new_group_id ) )
@@ -3754,5 +3758,5 @@
 }
 	function bp_get_new_group_name() {
-		global $bp;
+		$bp = buddypress();
 
 		if ( isset( $bp->groups->current_group->name ) )
@@ -3768,5 +3772,5 @@
 }
 	function bp_get_new_group_description() {
-		global $bp;
+		$bp = buddypress();
 
 		if ( isset( $bp->groups->current_group->description ) )
@@ -3782,5 +3786,6 @@
 }
 	function bp_get_new_group_enable_forum() {
-		global $bp;
+		$bp = buddypress();
+
 		return (int) apply_filters( 'bp_get_new_group_enable_forum', $bp->groups->current_group->enable_forum );
 	}
@@ -3790,5 +3795,6 @@
 }
 	function bp_get_new_group_status() {
-		global $bp;
+		$bp = buddypress();
+
 		return apply_filters( 'bp_get_new_group_status', $bp->groups->current_group->status );
 	}
@@ -3798,5 +3804,5 @@
 }
 	function bp_get_new_group_avatar( $args = '' ) {
-		global $bp;
+		$bp = buddypress();
 
 		$defaults = array(
@@ -3820,5 +3826,5 @@
 }
 	function bp_get_group_creation_previous_link() {
-		global $bp;
+		$bp = buddypress();
 
 		foreach ( (array) $bp->groups->group_creation_steps as $slug => $name ) {
@@ -3849,5 +3855,5 @@
 	 */
 	function bp_get_groups_current_create_step() {
-		global $bp;
+		$bp = buddypress();
 
 		if ( !empty( $bp->groups->current_create_step ) ) {
@@ -3861,5 +3867,5 @@
 
 function bp_is_last_group_creation_step() {
-	global $bp;
+	$bp = buddypress();
 
 	$keys      = array_keys( $bp->groups->group_creation_steps );
@@ -3873,5 +3879,5 @@
 
 function bp_is_first_group_creation_step() {
-	global $bp;
+	$bp = buddypress();
 
 	$keys       = array_keys( $bp->groups->group_creation_steps );
@@ -3888,5 +3894,5 @@
 }
 	function bp_get_new_group_invite_friend_list( $args = '' ) {
-		global $bp;
+		$bp = buddypress();
 
 		if ( !bp_is_active( 'friends' ) )
@@ -3945,5 +3951,5 @@
  */
 function bp_groups_header_tabs() {
-	global $bp;?>
+	$bp = buddypress(); ?>
 
 	<li<?php if ( !bp_action_variable( 0 ) || bp_is_action_variable( 'recently-active', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/recently-active' ) ?>"><?php _e( 'Recently Active', 'buddypress' ) ?></a></li>
@@ -4095,5 +4101,5 @@
 }
 	function bp_get_group_avatar_delete_link() {
-		global $bp;
+		$bp = buddypress();
 
 		return apply_filters( 'bp_get_group_avatar_delete_link', wp_nonce_url( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/group-avatar/delete', 'bp_group_avatar_delete' ) );
Index: /trunk/src/bp-members/bp-members-adminbar.php
===================================================================
--- /trunk/src/bp-members/bp-members-adminbar.php	(revision 9470)
+++ /trunk/src/bp-members/bp-members-adminbar.php	(revision 9471)
@@ -21,5 +21,5 @@
  */
 function bp_members_admin_bar_my_account_menu() {
-	global $bp, $wp_admin_bar;
+	global $wp_admin_bar;
 
 	// Bail if this is an ajax request
@@ -29,4 +29,6 @@
 	// Logged in user
 	if ( is_user_logged_in() ) {
+
+		$bp = buddypress();
 
 		// Stored in the global so we can add menus easily later on
@@ -73,5 +75,5 @@
  */
 function bp_members_admin_bar_user_admin_menu() {
-	global $bp, $wp_admin_bar;
+	global $wp_admin_bar;
 
 	// Only show if viewing a user
@@ -82,4 +84,6 @@
 	if ( !current_user_can( 'edit_users' ) || bp_is_my_profile() )
 		return false;
+
+	$bp = buddypress();
 
 	// Unique ID for the 'My Account' menu
Index: /trunk/src/bp-members/bp-members-functions.php
===================================================================
--- /trunk/src/bp-members/bp-members-functions.php	(revision 9470)
+++ /trunk/src/bp-members/bp-members-functions.php	(revision 9471)
@@ -21,5 +21,5 @@
  */
 function bp_members_has_directory() {
-	global $bp;
+	$bp = buddypress();
 
 	return (bool) !empty( $bp->pages->members->id );
Index: /trunk/src/bp-members/bp-members-screens.php
===================================================================
--- /trunk/src/bp-members/bp-members-screens.php	(revision 9470)
+++ /trunk/src/bp-members/bp-members-screens.php	(revision 9471)
@@ -65,5 +65,5 @@
  */
 function bp_core_screen_signup() {
-	global $bp;
+	$bp = buddypress();
 
 	if ( ! bp_is_current_component( 'register' ) || bp_current_action() )
Index: /trunk/src/bp-members/bp-members-template.php
===================================================================
--- /trunk/src/bp-members/bp-members-template.php	(revision 9470)
+++ /trunk/src/bp-members/bp-members-template.php	(revision 9471)
@@ -1298,5 +1298,5 @@
  */
 function bp_get_loggedin_user_nav() {
-	global $bp;
+	$bp = buddypress();
 
 	// Loop through each navigation item
@@ -1340,5 +1340,5 @@
  */
 function bp_get_displayed_user_nav() {
-	global $bp;
+	$bp = buddypress();
 
 	foreach ( (array) $bp->bp_nav as $user_nav_item ) {
@@ -1484,5 +1484,5 @@
 	 */
 	function bp_get_displayed_user_email() {
-		global $bp;
+		$bp = buddypress();
 
 		// If displayed user exists, return email address
@@ -1646,5 +1646,5 @@
  */
 function bp_displayed_user_domain() {
-	global $bp;
+	$bp = buddypress();
 
 	/**
@@ -1664,5 +1664,5 @@
  */
 function bp_loggedin_user_domain() {
-	global $bp;
+	$bp = buddypress();
 
 	/**
@@ -1688,5 +1688,5 @@
 	 */
 	function bp_get_displayed_user_fullname() {
-		global $bp;
+		$bp = buddypress();
 
 		/**
@@ -1718,5 +1718,5 @@
 	 */
 	function bp_get_loggedin_user_fullname() {
-		global $bp;
+		$bp = buddypress();
 
 		/**
@@ -1742,5 +1742,5 @@
 	 */
 	function bp_get_displayed_user_username() {
-		global $bp;
+		$bp = buddypress();
 
 		if ( bp_displayed_user_id() ) {
@@ -1772,5 +1772,5 @@
 	 */
 	function bp_get_loggedin_user_username() {
-		global $bp;
+		$bp = buddypress();
 
 		if ( bp_loggedin_user_id() ) {
@@ -2096,5 +2096,5 @@
 	 */
 	function bp_get_signup_avatar_dir_value() {
-		global $bp;
+		$bp = buddypress();
 
 		// Check if signup_avatar_dir is passed
@@ -2132,7 +2132,5 @@
 	 */
 	function bp_get_current_signup_step() {
-		global $bp;
-
-		return $bp->signup->step;
+		return buddypress()->signup->step;
 	}
 
@@ -2303,9 +2301,10 @@
 	 */
 	function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
-		global $bp;
 
 		// Must be displayed user
 		if ( !bp_displayed_user_id() )
 			return;
+
+		$bp = buddypress();
 
 		// Append $action to $url if there is no $type
Index: /trunk/src/bp-messages/bp-messages-classes.php
===================================================================
--- /trunk/src/bp-messages/bp-messages-classes.php	(revision 9470)
+++ /trunk/src/bp-messages/bp-messages-classes.php	(revision 9471)
@@ -135,5 +135,5 @@
 	 */
 	public function populate( $thread_id = 0, $order = 'ASC', $args = array() ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if( 'ASC' != $order && 'DESC' != $order ) {
@@ -149,4 +149,6 @@
 		$this->thread_id      = $thread_id;
 
+		$bp = buddypress();
+
 		if ( !$this->messages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE thread_id = %d ORDER BY date_sent " . $order, $this->thread_id ) ) ) {
 			return false;
@@ -210,5 +212,7 @@
 	 */
 	public function get_recipients() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$recipients = array();
@@ -244,5 +248,5 @@
 	 */
 	public static function delete( $thread_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		/**
@@ -254,4 +258,6 @@
 		 */
 		do_action( 'bp_messages_thread_before_mark_delete', $thread_id );
+
+		$bp = buddypress();
 
 		// Mark messages as deleted
@@ -335,5 +341,5 @@
 	 */
 	public static function get_current_threads_for_user( $args = array() ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// Backward compatibility with old method of passing arguments
@@ -405,4 +411,6 @@
 		}
 
+		$bp = buddypress();
+
 		// set up SQL array
 		$sql = array();
@@ -491,6 +499,7 @@
 	 */
 	public static function mark_as_read( $thread_id ) {
-		global $wpdb, $bp;
-
+		global $wpdb;
+
+		$bp  = buddypress();
 		$sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id );
 		$wpdb->query($sql);
@@ -507,6 +516,7 @@
 	 */
 	public static function mark_as_unread( $thread_id ) {
-		global $wpdb, $bp;
-
+		global $wpdb;
+
+		$bp  = buddypress();
 		$sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id );
 		$wpdb->query($sql);
@@ -528,5 +538,5 @@
 	 */
 	public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$exclude_sender = '';
@@ -539,4 +549,6 @@
 			$type_sql = " AND unread_count = 0 ";
 
+		$bp = buddypress();
+
 		return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(thread_id) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0{$exclude_sender} {$type_sql}", $user_id ) );
 	}
@@ -551,5 +563,7 @@
 	 */
 	public static function user_is_sender( $thread_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$sender_ids = $wpdb->get_col( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
@@ -571,5 +585,7 @@
 	 */
 	public static function get_last_sender( $thread_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( ! $sender_id = $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d GROUP BY sender_id ORDER BY date_sent LIMIT 1", $thread_id ) ) ) {
@@ -589,5 +605,5 @@
 	 */
 	public static function get_inbox_count( $user_id = 0 ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) ) {
@@ -598,4 +614,6 @@
 
 		if ( false === $unread_count ) {
+			$bp = buddypress();
+
 			$unread_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM(unread_count) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0 AND sender_only = 0", $user_id ) );
 
@@ -624,8 +642,10 @@
 	 */
 	public static function check_access( $thread_id, $user_id = 0 ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_id ) )
 			$user_id = bp_loggedin_user_id();
+
+		$bp = buddypress();
 
 		return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0 AND user_id = %d", $thread_id, $user_id ) );
@@ -694,5 +714,5 @@
 	 */
 	public static function update_tables() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$bp_prefix = bp_core_get_table_prefix();
@@ -704,4 +724,6 @@
 			return true;
 		}
+
+		$bp = buddypress();
 
 		foreach( (array) $threads as $thread ) {
@@ -798,5 +820,7 @@
 	 */
 	public function populate( $id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( $message = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE id = %d", $id ) ) ) {
@@ -817,5 +841,7 @@
 	 */
 	public function send() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$this->sender_id = apply_filters( 'messages_message_sender_id_before_save', $this->sender_id, $this->id );
@@ -891,5 +917,8 @@
 	 */
 	public function get_recipients() {
-		global $bp, $wpdb;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) );
 	}
@@ -925,5 +954,8 @@
 	 */
 	public static function get_last_sent_for_user( $thread_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ) );
 	}
@@ -938,5 +970,8 @@
 	 */
 	public static function is_user_sender( $user_id, $message_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND id = %d", $user_id, $message_id ) );
 	}
@@ -949,5 +984,8 @@
 	 */
 	public static function get_message_sender( $message_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		return $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE id = %d", $message_id ) );
 	}
@@ -1018,5 +1056,7 @@
 	 */
 	public function populate() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$notice = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id ) );
@@ -1038,5 +1078,7 @@
 	 */
 	public function save() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$this->subject = apply_filters( 'messages_notice_subject_before_save', $this->subject, $this->id );
@@ -1117,5 +1159,5 @@
 	 */
 	public function delete() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		/**
@@ -1128,4 +1170,5 @@
 		do_action( 'messages_notice_before_delete', $this );
 
+		$bp  = buddypress();
 		$sql = $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_notices} WHERE id = %d", $this->id );
 
@@ -1154,5 +1197,5 @@
 	 */
 	public static function get_notices( $args = array() ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$r = wp_parse_args( $args, array(
@@ -1166,4 +1209,6 @@
 		}
 
+		$bp = buddypress();
+
 		$notices = $wpdb->get_results( "SELECT * FROM {$bp->messages->table_name_notices} ORDER BY date_sent DESC {$limit_sql}" );
 
@@ -1179,7 +1224,9 @@
 	 */
 	public static function get_total_notice_count() {
-		global $wpdb, $bp;
-
-		$notice_count = $wpdb->get_var( "SELECT COUNT(id) FROM " . $bp->messages->table_name_notices );
+		global $wpdb;
+
+		$bp = buddypress();
+
+		$notice_count = $wpdb->get_var( "SELECT COUNT(id) FROM {$bp->messages->table_name_notices}" );
 
 		return $notice_count;
@@ -1197,5 +1244,7 @@
 
 		if ( false === $notice ) {
-			global $wpdb, $bp;
+			global $wpdb;
+
+			$bp = buddypress();
 
 			$notice_id = $wpdb->get_var( "SELECT id FROM {$bp->messages->table_name_notices} WHERE is_active = 1" );
Index: /trunk/src/bp-xprofile/bp-xprofile-admin.php
===================================================================
--- /trunk/src/bp-xprofile/bp-xprofile-admin.php	(revision 9470)
+++ /trunk/src/bp-xprofile/bp-xprofile-admin.php	(revision 9471)
@@ -262,5 +262,7 @@
  */
 function xprofile_admin_manage_field( $group_id, $field_id = null ) {
-	global $bp, $wpdb, $message, $groups;
+	global $wpdb, $message, $groups;
+
+	$bp = buddypress();
 
 	$field           = new BP_XProfile_Field( $field_id );
Index: /trunk/src/bp-xprofile/bp-xprofile-classes.php
===================================================================
--- /trunk/src/bp-xprofile/bp-xprofile-classes.php	(revision 9470)
+++ /trunk/src/bp-xprofile/bp-xprofile-classes.php	(revision 9471)
@@ -25,9 +25,10 @@
 
 	public function populate( $id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$group = wp_cache_get( 'xprofile_group_' . $this->id, 'bp' );
 
 		if ( false === $group ) {
+			$bp = buddypress();
 			$group = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id ) );
 		}
@@ -45,5 +46,5 @@
 
 	public function save() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$this->name        = apply_filters( 'xprofile_group_name_before_save',        $this->name,        $this->id );
@@ -60,4 +61,6 @@
 		 */
 		do_action_ref_array( 'xprofile_group_before_save', array( &$this ) );
+
+		$bp = buddypress();
 
 		if ( $this->id )
@@ -86,5 +89,5 @@
 
 	public function delete() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $this->can_delete ) )
@@ -99,4 +102,6 @@
 		 */
 		do_action_ref_array( 'xprofile_group_before_delete', array( &$this ) );
+
+		$bp = buddypress();
 
 		// Delete field group
@@ -163,5 +168,5 @@
 	 */
 	public static function get( $args = array() ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$defaults = array(
@@ -197,4 +202,6 @@
 		}
 
+		$bp = buddypress();
+
 		if ( ! empty( $hide_empty_groups ) ) {
 			$group_ids = $wpdb->get_col( "SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC" );
@@ -416,5 +423,5 @@
 
 	public static function update_position( $field_group_id, $position ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !is_numeric( $position ) ) {
@@ -424,4 +431,6 @@
 		// purge profile field group cache
 		wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) );
@@ -481,9 +490,11 @@
 	 */
 	public static function fetch_default_visibility_levels() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$default_visibility_levels = wp_cache_get( 'xprofile_default_visibility_levels', 'bp' );
 
 		if ( false === $default_visibility_levels ) {
+			$bp = buddypress();
+
 			$levels = $wpdb->get_results( "SELECT object_id, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND ( meta_key = 'default_visibility' OR meta_key = 'allow_custom_visibility' )" );
 
@@ -658,5 +669,5 @@
 
 	public function populate( $id, $user_id, $get_data ) {
-		global $wpdb, $userdata, $bp;
+		global $wpdb, $userdata;
 
 		if ( empty( $user_id ) ) {
@@ -664,4 +675,5 @@
 		}
 
+		$bp  = buddypress();
 		$sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id );
 
@@ -699,5 +711,5 @@
 
 	public function delete( $delete_data = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// Prevent deletion if no ID is present
@@ -707,4 +719,6 @@
 			return false;
 
+		$bp = buddypress();
+
 		if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) )
 			return false;
@@ -718,5 +732,7 @@
 
 	public function save() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$this->group_id    = apply_filters( 'xprofile_field_group_id_before_save',    $this->group_id,    $this->id );
@@ -857,5 +873,5 @@
 
 	public function get_children( $for_editing = false ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// This is done here so we don't have problems with sql injection
@@ -875,4 +891,5 @@
 		}
 
+		$bp  = buddypress();
 		$sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id );
 
@@ -891,6 +908,7 @@
 
 	public function delete_children() {
-		global $wpdb, $bp;
-
+		global $wpdb;
+
+		$bp  = buddypress();
 		$sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE parent_id = %d", $this->id );
 
@@ -901,7 +919,8 @@
 
 	public static function get_type( $field_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !empty( $field_id ) ) {
+			$bp  = buddypress();
 			$sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id );
 
@@ -917,7 +936,8 @@
 
 	public static function delete_for_group( $group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !empty( $group_id ) ) {
+			$bp  = buddypress();
 			$sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id );
 
@@ -933,5 +953,7 @@
 
 	public static function get_id_from_name( $field_name ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( empty( $bp->profile->table_name_fields ) || !isset( $field_name ) )
@@ -942,8 +964,10 @@
 
 	public static function update_position( $field_id, $position, $field_group_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( !is_numeric( $position ) || !is_numeric( $field_group_id ) )
 			return false;
+
+		$bp = buddypress();
 
 		// Update $field_id with new $position and $field_group_id
@@ -1221,5 +1245,5 @@
 
 	public function populate( $field_id, $user_id )  {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$cache_key   = "{$user_id}:{$field_id}";
@@ -1227,4 +1251,6 @@
 
 		if ( false === $profiledata ) {
+			$bp = buddypress();
+
 			$sql         = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );
 			$profiledata = $wpdb->get_row( $sql );
@@ -1257,5 +1283,5 @@
 	 */
 	public function exists() {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		// Check cache first
@@ -1266,4 +1292,5 @@
 			$retval = true;
 		} else {
+			$bp = buddypress();
 			$retval = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $this->user_id, $this->field_id ) );
 		}
@@ -1284,9 +1311,10 @@
 	 *
 	 * @global object $wpdb
-	 * @global array $bp
 	 * @return bool
 	 */
 	public function is_valid_field() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$retval = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id ) );
@@ -1304,5 +1332,7 @@
 
 	public function save() {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$this->user_id      = apply_filters( 'xprofile_data_user_id_before_save',      $this->user_id,         $this->id );
@@ -1509,9 +1539,10 @@
 	 */
 	public static function get_fielddataid_byid( $field_id, $user_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $field_id ) || empty( $user_id ) ) {
 			$fielddata_id = 0;
 		} else {
+			$bp = buddypress();
 
 			// Check cache first
@@ -1539,5 +1570,5 @@
 	 */
 	public static function get_value_byid( $field_id, $user_ids = null ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		if ( empty( $user_ids ) ) {
@@ -1562,4 +1593,5 @@
 		// Prime caches
 		if ( ! empty( $uncached_ids ) ) {
+			$bp = buddypress();
 			$uncached_ids_sql = implode( ',', $uncached_ids );
 			$queried_data = $wpdb->get_results( $wpdb->prepare( "SELECT id, user_id, field_id, value, last_updated FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id IN ({$uncached_ids_sql})", $field_id ) );
@@ -1610,8 +1642,10 @@
 
 	public static function get_value_byfieldname( $fields, $user_id = null ) {
-		global $bp, $wpdb;
+		global $wpdb;
 
 		if ( empty( $fields ) )
 			return false;
+
+		$bp = buddypress();
 
 		if ( empty( $user_id ) )
@@ -1659,5 +1693,7 @@
 
 	public static function delete_for_field( $field_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) )
@@ -1668,5 +1704,7 @@
 
 	public static function get_last_updated( $user_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		$last_updated = $wpdb->get_var( $wpdb->prepare( "SELECT last_updated FROM {$bp->profile->table_name_data} WHERE user_id = %d ORDER BY last_updated LIMIT 1", $user_id ) );
@@ -1676,5 +1714,7 @@
 
 	public static function delete_data_for_user( $user_id ) {
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 
 		return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) );
@@ -1682,7 +1722,9 @@
 
 	public static function get_random( $user_id, $exclude_fullname ) {
-		global $wpdb, $bp;
+		global $wpdb;
 
 		$exclude_sql = ! empty( $exclude_fullname ) ? ' AND pf.id != 1' : '';
+
+		$bp = buddypress();
 
 		return $wpdb->get_results( $wpdb->prepare( "SELECT pf.type, pf.name, pd.value FROM {$bp->profile->table_name_data} pd INNER JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id AND pd.user_id = %d {$exclude_sql} ORDER BY RAND() LIMIT 1", $user_id ) );
Index: /trunk/src/bp-xprofile/bp-xprofile-functions.php
===================================================================
--- /trunk/src/bp-xprofile/bp-xprofile-functions.php	(revision 9470)
+++ /trunk/src/bp-xprofile/bp-xprofile-functions.php	(revision 9471)
@@ -218,5 +218,4 @@
  */
 function xprofile_insert_field( $args = '' ) {
-	global $bp;
 
 	$r = wp_parse_args( $args, array(
@@ -240,5 +239,5 @@
 
 	// Check this is a valid field type
-	if ( ! in_array( $r['type'], (array) $bp->profile->field_types ) ) {
+	if ( ! in_array( $r['type'], (array) buddypress()->profile->field_types ) ) {
 		return false;
 	}
@@ -1022,5 +1021,4 @@
  */
 function bp_xprofile_get_visibility_levels() {
-	global $bp;
 
 	/**
@@ -1031,5 +1029,5 @@
 	 * @param array $visibility_levels Array of visibility levels.
 	 */
-	return apply_filters( 'bp_xprofile_get_visibility_levels', $bp->profile->visibility_levels );
+	return apply_filters( 'bp_xprofile_get_visibility_levels', buddypress()->profile->visibility_levels );
 }
 
Index: /trunk/src/bp-xprofile/bp-xprofile-template.php
===================================================================
--- /trunk/src/bp-xprofile/bp-xprofile-template.php	(revision 9470)
+++ /trunk/src/bp-xprofile/bp-xprofile-template.php	(revision 9471)
@@ -370,5 +370,7 @@
 }
 	function bp_get_the_profile_group_edit_form_action() {
-		global $bp, $group;
+		global $group;
+
+		$bp = buddypress();
 
 		/**
@@ -845,6 +847,7 @@
  */
 function bp_profile_group_tabs() {
-	global $bp, $group_name;
-
+	global $group_name;
+
+	$bp     = buddypress();
 	$groups = bp_profile_get_field_groups();
 
@@ -967,5 +970,5 @@
 }
 	function bp_get_avatar_delete_link() {
-		global $bp;
+		$bp = buddypress();
 
 		/**
@@ -980,5 +983,5 @@
 
 function bp_edit_profile_button() {
-	global $bp;
+	$bp = buddypress();
 
 	bp_button( array (
Index: /trunk/tests/phpunit/includes/testcase.php
===================================================================
--- /trunk/tests/phpunit/includes/testcase.php	(revision 9470)
+++ /trunk/tests/phpunit/includes/testcase.php	(revision 9471)
@@ -328,9 +328,8 @@
 	 * user during tests. BP caches the current user differently, so we
 	 * have to do a bit more work to change it
-	 *
-	 * @global BuddyPres $bp
 	 */
 	public static function set_current_user( $user_id ) {
-		global $bp;
+		$bp = buddypress();
+
 		$bp->loggedin_user->id = $user_id;
 		$bp->loggedin_user->fullname       = bp_core_get_user_displayname( $user_id );
Index: /trunk/tests/phpunit/testcases/activity/template.php
===================================================================
--- /trunk/tests/phpunit/testcases/activity/template.php	(revision 9470)
+++ /trunk/tests/phpunit/testcases/activity/template.php	(revision 9471)
@@ -22,5 +22,5 @@
 	 */
 	public function test_user_can_delete() {
-		global $bp;
+		$bp = buddypress();
 
 		$a = $this->factory->activity->create( array(
@@ -134,6 +134,4 @@
 			'action' => 'activity_update',
 		) );
-
-		global $wpdb, $bp;
 
 		$ids = wp_list_pluck( $activities_template->activities, 'id' );
Index: /trunk/tests/phpunit/testcases/core/cache.php
===================================================================
--- /trunk/tests/phpunit/testcases/core/cache.php	(revision 9470)
+++ /trunk/tests/phpunit/testcases/core/cache.php	(revision 9471)
@@ -14,5 +14,8 @@
 
 		// Confirm that all activitymeta is deleted
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
+
 		$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $a1 ) );
 
Index: /trunk/tests/phpunit/testcases/groups/functions.php
===================================================================
--- /trunk/tests/phpunit/testcases/groups/functions.php	(revision 9470)
+++ /trunk/tests/phpunit/testcases/groups/functions.php	(revision 9471)
@@ -442,5 +442,7 @@
 
 		// Get rid of any auto-created values
-		global $wpdb, $bp;
+		global $wpdb;
+
+		$bp = buddypress();
 		$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_groupmeta} WHERE group_id = %d", $g ) );
 		wp_cache_delete( $g, 'group_meta' );
Index: /trunk/tests/phpunit/testcases/members/functions.php
===================================================================
--- /trunk/tests/phpunit/testcases/members/functions.php	(revision 9470)
+++ /trunk/tests/phpunit/testcases/members/functions.php	(revision 9471)
@@ -172,6 +172,7 @@
 	 */
 	public function test_bp_core_get_user_displayname_xprofile_does_not_exist() {
+		$bp = buddypress();
 		$xprofile_is_active = bp_is_active( 'xprofile' );
-		buddypress()->active_components['xprofile'] = '1';
+		$bp->active_components['xprofile'] = '1';
 
 		$u = $this->factory->user->create( array(
@@ -181,5 +182,5 @@
 		// Delete directly because BP won't let you delete a required
 		// field through the API
-		global $wpdb, $bp;
+		global $wpdb;
 		$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = 1", $u ) );
 		wp_cache_delete( 'bp_user_fullname_' . $u, 'bp' );
@@ -191,5 +192,5 @@
 
 		if ( ! $xprofile_is_active ) {
-			unset( buddypress()->active_components['xprofile'] );
+			unset( $bp->active_components['xprofile'] );
 		}
 	}
@@ -233,5 +234,6 @@
 		// Delete directly because BP won't let you delete a required
 		// field through the API
-		global $wpdb, $bp;
+		global $wpdb;
+		$bp = buddypress();
 		$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = 1", $u2 ) );
 		wp_cache_delete( 'bp_user_fullname_' . $u2, 'bp' );
@@ -378,5 +380,6 @@
 
 		// Create an existing entry in last_activity to test no dupes
-		global $wpdb, $bp;
+		global $wpdb;
+		$bp = buddypress();
 		$wpdb->query( $wpdb->prepare(
 			"INSERT INTO {$bp->members->table_name_last_activity}
