Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active November 5, 2024 15:32
Show Gist options
  • Save andrewlimaza/9376d3222714a7377708b45ab40fb173 to your computer and use it in GitHub Desktop.
Save andrewlimaza/9376d3222714a7377708b45ab40fb173 to your computer and use it in GitHub Desktop.
Send admin an email when a user updates their email address in their WordPress profile.
<?php
/**
* Send admin an email when a user's email is updated via their Edit Profile page.
* Full Guide - https://yoohooplugins.com/send-email-to-admins-on-wordpress-profile-update/
* Add this code to your site by following - https://yoohooplugins.com/customize-wordpress/
*/
function yh_send_admin_email_user_updated( $user_id, $old_data, $new_data ) {
// Send an email to an admin when the user's email changes.
if ( $old_data->data->user_email !== $new_data['user_email'] ) {
$to = '[email protected]';
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
$subject = 'A user changed their email';
$body = 'A user has changed their email from ' . sanitize_email( $old_data->data->user_email ) . ' to ' . sanitize_email( $new_data['user_email'] );
wp_mail( $to, $subject, $body, $headers );
}
}
add_action( 'profile_update', 'yh_send_admin_email_user_updated', 10, 3 );
@andrewlimaza
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment