We were wondering the same (I’m guessing you’re talking about Buddypress’ extended profile, or “xprofile” fields.) I found the following the FAQ:
Send additional fields to MailChimp
Since version 1.1, you can specify which additional user fields to send to MailChimp by mapping your fields on the settings page of the plugin.
If you need to send more complex data you can use the mailchimp_sync_user_data filter.
…so do buddypress xprofile fields class as ‘more complex data’, or is there a certain way we can put the field names in the settings page, and is there any documentation for that?
We’ve added the following to our functions.php file, and having it tested now.
//Add buddypress xprofile field to MailChimp Sync
add_filter( 'mailchimp_sync_user_data', 'mailchimp_buddypress', 10, 2 );
function mailchimp_buddypress( $data, $user ) {
$user_id = $user->ID;
$data['FIELD'] = xprofile_get_field_data( 454 , $user_id );
return $data;
}
We’ll let you know how it goes.
Yep, the xprofile fields are indeed what I’m talking about. Let me know how it goes!
That’s worked for us.
Add that code to your theme’s functions.php file, but change ‘454’ for the id of your chosen xprofile field, and change ‘FIELD’ for the mailchimp field you want it synchronised to.
NB: It doesn’t give you any feedback to show that it’s worked and it won’t appear on the settings page – it just does it quietly in the background, so you’ll have to update a user and see if the changes appear in mailchimp.
Also, the synchronising will only happen whenever a user is updated or added. If you want it to happen any other times, you’ll have to use the action hooks. (do_action('mailchimp_sync_update_subscriber', $user_id);
)
It crashes and burns for me when I try to add it to my functions.php. I’m looking for multiple fields – any thoughts on what I’m doing wrong?
//Add buddypress xprofile field to MailChimp Sync
add_filter( 'mailchimp_sync_user_data', 'mailchimp_buddypress', 10, 2 );
//FULLNAME
function mailchimp_buddypress( $data, $user ) {
$user_id = $user->ID;
$data['FULLNAME'] = xprofile_get_field_data( 1 , $user_id );
return $data;
}
//TEACHER
function mailchimp_buddypress( $data, $user ) {
$user_id = $user->ID;
$data['TEACHER'] = xprofile_get_field_data( 3 , $user_id );
return $data;
}
//CHILD
function mailchimp_buddypress( $data, $user ) {
$user_id = $user->ID;
$data['CHILD'] = xprofile_get_field_data( 2 , $user_id );
return $data;
}
//PHOTO
function mailchimp_buddypress( $data, $user ) {
$user_id = $user->ID;
$data['PHOTO'] = xprofile_get_field_data( 11 , $user_id );
return $data;
}
Ah yes you’ll want to combine them into one function to be called (What you’re doing at the moment is setting the mailchimp_buddypress function and then rewriting it three times)
You’ll want something along the lines of…
//Add buddypress xprofile field to MailChimp Sync
//Call the function
add_filter( 'mailchimp_sync_user_data', 'mailchimp_buddypress', 10, 2 );
//Write the function
function mailchimp_buddypress( $data, $user ) {
//Get user ID
$user_id = $user->ID;
// Store Xprofile fields in the $data variable
$data['FULLNAME'] = xprofile_get_field_data( 1 , $user_id );
$data['TEACHER'] = xprofile_get_field_data( 3 , $user_id );
$data['PHOTO'] = xprofile_get_field_data( 11 , $user_id );
//Return the data
return $data;
}
That should be alright, but I’m writing on a mobile, so you may want to check it.
All right! My site doesn’t crash and syncing happens. Now I just need to get the field mapping right, because my data isn’t showing up in Mailchimp.
Still: vast improvement over the crashing. If anyone ever asks me who the man is, I will point them your way. Thanks!
Hi Matt and jdmbaldwin,
I ve tried your code but it is not working – my data isn’t showing up in Mailchimp.
Have you had any luck making it work ?
Thanks
Any luck with this? Is this working for you guys? I’m trying to sync buddypress xprofile fields to mailchimp groups. This should be assignable in the plugin dashboard but I’d settle for hacking the php file. Please let me know if this is a viable option…
That format of that last code chunk was working fine for us when I last checked. I’ll have a look.
Yup working fine.
@gaysurfers what does your code look like?
@matt are you filling in the additional fields as well as using this code? I’m not exactly sure the settings I am supposed to do for this. I am in the process of troubleshooting now and if I figure it out I will post it
I got it, I made a mistake while inputting the code in functions.php
This is what I have
//Add buddypress xprofile field to MailChimp Sync
//Call the function
add_filter( 'mailchimp_sync_user_data', 'mailchimp_buddypress', 10, 2 );
//Write the function
function mailchimp_buddypress( $data, $user ) {
//Get user ID
$user_id = $user->ID;
// Store Xprofile fields in the $data variable
$data['STREET'] = xprofile_get_field_data( 13 , $user_id );
$data['STREET2'] = xprofile_get_field_data( 14 , $user_id );
$data['CITY'] = xprofile_get_field_data( 7 , $user_id );
$data['STATE'] = xprofile_get_field_data( 14 , $user_id );
$data['ZIP'] = xprofile_get_field_data( 9 , $user_id );
//Return the data
return $data;
}
STREET, STREET2 etc are the field tags in mailchimp. Also, you do not have to add anything to the “send additional fields” area