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 );
Hello,
Is there anyway you can get this to also show the old xprofile data?
Similar to your other post for standard profile fields…
function sr_user_profile_update_email( $user_id, $old_user_data )
Thanks! :)
Dan