If you are running a multi-user Blog or WordPress site, it would be nice to send a notification email upon user successfully updates his or her profile. Such feature could be particularly very useful to detect unauthorized account access on your site. From overall security point of view it is a very good option to have on your WP based site.
Here is a simple snippet that would allow you to do just that.
<?php
add_action('profile_update','notify_user_profile_update', 10, 2);
function notify_user_profile_update($user_id) {
$siteurl = get_bloginfo('wpurl');
$userinfo = get_userdata($user_id);
$to = $userinfo->user_email;
$headers = 'From: Admin <'.get_bloginfo('admin_email').'>';
$subject = 'Profile Updated! - '.$siteurl.'';
$message = 'Hello '.$userinfo->display_name.'\nYour profile has been updated!\n\nThank you.';
wp_mail($to, $subject, $message, $headers); }
?>
Simply copy and paste this snippet on your current theme’s functions.php page and update it. You are good to go now.
Explanation
What we are doing here is fairly simple and easy to understand. I am using an action hook to call a function (notify_user_profile_update) which will collect the user information (user id, email & user display name) and then send an email. Now, this add_action hook will only trigger the function when the user’s profile gets updated.
References: profile_update, wp_mail
Comment
Leave a Reply