BuddyPress: Send Admin Notification when User Updates Extended Profile Fields
Background
I wrote a similar post explaining how to send an email notification from WordPress when standard and custom profile fields are updated. A commenter on that post was asking if this was possible with the extended profile fields that you setup in BuddyPress. Well, of course anything is possible…it’s just a matter of figuring it out ;)
Solution
In this example I setup a custom profile field in BuddyPress named “Color”. The code below will send an email if a member changes that field.
- Place this code in your
functions.php
file or into your custom functionality plugin if you’ve created one. - Add the email address you want there alerts to go to on line 3.
- Add your field’s name in both places on line 4 that say “Color” (your field name should appear exactly the way you wrote it when you created the field).
- If you want to change the subject of the email, you can do that on line 5.
function rc_buddypress_profile_update( $user_id ) { $admin_email = "YOUR-EMAIL@DOMAIN.COM"; $message = sprintf( __( 'Member: %1$s', 'buddypress' ), bp_core_get_user_displayname( $user_id ) ) . "\r\n\r\n"; $message .= sprintf( __( 'Color: %s' ), bp_get_profile_field_data('field=Color') ). "\r\n\r\n"; wp_mail( $admin_email, sprintf( __( '[YOUR SITE] Member Profile Update' ), get_option('blogname') ), $message ); } add_action( 'xprofile_updated_profile', 'rc_buddypress_profile_update', 10, 5 );
It works for me. Thank you very much!!!
Too cool! Thanks for this! :)
In your other example you provided instances for multiple fields that showed the old and the new and would send a separate email only if that field was changed.
Would it be difficult to do that in this case?
Note: I’m not a seasoned “PHPer” ;)
Greetings,
Is it possible to include all the profile details in the new registration email sent to admin. If yes, how? Sorry I am a newbie.
Thanks in advance
Check the article here: http://wordpress.stackexchange.com/questions/15304/how-to-change-the-default-registration-email-plugin-and-or-non-plugin
Hey Chris,
I have a few questions about this function. Specifically, for line 5 do I need to include every single field? Also, for the bit of code that preceeds bp_get_profile_field_data, .= sprintf( __( ‘Color: %s’ ). Do I need to include anything in here, next to ‘Color:%s’ or leave it as is?
For line 6, do I need to type the captitalized [YOUR SITE] exactly like this [INTIMATENCOUNTERS]?
And lastly, for ‘blogname’ would I type ‘intimatencounters’ ?
function rc_buddypress_profile_update( $user_id ) {
$admin_email = “admin@intimatencounters.com”;
$message = sprintf( __( ‘Member: %1$s’, ‘buddypress’ ), bp_core_get_user_displayname( $user_id ) ) . “\r\n\r\n”;
$message .= sprintf( __( ‘Color: %s’ ), bp_get_profile_field_data(‘field=Color’) ). “\r\n\r\n”;
wp_mail( $admin_email, sprintf( __( ‘[YOUR SITE] Member Profile Update’ ), get_option(‘IntimatEncnounters’) ), $message );
}
add_action( ‘xprofile_updated_profile’, ‘rc_buddypress_profile_update’, 10, 5 );
I emailed you about the solution we discussed on the phone ;)
Thank you for this! I got it to work when the field is just text or a radio button. When the user updates a field that has checkboxes, it emails this:
“Days available: Array”
instead of this:
“Days available: Monday, Thursday, Friday”
Is there a way to get the array values emailed as well?
It’s returning “Array” because you have multiple values – I don’t have time to troubleshoot the correct code for you right this second, but off the top of my head you would need to do a “foreach” in order to spit out all of the values.