Forked from strangerstudios/pmprobuddy_update_user_meta.php
Created
February 14, 2017 05:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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