Copy xprofile field data to usermeta -Success ! but one little php tweak needed
-
Found this code that copies (on registration) profile field data to usermeta fields at https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/xprofile-vs-usermeta-syncing-problems/
function synchro_wp_usermeta($user_id, $password, $meta) { global $bp, $wpdb; $uid = get_userdata($user_id); $email = $uid->user_email; $fullname = $meta[field_1]; ... whatever you need here .... update_usermeta( $user_id, 'nickname', $fullname ); update_usermeta( $user_id, 'first_name', $firstname ); update_usermeta( $user_id, 'last_name', $lastname ); $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $user_id ) ); $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d", bp_core_get_user_domain( $user_id ), $user_id ) ); } add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3); I have tested it and it works.
In the line above
$fullname = $meta[field_1];
field_1 refers to the id number of the field in wp_XX_bp_xprofile_fields (where XX is the site id number).
I want to use the field name here, not the number.
what do I change
$fullname = $meta[field_1];
to use the field name ? Please.
- The topic ‘Copy xprofile field data to usermeta -Success ! but one little php tweak needed’ is closed to new replies.