Better metadata wrappers in BP 1.3

BuddyPress 1.3 will introduce a number of new functions to help plugin authors store options and usermeta. For options, we have:

  • bp_get_option()
  • bp_update_option()
  • bp_delete_option()

and for usermeta, we have

  • bp_get_user_meta()
  • bp_update_user_meta()
  • bp_delete_user_meta()

These functions are essentially wrappers for the corresponding WP functions (get_option(), get_user_meta(), etc). Their syntax is exactly the same as those WP functions.

So why introduce these new functions? In both cases, the goal is to make it possible for BuddyPress to be run on unorthodox setups.

In the case of options, BP 1.3 moves all BP settings out of sitemeta and into blog options tables. On a typical setup, BP will store all settings in the options table of BP_ROOT_BLOG. But in non-standard setups – including BP_ENABLE_MULTIBLOG, or multinetwork BP – certain options may need to be stored somewhere other than BP_ROOT_BLOG. The bp_x_option() functions wrap a utility function called bp_get_option_blog_id(), which allows plugin authors to filter the blog where a given option is stored.

Likewise, in the case of usermeta, the new functions will allow for more flexibility. I’ve already written about bp_get_user_meta_key() and the motivations behind it. The new bp_x_user_meta() functions are just wrappers for x_user_meta() calls, which use bp_get_user_meta_key() to allow the meta keys to be filtered. These wrapper functions should make it much easier for plugin authors to access and store usermeta.

These changes are nearly 100% backward-compatible. If your plugin or theme still uses the WP usermeta and options functions, it should continue to work in BP 1.3, unless the admin enables one of the aforementioned unorthodox setups. Plugin authors are highly encouraged to use the bp_ variants from here on out.

For more information, see the changesets where these wrappers were introduced: [4559] (options) and [4558] (usermeta).

#1-3, #bp_get_user_meta_key, #options, #sitemeta, #usermeta