Send Email Notification Upon User Profile Update

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

Today In History

  •  
  •  

Comment

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from HTMLify, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.