Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greathmaster/50302a9cc6cf1f7f65dc6ae7b4ced5ef to your computer and use it in GitHub Desktop.
Save greathmaster/50302a9cc6cf1f7f65dc6ae7b4ced5ef to your computer and use it in GitHub Desktop.
Sync WordPress user meta fields (e.g. those added by PMPro Register Helper) with BuddyPress profile fields.
/*
Sync PMPro fields to BuddyPress profile fields.
*/
function pmprobuddy_update_user_meta($meta_id, $object_id, $meta_key, $meta_value)
{
//make sure buddypress is loaded
do_action('bp_init');
//array of user meta to mirror
$um = array(
"company" => "Company", //usermeta field => buddypress profile field
);
//check if this user meta is to be mirrored
foreach($um as $left => $right)
{
if($meta_key == $left)
{
//find the buddypress field
$field = xprofile_get_field_id_from_name($right);
//update it
if(!empty($field))
xprofile_set_field_data($field, $object_id, $meta_value);
}
}
}
add_action('update_user_meta', 'pmprobuddy_update_user_meta', 10, 4);
//need to add the meta_id for add filter
function pmprobuddy_add_user_meta($object_id, $meta_key, $meta_value)
{
pmprobuddy_update_user_meta(NULL, $object_id, $meta_key, $meta_value);
}
add_action('add_user_meta', 'pmprobuddy_add_user_meta', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment