2

I have previously asked about How to automatically send email to Admin when a user/member changes his/hers profile data. And got some very good answers. Send automatic mail to Admin when user/member changes/adds profile

Now a follow up: I only want to send/email the data (profiledata) that was updated/added.

4
  • You might want to reward the answer to the previous question. Folks are less likely to help someone who doesn't accept answers. Commented Jun 16, 2011 at 19:51
  • Ok. So, two7s_clash tell me how to do that other than expressing my gratitude which I have done. To up-vote the excellent answer more required 15 "points" which I don't have.
    – Fredag
    Commented Jun 17, 2011 at 12:20
  • You don't up vote it, you accept it as correct by checking the check. Commented Jun 17, 2011 at 14:56
  • @two7s_clash: Thanks. Checked! And now green... And I have read the faq!
    – Fredag
    Commented Jun 17, 2011 at 15:09

2 Answers 2

-1

So, as Bainternet notes, you would need to compare the new field value to what it was right before the edit. In essence, you will need to build in version control for the profile fields. You will need to add a database table to store this info, using the the $wpdb object to write, and read from it.

Basically, on personal_options_update and edit_user_profile_update you will glean the data as in the previous answer, but then also compare it to your table storing the what existed in the previous save. You'll only send a particular field's data if there is mismatch.

1
  • I was hoping for an easier solution but will do some experiments with this. Thanks two7s_clash and Bainternet!
    – Fredag
    Commented Jun 20, 2011 at 9:07
1

Here's a modified version building on the work from others, here. This instance sends an email if the user's email field has been changed. Swap 'user_email' with whatever user meta you like.

add_action( 'personal_options_update', 'notify_admin_on_update' );
add_action( 'edit_user_profile_update','notify_admin_on_update');
function notify_admin_on_update(){
global $current_user;
get_currentuserinfo();

if (!current_user_can( 'administrator' )){// avoid sending emails when admin is updating user profiles
    $to = '[email protected]';//change this email to whatever
    $subject = 'A user has updated their profile';//sent email subject field
    $message = "The user : " .$current_user->display_name . " has updated their email to: " .$current_user->user_email."";
    wp_mail( $to, $subject, $message);//the code that sends the message
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.