Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MaximilianoRicoTabo/70c3b0015f330822dc115fd4bf27cb55 to your computer and use it in GitHub Desktop.
Save MaximilianoRicoTabo/70c3b0015f330822dc115fd4bf27cb55 to your computer and use it in GitHub Desktop.
Send a custom notification when a user changes their profile
/**
* Hook into profile update and send a notification to site admin
*
* @param int $user_id The ID of the user being updated
* @param object $old_user_data The object of the user before it was updated.
* @return void
*/
function user_profile_update( $user_id, $old_user_data ) {
if( class_exists( 'PMProEmail' ) ) {
//get the user updated.
$user = get_userdata( $user_id );
$email = new PMProEmail();
$recipient = get_bloginfo('admin_email');
//with user fetched we can add to the body user data. We also have $old_user_data to compare if we want.
$data['body'] = "The user " . $user->first_name . " " . $user->last_name . " has updated their profile";
$email->sendEmail($recipient, $from = NULL, $fromname = NULL, "User has changed profile", "user-changed-profile", $data);
}
}
add_action( 'profile_update', 'user_profile_update', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment