Accessing user metadata in BP 1.3
BuddyPress plugin authors updating their plugins for BuddyPress 1.3 will want to be aware of some recent changes to the way that user metadata is stored and accessed throughout BuddyPress.
Usermeta has been one of the final issues standing in the way of running separate BuddyPress instances on a single WordPress network. BP stores a variety of user metadata in WP’s global usermeta table, but multi-BP would require this usermeta to be stored separately for each BP instance. The solution, implemented in r4372 and r4378, is to introduce a wrapper function
bp_get_user_meta_key(), which allows user meta keys to be filtered by plugins. See #2952 for more information.
What this means for you: BP user metadata remains unchanged, and your plugins that depend on this metadata will continue to work as expected in BP 1.3. However, in order for your plugin to be compatible with multi-BP, you will have to use
bp_get_user_meta_key() whenever you fetch or store usermeta data. For example, let’s say you have a Favorite Groups plugin, and a function that stores a user’s favorite groups in a usermeta called ‘bp_favorite_groups’. Your _user_meta() calls should look like this:
$favorites = get_user_meta( $user_id, bp_get_user_meta_key( 'bp_favorite_groups' ), true );
$favorites = $new_favorite;
update_user_meta( $user_id, bp_get_user_meta_key( 'bp_favorite_groups' ), $favorites );
Still have questions? Have a look at the inline docs, or leave a comment here.