To simplify my question, I’ve pasted the code in that Chris wrote. I just don’t know how to call the buddypress xprofile fields?
/* ===========================================
Send Emails when User Profile Changes
=============================================*/
// IF EMAIL CHANGES
function sr_user_profile_update_email( $user_id, $old_user_data ) {
$user = get_userdata( $user_id );
if($old_user_data->user_email != $user->user_email) {
$admin_email = "email@yourdomain.com";
$message = sprintf( __( 'This user has updated their profile on the SchoolRise USA Staff Member site.' ) ) . "\r\n\r\n";
$message .= sprintf( __( 'Display Name: %s' ), $user->display_name ). "\r\n\r\n";
$message .= sprintf( __( 'Old Email: %s' ), $old_user_data->user_email ). "\r\n\r\n";
$message .= sprintf( __( 'New Email: %s' ), $user->user_email ). "\r\n\r\n";
wp_mail( $admin_email, sprintf( __( '[Staff Member Site] User Profile Update' ), get_option('blogname') ), $message );
}
}
// Save old user data and meta for later comparison for non-standard fields (phone, address etc.)
function sr_old_user_data_transient(){
$user_id = get_current_user_id();
$user_data = get_userdata( $user_id );
$user_meta = get_user_meta( $user_id );
foreach( $user_meta as $key=>$val ){
$user_data->data->$key = current($val);
}
// 1 hour should be sufficient
set_transient( 'sr_old_user_data_' . $user_id, $user_data->data, 60 * 60 );
}
add_action('show_user_profile', 'sr_old_user_data_transient');
// Cleanup when done
function sr_old_user_data_cleanup( $user_id, $old_user_data ){
delete_transient( 'sr_old_user_data_' . $user_id );
}
add_action( 'profile_update', 'sr_old_user_data_cleanup', 1000, 2 );