Last active
November 5, 2024 15:32
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the full guide here - https://yoohooplugins.com/send-email-to-admins-on-wordpress-profile-update/