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.
John James Jacoby 11:42 pm on May 16, 2011 Permalink |
Solid.
Sarah Gooding 1:37 am on May 17, 2011 Permalink |
This is very exciting! Quick question – will multi-BP be available in the future with a plugin or will it be something that can be enabled via wp-config file or something similar?
Boone B. Gorges 12:36 pm on May 17, 2011 Permalink |
At the moment, there are no plans (or patches) to make this a core feature of BP. But it’s getting close to the point where a plugin would pretty easily be able to make it happen. See wpmuguru’s proposed plugin from #2952, for instance: http://buddypress.trac.wordpress.org/attachment/ticket/2952/bp-multi-network.php (This plugin won’t work as it stands, but it suggests how such a thing would be done.)
A-Sun 12:15 pm on May 25, 2011 Permalink |
agreed Sarah! Thanks Boone!
Ron 4:02 pm on May 17, 2011 Permalink |
I’ll see if I can touch up & release the rest of the bp-multi-network plugin in the next week.
slaFFik 4:33 pm on May 17, 2011 Permalink |
That would be awesome, Ron.
Ron 5:51 pm on May 19, 2011 Permalink |
We had to do a bit more to BP: http://buddypress.trac.wordpress.org/ticket/3228
I’ll see if I can get something up for people to test with over the next couple days.
Ron 7:09 pm on May 19, 2011 Permalink |
The plugin with brief instructions is available here: http://wpmututorials.com/news/new-features/multiple-buddypress-social-networks/
Новости: BuddyPress 1.3, BP Multi-Network, bbPress 2.0 | Русский BuddyPress и WordPress MS, плагины, шаблоны, хаки 4:46 pm on May 23, 2011 Permalink |
[...] Также разработчикам надо прочитать вот эту запись (на английском) - Доступ к данным пользователя в BP 1.3. [...]
L’Hebdo WordPress : bbPress – Buddypress – WordCamp | Choisir-son-CMS.tk 4:13 pm on May 24, 2011 Permalink |
[...] BuddyPress arrive en version 1.3 avec son lot de nouveautés. Explication. [...]
Better metadata wrappers in BP 1.3 « BuddyPress Development Updates 7:20 pm on June 24, 2011 Permalink |
[...] Just a reminder today is dev c…Paul Gibbs on 404 & search page dev chat…A-Sun on Accessing user metadata in BP…Paul Gibbs on On May 25th’s dev chat [...]