WordPress to BuddyPress profile sync
-
In BuddyPress there is a built-in mechanism for synchronizing profile fields from WordPress.
By default, it synchronizes only the “display_name” field, which is not always sufficient.
Here is an example of the code by which you can synchronize any available fields in the WordPress field with the Buddypress fieldsfunction xprofile_sync_bp_profile2( &$errors, $update, &$user ) { // Bail if profile syncing is disabled. if ( bp_disable_profile_sync() || ! $update || $errors->get_error_codes() ) { return; } // Querying data from a table "usermeta", first we get the value of the custom field "address" and substitute this value for the "Address" field of the xprofile BuddyPress $address = get_user_meta( $user->ID, 'address', 'true' ); xprofile_set_field_data( 'Address', $user->ID, $address ); //Similarly with other fields $firstname = get_user_meta( $user->ID, 'first_name', 'true' ); xprofile_set_field_data( 'Name', $user->ID, $firstname ); $lastname = get_user_meta( $user->ID, 'last_name', 'true' ); xprofile_set_field_data( 'Lastname', $user->ID, $lastname ); $description = get_user_meta( $user->ID, 'description', 'true' ); xprofile_set_field_data( 'Bio', $user->ID, $description ); // Querying data from a table "user" xprofile_set_field_data( 'E-mail', $user->ID, $user->user_email ); xprofile_set_field_data( 'Site', $user->ID, $user->user_url ); } add_action( 'user_profile_update_errors', 'xprofile_sync_bp_profile2', 10, 3 );
Unfortunately, the fields are synchronized only when the profile is updated. I do not know how to start mass synchronization 🙁
I hope someone will find this information useful.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.